diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-30 01:55:24 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-30 01:55:24 -0400 |
| commit | c5ff7d86b970bf2aea1214f2be04bd5c0584a0a9 (patch) | |
| tree | 77f164cff4f96f8e4709fe4d9c52f98752a7b517 /stdlib/datetime.c | |
| parent | 793717729ae46bd026eff882f7d4da819dec32e5 (diff) | |
Bugfix DateTime.new()
Diffstat (limited to 'stdlib/datetime.c')
| -rw-r--r-- | stdlib/datetime.c | 15 |
1 files changed, 10 insertions, 5 deletions
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)}; } |
