hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit df3e31a41ac143c482fba791831a1097b34909e2
parent 500b385c073fb93392224916035262d4c218bac5
Author: Byron Torres <b@torresjrjr.com>
Date:   Sat, 11 Jun 2022 03:54:43 +0100

datetime: add calc_janfirstweekday()

Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mdatetime/date.ha | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/datetime/date.ha b/datetime/date.ha @@ -58,6 +58,18 @@ fn calc_n_days_in_year(y: int) int = { }; }; +// Calculates the day-of-week of January 1st, given a year. +fn calc_janfirstweekday(y: int) int = { + const y = (y % 400) + 400; // keep year > 0 (using Gegorian cycle) + // Gauss' algorithm + const wd = ( + + 5 * ((y - 1) % 4) + + 4 * ((y - 1) % 100) + + 6 * ((y - 1) % 400) + ) % 7; + return wd + 1; +}; + // Calculates the era, given a year. fn calc_era(y: int) int = { return if (y >= 0) {