From c5ff7d86b970bf2aea1214f2be04bd5c0584a0a9 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 30 Sep 2024 01:55:24 -0400 Subject: Bugfix DateTime.new() --- stdlib/datetime.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'stdlib') diff --git a/stdlib/datetime.c b/stdlib/datetime.c index 6ad4966f..3321dde7 100644 --- a/stdlib/datetime.c +++ b/stdlib/datetime.c @@ -50,8 +50,6 @@ public DateTime_t DateTime$now(void) public DateTime_t DateTime$new(Int_t year, Int_t month, Int_t day, Int_t hour, Int_t minute, double second, OptionalText_t timezone) { - if (timezone.length >= 0) - DateTime$set_local_timezone(timezone); struct tm info = { .tm_min=Int_to_Int32(minute, false), .tm_hour=Int_to_Int32(hour, false), @@ -60,9 +58,16 @@ public DateTime_t DateTime$new(Int_t year, Int_t month, Int_t day, Int_t hour, I .tm_year=Int_to_Int32(year, false) - 1900, .tm_isdst=-1, }; - time_t t = mktime(&info); - if (timezone.length >= 0) - DateTime$set_local_timezone(_local_timezone); + + time_t t; + if (timezone.length >= 0) { + OptionalText_t old_timezone = _local_timezone; + DateTime$set_local_timezone(timezone); + t = mktime(&info); + DateTime$set_local_timezone(old_timezone); + } else { + t = mktime(&info); + } return (DateTime_t){.tv_sec=t + (time_t)second, .tv_usec=(suseconds_t)(fmod(second, 1.0) * 1e9)}; } -- cgit v1.2.3