ISORecords.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <AK/String.h>
  9. #include <AK/Types.h>
  10. #include <AK/Variant.h>
  11. #include <LibCrypto/BigInt/SignedBigInteger.h>
  12. namespace JS::Temporal {
  13. // 3.5.1 ISO Date Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-records
  14. struct ISODate {
  15. i32 year { 0 };
  16. u8 month { 0 };
  17. u8 day { 0 };
  18. };
  19. // 4.5.1 Time Records, https://tc39.es/proposal-temporal/#sec-temporal-time-records
  20. struct Time {
  21. double days { 0 };
  22. u8 hour { 0 };
  23. u8 minute { 0 };
  24. u8 second { 0 };
  25. u16 millisecond { 0 };
  26. u16 microsecond { 0 };
  27. u16 nanosecond { 0 };
  28. };
  29. // 5.5.1 ISO Date-Time Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-records
  30. struct ISODateTime {
  31. ISODate iso_date;
  32. Time time;
  33. };
  34. // 7.5.3 Internal Duration Records, https://tc39.es/proposal-temporal/#sec-temporal-internal-duration-records
  35. // A time duration is an integer in the inclusive interval from -maxTimeDuration to maxTimeDuration, where
  36. // maxTimeDuration = 2**53 × 10**9 - 1 = 9,007,199,254,740,991,999,999,999. It represents the portion of a
  37. // Temporal.Duration object that deals with time units, but as a combined value of total nanoseconds.
  38. using TimeDuration = Crypto::SignedBigInteger;
  39. // 9.5.1 ISO Year-Month Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-year-month-records
  40. struct ISOYearMonth {
  41. i32 year { 0 };
  42. u8 month { 0 };
  43. };
  44. // 13.31 ISO String Time Zone Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-string-time-zone-parse-records
  45. struct ParsedISOTimeZone {
  46. bool z_designator { false };
  47. Optional<String> offset_string;
  48. Optional<String> time_zone_annotation;
  49. };
  50. // 13.32 ISO Date-Time Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-parse-records
  51. struct ParsedISODateTime {
  52. struct StartOfDay { };
  53. Optional<i32> year { 0 };
  54. u8 month { 0 };
  55. u8 day { 0 };
  56. Variant<StartOfDay, Time> time;
  57. ParsedISOTimeZone time_zone;
  58. Optional<String> calendar;
  59. };
  60. }