2021-12-28 12:53:53 -05:00
|
|
|
/*
|
2022-01-31 13:07:22 -05:00
|
|
|
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
2021-12-28 12:53:53 -05:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-01-24 12:36:17 -05:00
|
|
|
#include <AK/Array.h>
|
2023-12-16 17:49:34 +03:30
|
|
|
#include <AK/ByteString.h>
|
2022-01-20 11:55:48 -05:00
|
|
|
#include <AK/Error.h>
|
2023-04-18 18:31:00 +01:00
|
|
|
#include <AK/Format.h>
|
2021-12-28 12:53:53 -05:00
|
|
|
#include <AK/Optional.h>
|
|
|
|
|
#include <AK/StringView.h>
|
2022-01-10 16:56:09 -05:00
|
|
|
#include <AK/Time.h>
|
|
|
|
|
#include <AK/Types.h>
|
2022-07-05 15:56:23 -04:00
|
|
|
#include <AK/Vector.h>
|
2021-12-28 12:53:53 -05:00
|
|
|
#include <LibTimeZone/Forward.h>
|
|
|
|
|
|
|
|
|
|
namespace TimeZone {
|
|
|
|
|
|
2023-10-03 12:02:53 -04:00
|
|
|
enum class IsLink {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct TimeZoneIdentifier {
|
|
|
|
|
StringView name;
|
|
|
|
|
IsLink is_link { IsLink::No };
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-19 14:18:02 -05:00
|
|
|
enum class InDST {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Offset {
|
|
|
|
|
i64 seconds { 0 };
|
|
|
|
|
InDST in_dst { InDST::No };
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-24 12:36:17 -05:00
|
|
|
struct NamedOffset : public Offset {
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString name;
|
2022-01-24 12:36:17 -05:00
|
|
|
};
|
|
|
|
|
|
2022-02-02 14:31:05 -05:00
|
|
|
struct Coordinate {
|
|
|
|
|
constexpr float decimal_coordinate() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<float>(degrees) + (static_cast<float>(minutes) / 60.0f) + (static_cast<float>(seconds) / 3'600.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i16 degrees { 0 };
|
|
|
|
|
u8 minutes { 0 };
|
|
|
|
|
u8 seconds { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Location {
|
|
|
|
|
Coordinate latitude;
|
|
|
|
|
Coordinate longitude;
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-24 19:55:19 -05:00
|
|
|
StringView system_time_zone();
|
2022-01-11 23:21:36 -05:00
|
|
|
StringView current_time_zone();
|
2022-01-20 11:55:48 -05:00
|
|
|
ErrorOr<void> change_time_zone(StringView time_zone);
|
2023-10-03 12:02:53 -04:00
|
|
|
ReadonlySpan<TimeZoneIdentifier> all_time_zones();
|
2022-01-11 23:21:36 -05:00
|
|
|
|
2021-12-28 12:53:53 -05:00
|
|
|
Optional<TimeZone> time_zone_from_string(StringView time_zone);
|
2022-01-10 12:45:16 -05:00
|
|
|
StringView time_zone_to_string(TimeZone time_zone);
|
2022-01-10 12:57:30 -05:00
|
|
|
Optional<StringView> canonicalize_time_zone(StringView time_zone);
|
2021-12-28 12:53:53 -05:00
|
|
|
|
2022-01-18 11:20:43 -05:00
|
|
|
Optional<DaylightSavingsRule> daylight_savings_rule_from_string(StringView daylight_savings_rule);
|
|
|
|
|
StringView daylight_savings_rule_to_string(DaylightSavingsRule daylight_savings_rule);
|
|
|
|
|
|
2023-03-13 22:28:08 +01:00
|
|
|
Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::UnixDateTime time);
|
|
|
|
|
Optional<Offset> get_time_zone_offset(StringView time_zone, AK::UnixDateTime time);
|
2022-01-10 16:56:09 -05:00
|
|
|
|
2023-03-13 22:28:08 +01:00
|
|
|
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::UnixDateTime time);
|
|
|
|
|
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::UnixDateTime time);
|
2022-01-24 12:36:17 -05:00
|
|
|
|
2022-02-02 14:31:05 -05:00
|
|
|
Optional<Location> get_time_zone_location(TimeZone time_zone);
|
|
|
|
|
Optional<Location> get_time_zone_location(StringView time_zone);
|
|
|
|
|
|
2022-07-05 15:56:23 -04:00
|
|
|
Optional<Region> region_from_string(StringView region);
|
|
|
|
|
StringView region_to_string(Region region);
|
|
|
|
|
Vector<StringView> time_zones_in_region(StringView region);
|
|
|
|
|
|
2021-12-28 12:53:53 -05:00
|
|
|
}
|
2023-04-18 18:31:00 +01:00
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct AK::Formatter<TimeZone::TimeZone> : Formatter<FormatString> {
|
|
|
|
|
ErrorOr<void> format(FormatBuilder& builder, TimeZone::TimeZone const& time_zone)
|
|
|
|
|
{
|
|
|
|
|
return Formatter<FormatString>::format(builder, TimeZone::time_zone_to_string(time_zone));
|
|
|
|
|
}
|
|
|
|
|
};
|