TimeZone.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/Error.h>
  9. #include <AK/Optional.h>
  10. #include <AK/String.h>
  11. #include <AK/StringView.h>
  12. #include <AK/Time.h>
  13. #include <AK/Types.h>
  14. #include <LibTimeZone/Forward.h>
  15. namespace TimeZone {
  16. enum class InDST {
  17. No,
  18. Yes,
  19. };
  20. struct Offset {
  21. i64 seconds { 0 };
  22. InDST in_dst { InDST::No };
  23. };
  24. struct NamedOffset : public Offset {
  25. String name;
  26. };
  27. struct Coordinate {
  28. constexpr float decimal_coordinate() const
  29. {
  30. return static_cast<float>(degrees) + (static_cast<float>(minutes) / 60.0f) + (static_cast<float>(seconds) / 3'600.0f);
  31. }
  32. i16 degrees { 0 };
  33. u8 minutes { 0 };
  34. u8 seconds { 0 };
  35. };
  36. struct Location {
  37. Coordinate latitude;
  38. Coordinate longitude;
  39. };
  40. StringView system_time_zone();
  41. StringView current_time_zone();
  42. ErrorOr<void> change_time_zone(StringView time_zone);
  43. Span<StringView const> all_time_zones();
  44. Optional<TimeZone> time_zone_from_string(StringView time_zone);
  45. StringView time_zone_to_string(TimeZone time_zone);
  46. Optional<StringView> canonicalize_time_zone(StringView time_zone);
  47. Optional<DaylightSavingsRule> daylight_savings_rule_from_string(StringView daylight_savings_rule);
  48. StringView daylight_savings_rule_to_string(DaylightSavingsRule daylight_savings_rule);
  49. Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time);
  50. Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Time time);
  51. Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Time time);
  52. Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Time time);
  53. Optional<Location> get_time_zone_location(TimeZone time_zone);
  54. Optional<Location> get_time_zone_location(StringView time_zone);
  55. }