mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibC+LibCore: Use tm_isdst to handle time zone offsets in DST
Previously, we were incorrectly assuming that the daylight global variable indicated whether the current time zone is in DST. In reality, the daylight variable only indicates whether a time zone *can* be in DST. Instead, the tm structure has a tm_isdst member that should be used for this purpose. Ensure our LibC handles tm_isdst, and avoid errant usage of the daylight variable in Core::DateTime.
This commit is contained in:
committed by
Linus Groh
parent
e683ca00cc
commit
a4a7efaf5f
Notes:
sideshowbarker
2024-07-17 10:31:19 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/a4a7efaf5f Pull-request: https://github.com/SerenityOS/serenity/pull/14760
@@ -92,13 +92,13 @@ String DateTime::to_string(StringView format) const
|
||||
int const format_len = format.length();
|
||||
|
||||
auto format_time_zone_offset = [&](bool with_separator) {
|
||||
#if defined(__serenity__)
|
||||
auto offset_seconds = daylight ? -altzone : -timezone;
|
||||
#elif !defined(__FreeBSD__)
|
||||
auto offset_seconds = -timezone;
|
||||
#else
|
||||
auto offset_seconds = 0;
|
||||
#endif
|
||||
struct tm gmt_tm;
|
||||
gmtime_r(&m_timestamp, &gmt_tm);
|
||||
|
||||
gmt_tm.tm_isdst = -1;
|
||||
auto gmt_timestamp = mktime(&gmt_tm);
|
||||
|
||||
auto offset_seconds = static_cast<time_t>(difftime(m_timestamp, gmt_timestamp));
|
||||
StringView offset_sign;
|
||||
|
||||
if (offset_seconds >= 0) {
|
||||
@@ -251,11 +251,7 @@ String DateTime::to_string(StringView format) const
|
||||
format_time_zone_offset(true);
|
||||
break;
|
||||
case 'Z': {
|
||||
#ifndef __FreeBSD__
|
||||
auto const* timezone_name = tzname[daylight];
|
||||
#else
|
||||
auto const* timezone_name = tzname[0];
|
||||
#endif
|
||||
auto const* timezone_name = tzname[tm.tm_isdst == 0 ? 0 : 1];
|
||||
builder.append({ timezone_name, strlen(timezone_name) });
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user