diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-05-15 12:58:05 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-05-15 12:58:05 +0100 |
| commit | be3aa4a24251f2b92724a90da95df0b98d16e69f (patch) | |
| tree | 77b50a7cb0b536514305b6c7e4d09d0033f9a612 /src | |
| parent | c62f2251c71e1eabf94f3b1ee291b91543228819 (diff) | |
Add ::time_of_day without seconds.
Diffstat (limited to 'src')
| -rw-r--r-- | src/local_time.cc | 9 | ||||
| -rw-r--r-- | src/local_time.h | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/local_time.cc b/src/local_time.cc index 8a009209..647ff35d 100644 --- a/src/local_time.cc +++ b/src/local_time.cc @@ -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; } diff --git a/src/local_time.h b/src/local_time.h index 1e4c8228..d213b898 100644 --- a/src/local_time.h +++ b/src/local_time.h @@ -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; |
