constants.odin 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package datetime
  2. /*
  3. Type representing a mononotic day number corresponding to a date.
  4. Ordinal 1 = Midnight Monday, January 1, 1 A.D. (Gregorian)
  5. | Midnight Monday, January 3, 1 A.D. (Julian)
  6. */
  7. Ordinal :: i64
  8. /*
  9. */
  10. EPOCH :: Ordinal(1)
  11. /*
  12. Minimum valid value for date.
  13. The value is chosen such that a conversion `date -> ordinal -> date` is always
  14. safe.
  15. */
  16. MIN_DATE :: Date{year = -25_252_734_927_766_552, month = 1, day = 1}
  17. /*
  18. Maximum valid value for date
  19. The value is chosen such that a conversion `date -> ordinal -> date` is always
  20. safe.
  21. */
  22. MAX_DATE :: Date{year = 25_252_734_927_766_552, month = 12, day = 31}
  23. /*
  24. Minimum value for an ordinal
  25. */
  26. MIN_ORD :: Ordinal(-9_223_372_036_854_775_234)
  27. /*
  28. Maximum value for an ordinal
  29. */
  30. MAX_ORD :: Ordinal( 9_223_372_036_854_774_869)
  31. /*
  32. Possible errors returned by datetime functions.
  33. */
  34. Error :: enum {
  35. None,
  36. Invalid_Year,
  37. Invalid_Month,
  38. Invalid_Day,
  39. Invalid_Hour,
  40. Invalid_Minute,
  41. Invalid_Second,
  42. Invalid_Nano,
  43. Invalid_Ordinal,
  44. Invalid_Delta,
  45. }
  46. /*
  47. A type representing a date.
  48. The minimum and maximum values for a year can be found in `MIN_DATE` and
  49. `MAX_DATE` constants. The `month` field can range from 1 to 12, and the day
  50. ranges from 1 to however many days there are in the specified month.
  51. */
  52. Date :: struct {
  53. year: i64,
  54. month: i8,
  55. day: i8,
  56. }
  57. /*
  58. A type representing a time within a single day within a nanosecond precision.
  59. */
  60. Time :: struct {
  61. hour: i8,
  62. minute: i8,
  63. second: i8,
  64. nano: i32,
  65. }
  66. /*
  67. A type representing datetime.
  68. */
  69. DateTime :: struct {
  70. using date: Date,
  71. using time: Time,
  72. }
  73. /*
  74. A type representing a difference between two instances of datetime.
  75. **Note**: All fields are i64 because we can also use it to add a number of
  76. seconds or nanos to a moment, that are then normalized within their respective
  77. ranges.
  78. */
  79. Delta :: struct {
  80. days: i64,
  81. seconds: i64,
  82. nanos: i64,
  83. }
  84. /*
  85. Type representing one of the months.
  86. */
  87. Month :: enum i8 {
  88. January = 1,
  89. February,
  90. March,
  91. April,
  92. May,
  93. June,
  94. July,
  95. August,
  96. September,
  97. October,
  98. November,
  99. December,
  100. }
  101. /*
  102. Type representing one of the weekdays.
  103. */
  104. Weekday :: enum i8 {
  105. Sunday = 0,
  106. Monday,
  107. Tuesday,
  108. Wednesday,
  109. Thursday,
  110. Friday,
  111. Saturday,
  112. }
  113. @(private)
  114. MONTH_DAYS :: [?]i8{-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}