mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-01 20:28:15 +00:00
[datetime]: Remove the definition of EPOCH
This commit is contained in:
@@ -5,13 +5,11 @@ Type representing a mononotic day number corresponding to a date.
|
|||||||
|
|
||||||
Ordinal 1 = Midnight Monday, January 1, 1 A.D. (Gregorian)
|
Ordinal 1 = Midnight Monday, January 1, 1 A.D. (Gregorian)
|
||||||
| Midnight Monday, January 3, 1 A.D. (Julian)
|
| Midnight Monday, January 3, 1 A.D. (Julian)
|
||||||
|
|
||||||
|
Every other ordinal counts days forwards, starting from the above date.
|
||||||
*/
|
*/
|
||||||
Ordinal :: i64
|
Ordinal :: i64
|
||||||
|
|
||||||
/*
|
|
||||||
*/
|
|
||||||
EPOCH :: Ordinal(1)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Minimum valid value for date.
|
Minimum valid value for date.
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ This procedure takes the value of an ordinal and returns the day of week for
|
|||||||
that ordinal.
|
that ordinal.
|
||||||
*/
|
*/
|
||||||
day_of_week :: proc "contextless" (ordinal: Ordinal) -> (day: Weekday) {
|
day_of_week :: proc "contextless" (ordinal: Ordinal) -> (day: Weekday) {
|
||||||
return Weekday((ordinal - EPOCH + 1) %% 7)
|
return Weekday(ordinal %% 7)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -349,8 +349,7 @@ the result is unspecified.
|
|||||||
unsafe_date_to_ordinal :: proc "contextless" (date: Date) -> (ordinal: Ordinal) {
|
unsafe_date_to_ordinal :: proc "contextless" (date: Date) -> (ordinal: Ordinal) {
|
||||||
year_minus_one := date.year - 1
|
year_minus_one := date.year - 1
|
||||||
|
|
||||||
// Day before epoch
|
ordinal = 0
|
||||||
ordinal = EPOCH - 1
|
|
||||||
|
|
||||||
// Add non-leap days
|
// Add non-leap days
|
||||||
ordinal += 365 * year_minus_one
|
ordinal += 365 * year_minus_one
|
||||||
@@ -382,17 +381,17 @@ This procedure returns the year and the day of the year of a given ordinal.
|
|||||||
Of the ordinal is outside of its valid range, the result is unspecified.
|
Of the ordinal is outside of its valid range, the result is unspecified.
|
||||||
*/
|
*/
|
||||||
unsafe_ordinal_to_year :: proc "contextless" (ordinal: Ordinal) -> (year: i64, day_ordinal: i64) {
|
unsafe_ordinal_to_year :: proc "contextless" (ordinal: Ordinal) -> (year: i64, day_ordinal: i64) {
|
||||||
// Days after epoch
|
// Correct for leap year cycle starting at day 1.
|
||||||
d0 := ordinal - EPOCH
|
d0 := ordinal - 1
|
||||||
|
|
||||||
// Number of 400-year cycles and remainder
|
// Number of 400-year cycles and remainder
|
||||||
n400, d1 := divmod(d0, 146097)
|
n400, d1 := divmod(d0, 365*400 + 100 - 3)
|
||||||
|
|
||||||
// Number of 100-year cycles and remainder
|
// Number of 100-year cycles and remainder
|
||||||
n100, d2 := divmod(d1, 36524)
|
n100, d2 := divmod(d1, 365*100 + 25 - 1)
|
||||||
|
|
||||||
// Number of 4-year cycles and remainder
|
// Number of 4-year cycles and remainder
|
||||||
n4, d3 := divmod(d2, 1461)
|
n4, d3 := divmod(d2, 365*4 + 1)
|
||||||
|
|
||||||
// Number of remaining days
|
// Number of remaining days
|
||||||
n1, d4 := divmod(d3, 365)
|
n1, d4 := divmod(d3, 365)
|
||||||
|
|||||||
Reference in New Issue
Block a user