mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:07:45 +00:00
LibTimeZone: Add an API to retrieve both daylight and standard offsets
This API will also include the formatted name of the time zone, with respect for DST (e.g. EST vs EDT for America/New_York).
This commit is contained in:
parent
fc0c88344b
commit
7103012c7d
4 changed files with 87 additions and 1 deletions
|
@ -4,7 +4,6 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Array.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibTimeZone/TimeZone.h>
|
||||
#include <stdio.h>
|
||||
|
@ -157,4 +156,25 @@ Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Time time)
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Array<NamedOffset, 2>> __attribute__((weak)) get_named_time_zone_offsets([[maybe_unused]] TimeZone time_zone, AK::Time)
|
||||
{
|
||||
#if !ENABLE_TIME_ZONE_DATA
|
||||
VERIFY(time_zone == TimeZone::UTC);
|
||||
|
||||
NamedOffset utc_offset {};
|
||||
utc_offset.name = "UTC"sv;
|
||||
|
||||
return Array { utc_offset, utc_offset };
|
||||
#else
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Time time)
|
||||
{
|
||||
if (auto maybe_time_zone = time_zone_from_string(time_zone); maybe_time_zone.has_value())
|
||||
return get_named_time_zone_offsets(*maybe_time_zone, time);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue