mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibJS+LibUnicode: Port retrieving the system time zone to ICU
This commit is contained in:
committed by
Andreas Kling
parent
89aa9a3af0
commit
d3e809bcd4
@@ -4,6 +4,7 @@ set(TEST_SOURCES
|
||||
TestIDNA.cpp
|
||||
TestLocale.cpp
|
||||
TestSegmenter.cpp
|
||||
TestTimeZone.cpp
|
||||
TestUnicodeCharacterTypes.cpp
|
||||
TestUnicodeNormalization.cpp
|
||||
)
|
||||
|
||||
43
Tests/LibUnicode/TestTimeZone.cpp
Normal file
43
Tests/LibUnicode/TestTimeZone.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibCore/Environment.h>
|
||||
#include <LibUnicode/TimeZone.h>
|
||||
|
||||
class TimeZoneGuard {
|
||||
public:
|
||||
explicit TimeZoneGuard(StringView time_zone)
|
||||
: m_time_zone(Core::Environment::get("TZ"sv))
|
||||
{
|
||||
MUST(Core::Environment::set("TZ"sv, time_zone, Core::Environment::Overwrite::Yes));
|
||||
}
|
||||
|
||||
~TimeZoneGuard()
|
||||
{
|
||||
if (m_time_zone.has_value())
|
||||
MUST(Core::Environment::set("TZ"sv, *m_time_zone, Core::Environment::Overwrite::Yes));
|
||||
else
|
||||
MUST(Core::Environment::unset("TZ"sv));
|
||||
}
|
||||
|
||||
private:
|
||||
Optional<StringView> m_time_zone;
|
||||
};
|
||||
|
||||
TEST_CASE(current_time_zone)
|
||||
{
|
||||
{
|
||||
TimeZoneGuard guard { "America/New_York"sv };
|
||||
EXPECT_EQ(Unicode::current_time_zone(), "America/New_York"sv);
|
||||
}
|
||||
{
|
||||
TimeZoneGuard guard { "ladybird"sv };
|
||||
EXPECT_EQ(Unicode::current_time_zone(), "UTC"sv);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user