From 2ad15b774f4abf64bee727bf3b674473e9e7faae Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Sat, 13 Jun 2026 17:20:36 +0200 Subject: [PATCH] style(schema): drop vestigial day clamp in DurationValue.instant The reference dates are all day 1, so min(1, daysInMonth(...)) was always 1; the clamp read as if the day could vary. Pass day 1 directly with a comment explaining why no clamp is needed. No behavior change. Found by the PR critic pass. --- Sources/Schema/DurationValue.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Schema/DurationValue.swift b/Sources/Schema/DurationValue.swift index 80b5254..adfaf99 100644 --- a/Sources/Schema/DurationValue.swift +++ b/Sources/Schema/DurationValue.swift @@ -42,9 +42,10 @@ extension PureXML.Schema { return .incomparable } - /// The instant, in seconds, of `reference` (day 1) + (months, seconds): - /// add the months with calendar rollover (clamping the day to the - /// resulting month's length, per the spec), then add the seconds. + /// The instant, in seconds, of `reference` + (months, seconds): add the + /// months with calendar rollover, then add the seconds. The reference + /// day is always 1, which is valid in every month, so no day clamping is + /// needed (a duration's day component lives in `seconds`, not here). private static func instant( _ reference: (year: Int, month: Int), addingMonths addMonths: Int, @@ -54,8 +55,7 @@ extension PureXML.Schema { let yearsCarried = Int((Double(total) / 12.0).rounded(.down)) let newYear = reference.year + yearsCarried let newMonth = total - yearsCarried * 12 + 1 - let newDay = Swift.min(1, DateTimeValue.daysInMonth(year: newYear, month: newMonth)) - let days = DateTimeValue.daysFromCivil(year: newYear, month: newMonth, day: newDay) + let days = DateTimeValue.daysFromCivil(year: newYear, month: newMonth, day: 1) return Double(days) * 86400 + seconds }