2021-12-28 20:53:53 +03:00
|
|
|
/*
|
2022-01-31 21:07:22 +03:00
|
|
|
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
2021-12-28 20:53:53 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-01-24 20:36:17 +03:00
|
|
|
#include <AK/Array.h>
|
2022-12-04 21:02:33 +03:00
|
|
|
#include <AK/DeprecatedString.h>
|
2022-01-20 19:55:48 +03:00
|
|
|
#include <AK/Error.h>
|
2021-12-28 20:53:53 +03:00
|
|
|
#include <AK/Optional.h>
|
|
|
|
#include <AK/StringView.h>
|
2022-01-11 00:56:09 +03:00
|
|
|
#include <AK/Time.h>
|
|
|
|
#include <AK/Types.h>
|
2022-07-05 22:56:23 +03:00
|
|
|
#include <AK/Vector.h>
|
2021-12-28 20:53:53 +03:00
|
|
|
#include <LibTimeZone/Forward.h>
|
|
|
|
|
|
|
|
namespace TimeZone {
|
|
|
|
|
2022-01-19 22:18:02 +03:00
|
|
|
enum class InDST {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Offset {
|
|
|
|
i64 seconds { 0 };
|
|
|
|
InDST in_dst { InDST::No };
|
|
|
|
};
|
|
|
|
|
2022-01-24 20:36:17 +03:00
|
|
|
struct NamedOffset : public Offset {
|
2022-12-04 21:02:33 +03:00
|
|
|
DeprecatedString name;
|
2022-01-24 20:36:17 +03:00
|
|
|
};
|
|
|
|
|
2022-02-02 22:31:05 +03: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-25 03:55:19 +03:00
|
|
|
StringView system_time_zone();
|
2022-01-12 07:21:36 +03:00
|
|
|
StringView current_time_zone();
|
2022-01-20 19:55:48 +03:00
|
|
|
ErrorOr<void> change_time_zone(StringView time_zone);
|
2022-01-20 02:05:31 +03:00
|
|
|
Span<StringView const> all_time_zones();
|
2022-01-12 07:21:36 +03:00
|
|
|
|
2021-12-28 20:53:53 +03:00
|
|
|
Optional<TimeZone> time_zone_from_string(StringView time_zone);
|
2022-01-10 20:45:16 +03:00
|
|
|
StringView time_zone_to_string(TimeZone time_zone);
|
2022-01-10 20:57:30 +03:00
|
|
|
Optional<StringView> canonicalize_time_zone(StringView time_zone);
|
2021-12-28 20:53:53 +03:00
|
|
|
|
2022-01-18 19:20:43 +03:00
|
|
|
Optional<DaylightSavingsRule> daylight_savings_rule_from_string(StringView daylight_savings_rule);
|
|
|
|
StringView daylight_savings_rule_to_string(DaylightSavingsRule daylight_savings_rule);
|
|
|
|
|
2022-01-19 22:18:02 +03:00
|
|
|
Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time);
|
|
|
|
Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Time time);
|
2022-01-11 00:56:09 +03:00
|
|
|
|
2022-01-24 20:36:17 +03:00
|
|
|
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Time time);
|
|
|
|
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Time time);
|
|
|
|
|
2022-02-02 22:31:05 +03:00
|
|
|
Optional<Location> get_time_zone_location(TimeZone time_zone);
|
|
|
|
Optional<Location> get_time_zone_location(StringView time_zone);
|
|
|
|
|
2022-07-05 22:56:23 +03: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 20:53:53 +03:00
|
|
|
}
|