mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
LibJS+LibTimeZone+LibUnicode: Indicate whether a time zone is in DST
Return whether the time zone is in DST during the provided time from TimeZone::get_time_zone_offset,
This commit is contained in:
parent
42c9c57141
commit
70f49d0696
7 changed files with 86 additions and 69 deletions
|
@ -450,7 +450,7 @@ static constexpr Array<@type@, @size@> @name@ { {
|
|||
append_string_conversions("DaylightSavingsRule"sv, "daylight_savings_rule"sv, time_zone_data.dst_offset_names);
|
||||
|
||||
generator.append(R"~~~(
|
||||
static i64 get_dst_offset(TimeZoneOffset const& time_zone_offset, AK::Time time)
|
||||
static Offset get_dst_offset(TimeZoneOffset const& time_zone_offset, AK::Time time)
|
||||
{
|
||||
auto const& dst_rules = s_dst_offsets[time_zone_offset.dst_rule];
|
||||
|
||||
|
@ -487,17 +487,17 @@ static i64 get_dst_offset(TimeZoneOffset const& time_zone_offset, AK::Time time)
|
|||
}
|
||||
|
||||
if (!standard_offset || !daylight_offset)
|
||||
return 0;
|
||||
return {};
|
||||
|
||||
auto standard_time_in_effect = time_in_effect_for_rule(*standard_offset);
|
||||
auto daylight_time_in_effect = time_in_effect_for_rule(*daylight_offset);
|
||||
|
||||
if ((time < daylight_time_in_effect) || (time >= standard_time_in_effect))
|
||||
return standard_offset->offset;
|
||||
return daylight_offset->offset;
|
||||
return { standard_offset->offset, InDST::No };
|
||||
return { daylight_offset->offset, InDST::Yes };
|
||||
}
|
||||
|
||||
Optional<i64> get_time_zone_offset(TimeZone time_zone, AK::Time time)
|
||||
Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time)
|
||||
{
|
||||
auto const& time_zone_offsets = s_time_zone_offsets[to_underlying(time_zone)];
|
||||
|
||||
|
@ -512,13 +512,16 @@ Optional<i64> get_time_zone_offset(TimeZone time_zone, AK::Time time)
|
|||
VERIFY(index < time_zone_offsets.size());
|
||||
auto const& time_zone_offset = time_zone_offsets[index];
|
||||
|
||||
i64 dst_offset = 0;
|
||||
if (time_zone_offset.dst_rule != -1)
|
||||
Offset dst_offset {};
|
||||
if (time_zone_offset.dst_rule != -1) {
|
||||
dst_offset = get_dst_offset(time_zone_offset, time);
|
||||
else
|
||||
dst_offset = time_zone_offset.dst_offset;
|
||||
} else {
|
||||
auto in_dst = time_zone_offset.dst_offset == 0 ? InDST::No : InDST::Yes;
|
||||
dst_offset = { time_zone_offset.dst_offset, in_dst };
|
||||
}
|
||||
|
||||
return time_zone_offset.offset + dst_offset;
|
||||
dst_offset.seconds += time_zone_offset.offset;
|
||||
return dst_offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue