MCPcopy
hub / github.com/formatjs/formatjs / MonthFromTime

Function MonthFromTime

packages/ecma262-abstract/DateOperations.ts:44–62  ·  view source on GitHub ↗
(
  t: number
)

Source from the content-addressed store, hash-verified

42}
43
44export function MonthFromTime(
45 t: number
46): 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 {
47 const dwy = DayWithinYear(t)
48 const leap = InLeapYear(t)
49 if (dwy >= 0 && dwy < 31) return 0
50 if (dwy < 59 + leap) return 1
51 if (dwy < 90 + leap) return 2
52 if (dwy < 120 + leap) return 3
53 if (dwy < 151 + leap) return 4
54 if (dwy < 181 + leap) return 5
55 if (dwy < 212 + leap) return 6
56 if (dwy < 243 + leap) return 7
57 if (dwy < 273 + leap) return 8
58 if (dwy < 304 + leap) return 9
59 if (dwy < 334 + leap) return 10
60 if (dwy < 365 + leap) return 11
61 throw new Error('Invalid time')
62}
63
64export function DateFromTime(t: number): number {
65 const dwy = DayWithinYear(t)

Callers 2

ToLocalTimeFunction · 0.85
DateFromTimeFunction · 0.85

Calls 2

DayWithinYearFunction · 0.85
InLeapYearFunction · 0.85

Tested by

no test coverage detected