-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
209 lines (194 loc) · 7.68 KB
/
mod.ts
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* # ComPlainDate
*
* Date-time utilities that keep timezones on the surface.
*
* ## Objects
*
* The {@link ComPlainDate} interface describes plain-date objects that can be
* created with the {@link PlainDate} factory.
*
* The {@link ComPlainTime} interface describes wall-time objects that can be
* created with the {@link PlainTime} factory.
*
* ### Objects extended for convenience
*
* _Note:_ The extended objects are not tree-shakable, so using them will
* increase your bundle size... a lot. They are meant for use in backend code
* only — *always use the main objects with utility functions in frontend code!*
*
* An extended type of plain-date object is described by the
* {@link ExtendedPlainDate} interface.
* Those objects are created with the {@link ExPlainDate} factory, which also
* implements the optional functions of the {@link PlainDateFactory} interface.
*
* ## Utility functions
*
* ### Parsing strings into objects
*
* - {@link parsePlainDate} (extract plain-date from string)
* - {@link parsePlainTime} (extract plain-time from string)
*
* ### Splitting native JS `Date` objects into separate plain-date & plain-time objects
*
* - {@link splitDateTime} - requires a named timezone
* - {@link splitLocalDateTime}
* - {@link splitUtcDateTime}
*
* ### Generating a new plain-date object from an existing one
*
* - {@link addBusinessDays}
* - {@link addDays}
* - {@link addMonths}
* - {@link addQuarters}
* - {@link addYears}
* - {@link firstWeekDay}
* - {@link startOfBusinessWeek}
* - {@link startOfMonth}
* - {@link startOfQuarter}
* - {@link startOfWeekend}
* - {@link startOfYear}
*
* Also see {@link pipePlainDate} and related type {@link PlainDateMapFn} that
* are useful when implementing your own plain-date mapper functions.
*
* ### Making user interface strings
*
* - {@link formatPlainDate}
* - {@link formatPlainTime}
* - {@link formatInstant}
* - {@link formatTimezone}
* - {@link formatDatetimeLocal} (for HTML datetime-local inputs)
*
* ### Getting information about a plain-date object
*
* - {@link daysInMonth}
* - {@link daysInYear}
* - {@link isBusinessDay} and inverse {@link isWeekendDay}
* - {@link isFirstDayOfMonth} and {@link isLastDayOfMonth}
* - {@link isFirstDayOfYear} and {@link isLastDayOfYear}
* - {@link isLeapYear}
* - {@link ordinal} (day of the year)
* - {@link quarter}
* - {@link weekDayNumber}
*
* ### Comparing plain-date objects
*
* - {@link differenceInBusinessDays}
* - {@link differenceInDays}
* - {@link differenceInMonths}
* - {@link differenceInQuarters}
* - {@link differenceInYears}
*
* ### Creating native JS `Date` objects from plain-date & plain-time objects
*
* - {@link createInstant} - requires a named timezone
* - {@link createLocalInstant}
* - {@link createUtcInstant}
*
* ### Generating a new native JS `Date` object from an existing one
*
* - {@link addTime}
* - {@link subtractTime}
*
* ### Comparing native JS `Date` objects
*
* - {@link differenceInMilliseconds}
*
* ### Working with timezone names
*
* - {@link safeTimezone} - falls back to system timezone
* - {@link localTimezone} (operating system timezone)
* - {@link supportedCanonicalTimezones}
* - {@link isTimezone}
* - {@link sanitizeTimezone} (clean up timezone name)
* - {@link parseTimezone} (extract timezone name from string) - throws error on failure
*
* @module()
*/
// Main objects
export { PlainDate } from "./PlainDate.ts";
export type { ComPlainDate, PlainDateFactory } from "./PlainDate.ts";
export { PlainTime } from "./PlainTime.ts";
export type { ComPlainTime, PlainTimeFactory } from "./PlainTime.ts";
// Extended objects
export { ExPlainDate } from "./ExPlainDate.ts";
export type { ExtendedPlainDate } from "./ExPlainDate.ts";
// Constants
export {
BUSINESS_DAYS_IN_WEEK,
DAYS_IN_COMMON_YEAR,
DAYS_IN_LEAP_YEAR,
DAYS_IN_WEEK,
HOURS_IN_DAY,
Month,
MS_IN_HOUR,
MS_IN_MINUTE,
MS_IN_SECOND,
Quarter,
WeekDay,
} from "./constants.ts";
export type { MonthNumber, QuarterNumber, WeekDayNumber } from "./constants.ts";
// Types
export type { PlainDateMapFn } from "./support/function-signatures.ts";
// Utils for parsing strings into objects
export { parsePlainDate } from "./utils/parsePlainDate.ts";
export { parsePlainTime } from "./utils/parsePlainTime.ts";
// Utils for splitting native JS `Date` objects into separate plain-date & plain-time objects
export { splitDateTime } from "./utils/splitDateTime.ts";
export { splitLocalDateTime } from "./utils/splitLocalDateTime.ts";
export { splitUtcDateTime } from "./utils/splitUtcDateTime.ts";
// Utils for generating a new plain-date object from an existing one
export { pipePlainDate } from "./utils/pipePlainDate.ts";
export { addBusinessDays } from "./utils/addBusinessDays.ts";
export { addDays } from "./utils/addDays.ts";
export { addMonths } from "./utils/addMonths.ts";
export { addQuarters } from "./utils/addQuarters.ts";
export { addYears } from "./utils/addYears.ts";
export { firstWeekDay } from "./utils/firstWeekDay.ts";
export { startOfBusinessWeek } from "./utils/startOfBusinessWeek.ts";
export { startOfMonth } from "./utils/startOfMonth.ts";
export { startOfQuarter } from "./utils/startOfQuarter.ts";
export { startOfWeekend } from "./utils/startOfWeekend.ts";
export { startOfYear } from "./utils/startOfYear.ts";
// Utils for making user interface strings
export { formatDatetimeLocal } from "./utils/formatDatetimeLocal.ts";
export { formatPlainDate } from "./utils/formatPlainDate.ts";
export { formatPlainTime } from "./utils/formatPlainTime.ts";
export { formatInstant } from "./utils/formatInstant.ts";
export { formatTimezone } from "./utils/formatTimezone.ts";
// Utils for getting information about a plain-date object
export { daysInMonth } from "./utils/daysInMonth.ts";
export { daysInYear } from "./utils/daysInYear.ts";
export { isBusinessDay } from "./utils/isBusinessDay.ts";
export { isFirstDayOfMonth } from "./utils/isFirstDayOfMonth.ts";
export { isFirstDayOfYear } from "./utils/isFirstDayOfYear.ts";
export { isLastDayOfMonth } from "./utils/isLastDayOfMonth.ts";
export { isLastDayOfYear } from "./utils/isLastDayOfYear.ts";
export { isLeapYear } from "./utils/isLeapYear.ts";
export { isWeekendDay } from "./utils/isWeekendDay.ts";
export { ordinal } from "./utils/ordinal.ts";
export { quarter } from "./utils/quarter.ts";
export { weekDayNumber } from "./utils/weekDayNumber.ts";
// Utils for comparing plain-date objects
export { differenceInBusinessDays } from "./utils/differenceInBusinessDays.ts";
export { differenceInDays } from "./utils/differenceInDays.ts";
export { differenceInMonths } from "./utils/differenceInMonths.ts";
export { differenceInQuarters } from "./utils/differenceInQuarters.ts";
export { differenceInYears } from "./utils/differenceInYears.ts";
// Utils for creating native JS `Date` objects from plain-date & plain-time objects
export { createInstant } from "./utils/createInstant.ts";
export { createLocalInstant } from "./utils/createLocalInstant.ts";
export { createUtcInstant } from "./utils/createUtcInstant.ts";
// Utils for generating a new native JS `Date` object from an existing one
export { addTime } from "./utils/addTime.ts";
export { subtractTime } from "./utils/subtractTime.ts";
// Utils for comparing native JS `Date` objects
export { differenceInMilliseconds } from "./utils/differenceInMilliseconds.ts";
// Utils for working with timezone names
export { safeTimezone } from "./utils/safeTimezone.ts";
export { localTimezone } from "./utils/localTimezone.ts";
export { supportedCanonicalTimezones } from "./utils/supportedCanonicalTimezones.ts";
export { isTimezone } from "./utils/isTimezone.ts";
export { sanitizeTimezone } from "./utils/sanitizeTimezone.ts";
export { parseTimezone } from "./utils/parseTimezone.ts";