MCPcopy
hub / github.com/date-fns/date-fns / y

Function y

pkgs/core/src/_lib/format/lightFormatters/index.ts:18–32  ·  view source on GitHub ↗
(date: Date, token: string)

Source from the content-addressed store, hash-verified

16export const lightFormatters = {
17 // Year
18 y(date: Date, token: string): string {
19 // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
20 // | Year | y | yy | yyy | yyyy | yyyyy |
21 // |----------|-------|----|-------|-------|-------|
22 // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
23 // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
24 // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
25 // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
26 // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
27
28 const signedYear = date.getFullYear();
29 // Returns 1 for 1 BC (which is year 0 in JavaScript)
30 const year = signedYear > 0 ? signedYear : 1 - signedYear;
31 return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
32 },
33
34 // Month
35 M(date: Date, token: string): string {

Callers

nothing calls this directly

Calls 1

addLeadingZerosFunction · 0.90

Tested by

no test coverage detected