change refactored a helper function to be an anonymous function, as it only existed because of error handling.
1 files changed, 20 insertions(+), 1 deletions(-)

M ifc.v
M ifc.v +20 -1
@@ 77,7 77,26 @@ pub fn IFC.from_time(t time.Time) !IFC {
 }
 
 fn (i IFC) month() Month {
-	if m := i.maybe_month() {
+	maybe_month := fn (i IFC) !Month {
+		if i.is_leap && i.day_of_year == 169 {
+			return Month.from(5)
+		}
+
+		if i.day_of_year == 365 || i.day_of_year == 366 {
+			return Month.from(12)
+		}
+
+		mut res := math.divide_euclid(i.day_of_year - 1, max_days)
+		if i.is_leap && i.day_of_year > 169 {
+			res = math.divide_euclid(i.day_of_year - 2, max_days)
+		}
+		mon, day := res.quot, res.rem
+		if day == 0 && mon != 13 {
+			return Month.from(mon)
+		}
+		return Month.from(mon)
+	}
+	if m := maybe_month(i) {
 		return m
 	}
 	return Month.january