From 232f54cd9b2e166d098d12b3457e6bbdf01c7e61 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 30 Oct 2021 09:06:27 +0200 Subject: [PATCH] LibCore: Fix off-by-one in DateTime::{create,set_time} day default arg Just like month, the day value here is one-based. This resulted in the following situation, which is obviously unexpected: Core::DateTime::create(1970); // 1970-01-00 -> 1969-12-31 --- Userland/Libraries/LibCore/DateTime.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibCore/DateTime.h b/Userland/Libraries/LibCore/DateTime.h index 46b6014ade..1e24751038 100644 --- a/Userland/Libraries/LibCore/DateTime.h +++ b/Userland/Libraries/LibCore/DateTime.h @@ -29,10 +29,10 @@ public: unsigned day_of_year() const; bool is_leap_year() const; - void set_time(int year, int month = 1, int day = 0, int hour = 0, int minute = 0, int second = 0); + 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; - static DateTime create(int year, int month = 1, int day = 0, int hour = 0, int minute = 0, int second = 0); + static DateTime create(int year, int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0); static DateTime now(); static DateTime from_timestamp(time_t); static Optional parse(const String& format, const String& string);