MCPcopy Create free account
hub / github.com/Effect-TS/effect / civilFromDays

Function civilFromDays

packages/sql/pg/src/PgTypes.ts:519–530  ·  view source on GitHub ↗
(days: number)

Source from the content-addressed store, hash-verified

517
518/** Civil date from days since 1970-01-01, after Howard Hinnant's algorithm. */
519const civilFromDays = (days: number): { year: number; month: number; day: number } => {
520 const z = days + 719468
521 const era = Math.floor(z / 146097)
522 const doe = z - era * 146097
523 const yoe = Math.floor((doe - Math.floor(doe / 1460) + Math.floor(doe / 36524) - Math.floor(doe / 146096)) / 365)
524 const y = yoe + era * 400
525 const doy = doe - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100))
526 const mp = Math.floor((5 * doy + 2) / 153)
527 const day = doy - Math.floor((153 * mp + 2) / 5) + 1
528 const month = mp < 10 ? mp + 3 : mp - 9
529 return { year: month <= 2 ? y + 1 : y, month, day }
530}
531
532/** Days since 1970-01-01 from a civil date. */
533const daysFromCivil = (year: number, month: number, day: number): number => {

Callers 1

formatDateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected