| 1 | module time |
| 2 | |
| 3 | fn test_days_from_unix_epoch() { |
| 4 | s := '2000-05-10 22:11:03' |
| 5 | time_test := parse(s) or { |
| 6 | eprintln('> failing format: ${s} | err: ${err}') |
| 7 | assert false |
| 8 | return |
| 9 | } |
| 10 | one_day_in_seconds := 86400 |
| 11 | |
| 12 | assert time_test.days_from_unix_epoch() == 11087 |
| 13 | assert time_test.days_from_unix_epoch() == int(time_test.unix / one_day_in_seconds) |
| 14 | assert days_from_unix_epoch(1970, 1, 1) == 0 |
| 15 | assert days_from_unix_epoch(1970, 2, 1) == 31 |
| 16 | assert days_from_unix_epoch(1970, 3, 1) == 59 |
| 17 | assert days_from_unix_epoch(2022, 11, 10) == 19306 |
| 18 | } |
| 19 | |
| 20 | fn test_date_from_days_after_unix_epoch() { |
| 21 | assert date_from_days_after_unix_epoch(11087).year == 2000 |
| 22 | assert date_from_days_after_unix_epoch(11087).month == 5 |
| 23 | assert date_from_days_after_unix_epoch(11087).day == 10 |
| 24 | assert date_from_days_after_unix_epoch(1).year == 1970 |
| 25 | assert date_from_days_after_unix_epoch(1).month == 1 |
| 26 | assert date_from_days_after_unix_epoch(1).day == 2 |
| 27 | |
| 28 | assert date_from_days_after_unix_epoch(31).year == 1970 |
| 29 | assert date_from_days_after_unix_epoch(31).month == 2 |
| 30 | assert date_from_days_after_unix_epoch(31).day == 1 |
| 31 | |
| 32 | assert date_from_days_after_unix_epoch(59).year == 1970 |
| 33 | assert date_from_days_after_unix_epoch(59).month == 3 |
| 34 | assert date_from_days_after_unix_epoch(59).day == 1 |
| 35 | } |
| 36 | |