DateToEpochDay converts a Date to its day offset from the Unix epoch.
(date Date)
| 98 | |
| 99 | // DateToEpochDay converts a Date to its day offset from the Unix epoch. |
| 100 | func DateToEpochDay(date Date) (int64, error) { |
| 101 | year := int64(date.Year) |
| 102 | if date.Month < time.January || date.Month > time.December { |
| 103 | return 0, SerializationErrorf("invalid date month %d", date.Month) |
| 104 | } |
| 105 | maxDay := daysInMonth(year, date.Month) |
| 106 | if date.Day < 1 || date.Day > maxDay { |
| 107 | return 0, SerializationErrorf( |
| 108 | "invalid date day %d for %d-%02d", |
| 109 | date.Day, |
| 110 | date.Year, |
| 111 | int(date.Month), |
| 112 | ) |
| 113 | } |
| 114 | return daysFromCivil(year, date.Month, int64(date.Day)), nil |
| 115 | } |
| 116 | |
| 117 | // DateFromEpochDay converts a Unix-epoch day offset to a Date. |
| 118 | func DateFromEpochDay(days int64) (Date, error) { |