def tz.day.index
bend-kit-time@0.3.0.0 · time.bend:1056
import bend-kit-time@0.3.0.0/time.bend as Time
import Base
import bend-kit-int@0.2.0.0/int.bend as Int
1056
1057def tz.day.index(d: TzDay, +y: U32) -> U32:
1058 match d:
1059 case Julian{+n}:
1060 (n - 1 + Bool.pick(U32, Bool.and(Date.is_leap(y), U32.is_ge(n, 60)), 1, 0) : U32)
1061 case Ordinal{n}:
1062 n
1063 case MonthWeek{+month, +week, +weekday}:
1064 +first_day = (Date.weekday(Date{y, month, 1}) % 7 : U32)
1065 +day = (1 + ((weekday + 7 - first_day) % 7) + (week - 1) * 7 : U32)
1066 +last = Date.days_in_month(y, month)
1067 +actual = Bool.pick(U32, U32.is_gt(day, last), (day - 7 : U32), day)
1068 Int.I64.to_u32(Int.I64.sub(Date.to_days(Date{y, month, actual}), Date.to_days(Date{y, 1, 1})))