Add Core::TimeZone as the single entry point for changing the current time zone. This updates both ICU and the process TZ/tzset state so libc-backed helpers such as AK::UnixDateTime::to_string() agree with JS/ICU time zone state. Previously only the ICU timezone would be updated, which could result in inconsistent results being returned.
27 lines
562 B
C++
27 lines
562 B
C++
/*
|
|
* Copyright (c) 2026, Shannon Booth <shannon@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibCore/Environment.h>
|
|
#include <LibCore/TimeZone.h>
|
|
#include <LibUnicode/TimeZone.h>
|
|
#include <time.h>
|
|
|
|
namespace Core::TimeZone {
|
|
|
|
ErrorOr<void> set_current_time_zone(StringView time_zone)
|
|
{
|
|
TRY(Unicode::set_current_time_zone(time_zone));
|
|
TRY(Core::Environment::set("TZ"sv, time_zone, Core::Environment::Overwrite::Yes));
|
|
tzset();
|
|
return {};
|
|
}
|
|
|
|
String current_time_zone()
|
|
{
|
|
return Unicode::current_time_zone();
|
|
}
|
|
|
|
}
|