Monorepo management for opam overlays
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Replace custom date/time code with ptime across 4 packages

- ocaml-sgp4: epoch_unix uses Ptime.of_date instead of manual leap year math
- ocaml-oem: parse_epoch uses Ptime.of_rfc3339 ~strict:false, replacing
60 lines of manual ISO 8601 splitting
- space: parse_since uses Ptime.of_rfc3339 ~strict:false instead of Scanf
- monopam: day_of_week uses Ptime.weekday, add_days uses Ptime.add_span

Reviewed all 12 flagged spots in mono — the remaining 8 either already
use ptime properly (tomlt, cookeio, requests) or are not date parsing
(coordinate Julian arithmetic, filename extraction).

+14 -41
+14 -41
lib/changes.ml
··· 301 301 302 302 (* Week calculation *) 303 303 304 - (* Get day of week: 0 = Sunday, 1 = Monday, ... 6 = Saturday 305 - Using Zeller's congruence for Gregorian calendar *) 304 + (* Day of week: 0 = Sunday, 1 = Monday, ... 6 = Saturday *) 306 305 let day_of_week year month day = 307 - let y = if month < 3 then year - 1 else year in 308 - let m = if month < 3 then month + 12 else month in 309 - let q = day in 310 - let k = y mod 100 in 311 - let j = y / 100 in 312 - let h = (q + (13 * (m + 1) / 5) + k + (k / 4) + (j / 4) - (2 * j)) mod 7 in 313 - (* Convert from Zeller's (0=Sat) to standard (0=Sun) *) 314 - (h + 6) mod 7 306 + match Ptime.of_date (year, month, day) with 307 + | None -> 0 308 + | Some t -> 309 + (match Ptime.weekday t with 310 + | `Sun -> 0 | `Mon -> 1 | `Tue -> 2 | `Wed -> 3 311 + | `Thu -> 4 | `Fri -> 5 | `Sat -> 6) 315 312 316 313 let add_days (y, m, d) n = 317 - (* Simple day addition - handles month/year boundaries *) 318 - let days_in_month year month = 319 - match month with 320 - | 1 | 3 | 5 | 7 | 8 | 10 | 12 -> 31 321 - | 4 | 6 | 9 | 11 -> 30 322 - | 2 -> 323 - if (year mod 4 = 0 && year mod 100 <> 0) || year mod 400 = 0 then 29 324 - else 28 325 - | _ -> 30 326 - in 327 - let rec loop y m d n = 328 - if n = 0 then (y, m, d) 329 - else if n > 0 then 330 - let dim = days_in_month y m in 331 - if d + n <= dim then (y, m, d + n) 332 - else 333 - let remaining = dim - d in 334 - let new_m = if m = 12 then 1 else m + 1 in 335 - let new_y = if m = 12 then y + 1 else y in 336 - loop new_y new_m 1 (n - remaining - 1) 337 - else if 338 - (* n < 0 *) 339 - d + n >= 1 340 - then (y, m, d + n) 341 - else 342 - let new_m = if m = 1 then 12 else m - 1 in 343 - let new_y = if m = 1 then y - 1 else y in 344 - let dim = days_in_month new_y new_m in 345 - loop new_y new_m dim (n + d) 346 - in 347 - loop y m d n 314 + match Ptime.of_date (y, m, d) with 315 + | None -> (y, m, d) 316 + | Some t -> 317 + let span = Ptime.Span.of_int_s (n * 86400) in 318 + (match Ptime.add_span t span with 319 + | Some t' -> let (y', m', d'), _ = Ptime.to_date_time t' in (y', m', d') 320 + | None -> (y, m, d)) 348 321 349 322 let format_date (y, m, d) = Fmt.str "%04d-%02d-%02d" y m d 350 323