Add ::time_of_day without seconds.
authorCarl Hetherington <cth@carlh.net>
Mon, 15 May 2017 11:58:05 +0000 (12:58 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 15 May 2017 11:58:05 +0000 (12:58 +0100)
src/local_time.cc
src/local_time.h

index 8a0092096caba28dfb66dd11d15302b95738ccbc..647ff35dd45e2032775a75ff9c7a2b62f2a13f34 100644 (file)
@@ -174,7 +174,7 @@ LocalTime::as_string (bool with_millisecond) const
        snprintf (
                buffer, sizeof (buffer),
                "%sT%s%s%02d:%02d",
-               date().c_str(), time_of_day(with_millisecond).c_str(), (_tz_hour >= 0 ? "+" : "-"), abs (_tz_hour), _tz_minute
+               date().c_str(), time_of_day(true, with_millisecond).c_str(), (_tz_hour >= 0 ? "+" : "-"), abs (_tz_hour), _tz_minute
                );
        return buffer;
 }
@@ -190,13 +190,16 @@ LocalTime::date () const
 
 /** @return The time in the form HH:MM:SS or HH:MM:SS.mmm */
 string
-LocalTime::time_of_day (bool with_millisecond) const
+LocalTime::time_of_day (bool with_second, bool with_millisecond) const
 {
        char buffer[32];
+       DCP_ASSERT(!(with_millisecond && !with_second));
        if (with_millisecond) {
                snprintf (buffer, sizeof (buffer), "%02d:%02d:%02d.%03d", _hour, _minute, _second, _millisecond);
-       } else {
+       } else if (with_second) {
                snprintf (buffer, sizeof (buffer), "%02d:%02d:%02d", _hour, _minute, _second);
+       } else {
+               snprintf (buffer, sizeof (buffer), "%02d:%02d", _hour, _minute);
        }
        return buffer;
 }
index 1e4c8228c1f887fbb27436b224132142283bf6be..d213b898f5371e9589254c8c0fe3db6e21d3e69a 100644 (file)
@@ -64,7 +64,7 @@ public:
 
        std::string as_string (bool with_millisecond = false) const;
        std::string date () const;
-       std::string time_of_day (bool with_millisecond = false) const;
+       std::string time_of_day (bool with_second, bool with_millisecond) const;
 
        bool operator== (LocalTime const & other) const;
        bool operator!= (LocalTime const & other) const;