diff --git a/synfig-core/src/synfig/time.cpp b/synfig-core/src/synfig/time.cpp index 709c018..644f9d3 100644 --- a/synfig-core/src/synfig/time.cpp +++ b/synfig-core/src/synfig/time.cpp @@ -162,6 +162,44 @@ Time::Time(const String &str_, float fps): } } +// This functions suggests what time is in seconds +std::string Time::get_string(Time::Format format) const +{ + Time time(*this); + if (time <= begin()) + return "SOT"; // Start Of Time + if (time >= end()) + return "EOT"; // End Of Time + + if(format <= FORMAT_NORMAL) + { + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); + return strprintf("%.3f", (float)time); + } + + + if(format<=FORMAT_VIDEO) + { + int hours, minutes, seconds, microseconds; + hours = time / 3600; + time -= hours*3600; + + minutes = time / 60; + time -= minutes*60; + + seconds=time; + time -= seconds; + + microseconds = time*1000; + + return strprintf("%02d:%02d:%02d.%02d", hours, minutes, seconds, microseconds); + } + + synfig::error(_("Translating Time to unknown format (not implemented)")); + + return ""; +} + String Time::get_string(float fps, Time::Format format)const { diff --git a/synfig-core/src/synfig/time.h b/synfig-core/src/synfig/time.h index d7d2fd5..1e5e985 100644 --- a/synfig-core/src/synfig/time.h +++ b/synfig-core/src/synfig/time.h @@ -76,7 +76,7 @@ public: Time(int x):value_(x) { } - Time(int hour, int minute, float second):value_(static_cast(second+hour*3600+minute*60)) { } + Time(int hour, int minute, float second):value_(static_cast(hour*3600 + minute*60 + second)) { } //! Constructs Time from the given string. /*! \note If the string references frames, then the @@ -104,7 +104,8 @@ public: //! Returns a string describing the current time value /*! \see Format */ - String get_string(float fps=0, Time::Format format=FORMAT_NORMAL)const; + String get_string(float fps=0, Time::Format format=FORMAT_NORMAL) const; + std::string get_string(Time::Format format) const; #ifdef _DEBUG const char *c_str()const;