mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:37:45 +00:00
LibTimeZone: Add an API to retrieve the system's current time zone
This is a wrapper API around the POSIX tzset / tzname information. It is to help ensure that tzset is invoked before accessing tzname.
This commit is contained in:
parent
9a7cd8fef8
commit
8a4ac9c387
2 changed files with 14 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibTimeZone/TimeZone.h>
|
#include <LibTimeZone/TimeZone.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
namespace TimeZone {
|
namespace TimeZone {
|
||||||
|
|
||||||
|
@ -19,6 +20,17 @@ enum class TimeZone : u16 {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
StringView current_time_zone()
|
||||||
|
{
|
||||||
|
static bool initialized_time_zone = false;
|
||||||
|
if (!initialized_time_zone) {
|
||||||
|
initialized_time_zone = true;
|
||||||
|
tzset();
|
||||||
|
}
|
||||||
|
|
||||||
|
return tzname[0];
|
||||||
|
}
|
||||||
|
|
||||||
Optional<TimeZone> __attribute__((weak)) time_zone_from_string([[maybe_unused]] StringView time_zone)
|
Optional<TimeZone> __attribute__((weak)) time_zone_from_string([[maybe_unused]] StringView time_zone)
|
||||||
{
|
{
|
||||||
#if !ENABLE_TIME_ZONE_DATA
|
#if !ENABLE_TIME_ZONE_DATA
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
namespace TimeZone {
|
namespace TimeZone {
|
||||||
|
|
||||||
|
StringView current_time_zone();
|
||||||
|
|
||||||
Optional<TimeZone> time_zone_from_string(StringView time_zone);
|
Optional<TimeZone> time_zone_from_string(StringView time_zone);
|
||||||
StringView time_zone_to_string(TimeZone time_zone);
|
StringView time_zone_to_string(TimeZone time_zone);
|
||||||
Optional<StringView> canonicalize_time_zone(StringView time_zone);
|
Optional<StringView> canonicalize_time_zone(StringView time_zone);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue