summaryrefslogtreecommitdiff
path: root/src/local_time.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-02-02 01:02:50 +0100
committerCarl Hetherington <cth@carlh.net>2023-02-02 01:02:50 +0100
commitb1464249c7b403a66ca63f403c80c39f1af63e65 (patch)
tree966daea7402bf5c2454c1b5ff0967768d2acd481 /src/local_time.cc
parentc89ed445b9fcd4d6c76cbf3278dd2d7d7e2e0a42 (diff)
Add with_timezone parameter to ::to_string().
Diffstat (limited to 'src/local_time.cc')
-rw-r--r--src/local_time.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/local_time.cc b/src/local_time.cc
index 0f87bb49..cadb7137 100644
--- a/src/local_time.cc
+++ b/src/local_time.cc
@@ -182,14 +182,24 @@ LocalTime::LocalTime (string s)
string
-LocalTime::as_string (bool with_millisecond) const
+LocalTime::as_string(bool with_millisecond, bool with_timezone) const
{
char buffer[32];
- snprintf (
+
+ auto const written = snprintf(
buffer, sizeof (buffer),
- "%sT%s%s%02d:%02d",
- date().c_str(), time_of_day(true, with_millisecond).c_str(), (_offset.hour() >= 0 ? "+" : "-"), abs(_offset.hour()), abs(_offset.minute())
+ "%sT%s",
+ date().c_str(), time_of_day(true, with_millisecond).c_str()
);
+
+ DCP_ASSERT(written < 32);
+
+ if (with_timezone) {
+ snprintf(
+ buffer + written, sizeof(buffer) - written,
+ "%s%02d:%02d", (_offset.hour() >= 0 ? "+" : "-"), abs(_offset.hour()), abs(_offset.minute())
+ );
+ }
return buffer;
}