diff --git a/src/lib/time/time.cpp b/src/lib/time/time.cpp index c39772fdf..996f1e07e 100644 --- a/src/lib/time/time.cpp +++ b/src/lib/time/time.cpp @@ -121,7 +121,7 @@ namespace time { { } - /** displaying an internal Lumiera Time value + /** display an internal Lumiera Time value * for diagnostic purposes or internal reporting. * @warning internal Lumiera time values refer to an * implementation dependent time origin/scale. @@ -133,9 +133,28 @@ namespace time { return string (lumiera_tmpbuf_print_time (t_)); } - TimeVar::operator string() const + /** @note recommendation to use TCode for external representation */ + TimeValue::operator string() const { - return string (lumiera_tmpbuf_print_time (t_)); + gavl_time_t time = t_; + int millis, seconds; + bool negative = (time < 0); + + if (negative) time = -time; + time /= GAVL_TIME_SCALE_MS; + millis = time % 1000; + seconds = time / 1000; + + return string (negative ? "-" : "") + + (seconds>0 or time==0? lexical_cast (seconds)+"s" : "") + + (millis>0? lexical_cast (millis)+"ms" : "") + ; + } + + TimeSpan::operator string() const + { + return string (lumiera_tmpbuf_print_time (t_)) + + "["+string(dur_)+"]"; } @@ -224,14 +243,10 @@ char* lumiera_tmpbuf_print_time (gavl_time_t time) { int milliseconds, seconds, minutes, hours; - int negative; + bool negative = (time < 0); - if(time < 0) - { - negative = 1; + if (negative) time = -time; - } - else negative = 0; time /= GAVL_TIME_SCALE_MS; milliseconds = time % 1000; diff --git a/src/lib/time/timevalue.hpp b/src/lib/time/timevalue.hpp index 04dec4370..d4585eb0c 100644 --- a/src/lib/time/timevalue.hpp +++ b/src/lib/time/timevalue.hpp @@ -118,6 +118,9 @@ namespace time { friend gavl_time_t _raw (TimeValue const& time) { return time.t_; } static TimeValue buildRaw_(gavl_time_t); + /** @internal diagnostics */ + operator std::string () const; + // Supporting totally_ordered friend bool operator< (TimeValue const& t1, TimeValue const& t2) { return t1.t_ < t2.t_; } friend bool operator< (TimeValue const& t1, gavl_time_t t2) { return t1.t_ < t2 ; } @@ -160,10 +163,7 @@ namespace time { return *this; } - /** @internal diagnostics */ - operator std::string () const; - - // Supporting mixing with plain long int arithmetics + // Support mixing with plain long int arithmetics operator gavl_time_t () const { return t_; } // Supporting additive @@ -515,6 +515,8 @@ namespace time { /** may change start / duration */ void accept (Mutation const&); + /** @internal diagnostics */ + operator std::string () const; /// Supporting extended total order, based on start and interval length friend bool operator== (TimeSpan const& t1, TimeSpan const& t2) { return t1.t_==t2.t_ && t1.dur_==t2.dur_; } diff --git a/tests/45controller.tests b/tests/45controller.tests index 310c58ce8..abeff8e33 100644 --- a/tests/45controller.tests +++ b/tests/45controller.tests @@ -12,26 +12,26 @@ out: Command-State. arguments=unbound, ·noUNDO·. out: capture state... out: Command-State. arguments=Closure\(\), ·noUNDO·. out: Command-State. arguments=Closure\(.\), ·noUNDO·. -out: Command-State. arguments=Closure\(.,0:..:....00\), ·noUNDO·. -out: Command-State. arguments=Closure\(0:..:....00,glorious,..\), . +out: Command-State. arguments=Closure\(.,.+s.*\), ·noUNDO·. +out: Command-State. arguments=Closure\(.+s.*,glorious,..\), . out: would be serialised.....Command-State. arguments=Closure\(\), ·noUNDO·. out: would be serialised.....Command-State. arguments=Closure\(.\), ·noUNDO·. -out: would be serialised.....Command-State. arguments=Closure\(.,0:..:....00\), ·noUNDO·. -out: would be serialised.....Command-State. arguments=Closure\(0:..:....00,glorious,..\), . +out: would be serialised.....Command-State. arguments=Closure\(.,.+s.*\), ·noUNDO·. +out: would be serialised.....Command-State. arguments=Closure\(.+s.*,glorious,..\), . out: sizeof\( .+control1.ArgumentHolder.+ \) = .+ -out: Command-State. arguments=Closure\(0:..:....00,Lumiera rocks,..\), ·noUNDO·. +out: Command-State. arguments=Closure\(.+s.*,Lumiera rocks,..\), ·noUNDO·. out: capture state... out: captured state: START...Lumiera rocks -out: Command-State. arguments=Closure\(0:..:....00,Lumiera rocks,..\), . +out: Command-State. arguments=Closure\(.+s.*,Lumiera rocks,..\), . out: invoke operation... -out: START...doIt\( Time=0:..:....00 "Lumiera rocks" rand=.. \) +out: START...doIt\( Time=.+s.* "Lumiera rocks" rand=.. \) out: undo... memento=START...Lumiera rocks -out: START...doIt\( Time=0:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocks +out: START...doIt\( Time=.+s.* "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocks out: capture state... -out: modified: Command-State. arguments=Closure\(0:00:00.123,unbelievable,..\), . -out: copied : Command-State. arguments=Closure\(0:..:....00,Lumiera rocks,..\), . -out: undo... memento=START...doIt\( Time=0:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks -out: RESET...undoIt\(time=0:..:....00\)----memento-:START...doIt\( Time=0:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks +out: modified: Command-State. arguments=Closure\(123ms,unbelievable,..\), . +out: copied : Command-State. arguments=Closure\(.+s.*,Lumiera rocks,..\), . +out: undo... memento=START...doIt\( Time=.+s.* "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks +out: RESET...undoIt\(time=0:..:....00\)----memento-:START...doIt\( Time=.+s.* "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks END diff --git a/tests/basics/time/time-value-test.cpp b/tests/basics/time/time-value-test.cpp index 057eb79ec..67667e3b1 100644 --- a/tests/basics/time/time-value-test.cpp +++ b/tests/basics/time/time-value-test.cpp @@ -319,7 +319,6 @@ namespace test{ // the time span behaves like a time CHECK (org == interval); - CHECK (string(Time(org)) == string(interval)); // can get the length by direct conversion Duration theLength(interval);