TimeZone.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Array.h>
  8. #include <AK/DeprecatedString.h>
  9. #include <AK/Error.h>
  10. #include <AK/Optional.h>
  11. #include <AK/StringView.h>
  12. #include <AK/Time.h>
  13. #include <AK/Types.h>
  14. #include <AK/Vector.h>
  15. #include <LibTimeZone/Forward.h>
  16. namespace TimeZone {
  17. enum class InDST {
  18. No,
  19. Yes,
  20. };
  21. struct Offset {
  22. i64 seconds { 0 };
  23. InDST in_dst { InDST::No };
  24. };
  25. struct NamedOffset : public Offset {
  26. DeprecatedString name;
  27. };
  28. struct Coordinate {
  29. constexpr float decimal_coordinate() const
  30. {
  31. return static_cast<float>(degrees) + (static_cast<float>(minutes) / 60.0f) + (static_cast<float>(seconds) / 3'600.0f);
  32. }
  33. i16 degrees { 0 };
  34. u8 minutes { 0 };
  35. u8 seconds { 0 };
  36. };
  37. struct Location {
  38. Coordinate latitude;
  39. Coordinate longitude;
  40. };
  41. StringView system_time_zone();
  42. StringView current_time_zone();
  43. ErrorOr<void> change_time_zone(StringView time_zone);
  44. ReadonlySpan<StringView> all_time_zones();
  45. Optional<TimeZone> time_zone_from_string(StringView time_zone);
  46. StringView time_zone_to_string(TimeZone time_zone);
  47. Optional<StringView> canonicalize_time_zone(StringView time_zone);
  48. Optional<DaylightSavingsRule> daylight_savings_rule_from_string(StringView daylight_savings_rule);
  49. StringView daylight_savings_rule_to_string(DaylightSavingsRule daylight_savings_rule);
  50. Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time);
  51. Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Time time);
  52. Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Time time);
  53. Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Time time);
  54. Optional<Location> get_time_zone_location(TimeZone time_zone);
  55. Optional<Location> get_time_zone_location(StringView time_zone);
  56. Optional<Region> region_from_string(StringView region);
  57. StringView region_to_string(Region region);
  58. Vector<StringView> time_zones_in_region(StringView region);
  59. }