summaryrefslogtreecommitdiff
path: root/date-fns/src/locale/types.ts
blob: b82c2275f12a9ad576ad923c9003d7f453b73ae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
export interface Locale {
  code: string
  formatDistance: FormatDistanceFn
  formatRelative: FormatRelativeFn
  localize: Localize
  formatLong: FormatLong
  match: Match
  options?: LocaleOptions
}

export interface LocaleOptions {
  weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6
  firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
}

export type FormatDistanceFn = (
  token:
    | 'lessThanXSeconds'
    | 'xSeconds'
    | 'halfAMinute'
    | 'lessThanXMinutes'
    | 'xMinutes'
    | 'aboutXHours'
    | 'xHours'
    | 'xDays'
    | 'aboutXMonths'
    | 'xMonths'
    | 'aboutXYears'
    | 'xYears'
    | 'overXYears'
    | 'almostXYears',
  count: number,
  options?: {
    addSuffix?: boolean
    comparison?: -1 | 0 | 1
  }
) => string

export type FormatRelativeFn = (
  token: 'lastWeek' | 'yesterday' | 'today' | 'tomorrow' | 'nextWeek' | 'other',
  date: Date | number,
  baseDate: Date | number,
  options?: { weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 }
) => string

export type LocalizeFn<TValue> = (
  value: TValue,
  options?: {
    width?: 'narrow' | 'short' | 'abbreviated' | 'wide'
    context?: 'formatting' | 'standalone'
  }
) => string

export interface Localize {
  ordinalNumber: LocalizeFn<number>
  era: LocalizeFn<0 | 1>
  quarter: LocalizeFn<1 | 2 | 3 | 4>
  month: LocalizeFn<0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11>
  day: LocalizeFn<0 | 1 | 2 | 3 | 4 | 5 | 6>
  dayPeriod: LocalizeFn<
    | 'am'
    | 'pm'
    | 'midnight'
    | 'noon'
    | 'morning'
    | 'afternoon'
    | 'evening'
    | 'night'
  >
}

export type FormatLongFn = (options?: {
  width?: 'full' | 'long' | 'medium' | 'short'
}) => string

export interface FormatLong {
  date: FormatLongFn
  time: FormatLongFn
  dateTime: FormatLongFn
}

export type MatchFn<TResult> = (
  str: string,
  options?: {
    width?: 'narrow' | 'short' | 'abbreviated' | 'wide'
  }
) => TResult

export interface Match {
  ordinalNumber: MatchFn<number>
  era: MatchFn<0 | 1>
  quarter: MatchFn<1 | 2 | 3 | 4>
  month: MatchFn<0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11>
  day: MatchFn<0 | 1 | 2 | 3 | 4 | 5 | 6>
  dayPeriod: MatchFn<
    | 'am'
    | 'pm'
    | 'midnight'
    | 'noon'
    | 'morning'
    | 'afternoon'
    | 'evening'
    | 'night'
  >
}