From 29c8ec5eb6fa86657cc15ffd5d2fb868128611b4 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 25 Jan 2022 16:07:22 -0500 Subject: LibCore: Support (and use) DateTime string formatting of the form %Z This formats the time zone name. This is now used in the default format string because DateTime is meant to represent local time; it only makes sense to include the time zone by default now that we support non-UTC. --- Userland/Libraries/LibCore/DateTime.cpp | 3 +++ Userland/Libraries/LibCore/DateTime.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibCore/DateTime.cpp b/Userland/Libraries/LibCore/DateTime.cpp index 490a27d2f6..dce43d57b5 100644 --- a/Userland/Libraries/LibCore/DateTime.cpp +++ b/Userland/Libraries/LibCore/DateTime.cpp @@ -246,6 +246,9 @@ String DateTime::to_string(const String& format) const format_time_zone_offset(true); break; + case 'Z': + builder.append(tzname[0]); + break; case '%': builder.append('%'); break; diff --git a/Userland/Libraries/LibCore/DateTime.h b/Userland/Libraries/LibCore/DateTime.h index 30ac5227af..628dd7e343 100644 --- a/Userland/Libraries/LibCore/DateTime.h +++ b/Userland/Libraries/LibCore/DateTime.h @@ -30,7 +30,7 @@ public: bool is_leap_year() const; void set_time(int year, int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0); - String to_string(const String& format = "%Y-%m-%d %H:%M:%S") const; + String to_string(const String& format = "%Y-%m-%d %H:%M:%S %Z") const; static DateTime create(int year, int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0); static DateTime now(); -- cgit v1.2.3