UNPKG

7.86 kBTypeScriptView Raw
1import type { Locale } from "./locale/types.js";
2export type * from "./locale/types.js";
3export type * from "./fp/types.js";
4/**
5 * The generic date constructor. Replicates the Date constructor. Used to build
6 * generic functions.
7 *
8 * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
9 */
10export interface GenericDateConstructor<DateType extends Date = Date> {
11 /**
12 * The date constructor. Creates date with the current date and time.
13 *
14 * @returns The date instance
15 */
16 new (): DateType;
17 /**
18 * The date constructor. Creates date with the passed date, number of
19 * milliseconds or string to parse.
20 *
21 * @param value - The date, number of milliseconds or string to parse
22 *
23 * @returns The date instance
24 */
25 new (value: Date | number | string): DateType;
26 /**
27 * The date constructor. Creates date with the passed date values (year,
28 * month, etc.) Note that the month is 0-indexed.
29 *
30 * @param year - The year
31 * @param month - The month. Note that the month is 0-indexed.
32 * @param date - The day of the month
33 * @param hours - The hours
34 * @param minutes - The minutes
35 * @param seconds - The seconds
36 * @param ms - The milliseconds
37 *
38 * @returns The date instance
39 */
40 new (
41 year: number,
42 month: number,
43 date?: number,
44 hours?: number,
45 minutes?: number,
46 seconds?: number,
47 ms?: number,
48 ): DateType;
49}
50/**
51 * The duration object. Contains the duration in the units specified by the
52 * object.
53 */
54export interface Duration {
55 /** The number of years in the duration */
56 years?: number;
57 /** The number of months in the duration */
58 months?: number;
59 /** The number of weeks in the duration */
60 weeks?: number;
61 /** The number of days in the duration */
62 days?: number;
63 /** The number of hours in the duration */
64 hours?: number;
65 /** The number of minutes in the duration */
66 minutes?: number;
67 /** The number of seconds in the duration */
68 seconds?: number;
69}
70/**
71 * The duration unit type alias.
72 */
73export type DurationUnit = keyof Duration;
74/**
75 * An object that combines two dates to represent the time interval.
76 *
77 * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
78 */
79export interface Interval<DateType extends Date = Date> {
80 /** The start of the interval. */
81 start: DateType | number | string;
82 /** The end of the interval. */
83 end: DateType | number | string;
84}
85/**
86 * A version of {@link Interval} that has both start and end resolved to Date.
87 */
88export interface NormalizedInterval<DateType extends Date = Date> {
89 /** The start of the interval. */
90 start: DateType;
91 /** The end of the interval. */
92 end: DateType;
93}
94/**
95 * The era. Can be either 0 (AD - Anno Domini) or 1 (BC - Before Christ).
96 */
97export type Era = 0 | 1;
98/**
99 * The year quarter. Goes from 1 to 4.
100 */
101export type Quarter = 1 | 2 | 3 | 4;
102/**
103 * The day of the week type alias. Unlike the date (the number of days since
104 * the beginning of the month), which begins with 1 and is dynamic (can go up to
105 * 28, 30, or 31), the day starts with 0 and static (always ends at 6). Look at
106 * it as an index in an array where Sunday is the first element and Saturday
107 * is the last.
108 */
109export type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6;
110/**
111 * The month type alias. Goes from 0 to 11, where 0 is January and 11 is
112 * December.
113 */
114export type Month = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
115/**
116 * FirstWeekContainsDate is used to determine which week is the first week of
117 * the year, based on what day the January, 1 is in that week.
118 *
119 * The day in that week can only be 1 (Monday) or 4 (Thursday).
120 *
121 * Please see https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system for more information.
122 */
123export type FirstWeekContainsDate = 1 | 4;
124/**
125 * The date values, used to set or get date object values.
126 */
127export interface DateValues {
128 /** The year */
129 year?: number;
130 /** The month */
131 month?: number;
132 /** The day of the month */
133 date?: number;
134 /** The hours */
135 hours?: number;
136 /** The minutes */
137 minutes?: number;
138 /** The seconds */
139 seconds?: number;
140 /** The milliseconds */
141 milliseconds?: number;
142}
143/**
144 * The number rounding method.
145 */
146export type RoundingMethod = "ceil" | "floor" | "round" | "trunc";
147/**
148 * The ISO string format.
149 *
150 * - basic: Minimal number of separators
151 * - extended: With separators added to enhance human readability
152 */
153export type ISOStringFormat = "extended" | "basic";
154/**
155 * The ISO date representation. Represents which component the string includes,
156 * date, time or both.
157 */
158export type ISOStringRepresentation = "complete" | "date" | "time";
159/**
160 * The step function options. Used to build function options.
161 */
162export interface StepOptions {
163 /** The step to use when iterating */
164 step?: number;
165}
166/**
167 * The week function options. Used to build function options.
168 */
169export interface WeekOptions {
170 /** Which day the week starts on. */
171 weekStartsOn?: Day;
172}
173/**
174 * The first week contains date options. Used to build function options.
175 */
176export interface FirstWeekContainsDateOptions {
177 /** See {@link FirstWeekContainsDate} for more details. */
178 firstWeekContainsDate?: FirstWeekContainsDate;
179}
180/**
181 * The localized function options. Used to build function options.
182 *
183 * @typeParam LocaleFields - The locale fields used in the relevant function. Defines the minimum set of locale fields that must be provided.
184 */
185export interface LocalizedOptions<LocaleFields extends keyof Locale> {
186 /** The locale to use in the function. */
187 locale?: Pick<Locale, LocaleFields>;
188}
189/**
190 * The ISO format function options. Used to build function options.
191 */
192export interface ISOFormatOptions {
193 /** The format to use: basic with minimal number of separators or extended
194 * with separators added to enhance human readability */
195 format?: ISOStringFormat;
196 /** The date representation - what component to format: date, time\
197 * or both (complete) */
198 representation?: ISOStringRepresentation;
199}
200/**
201 * The rounding options. Used to build function options.
202 */
203export interface RoundingOptions {
204 /** The rounding method to use */
205 roundingMethod?: RoundingMethod;
206}
207/**
208 * Additional tokens options. Used to build function options.
209 */
210export interface AdditionalTokensOptions {
211 /** If true, allows usage of the week-numbering year tokens `YY` and `YYYY`.
212 * See: https://date-fns.org/docs/Unicode-Tokens */
213 useAdditionalWeekYearTokens?: boolean;
214 /** If true, allows usage of the day of year tokens `D` and `DD`.
215 * See: https://date-fns.org/docs/Unicode-Tokens */
216 useAdditionalDayOfYearTokens?: boolean;
217}
218/**
219 * Nearest minute type. Goes from 1 to 30, where 1 is the nearest minute and 30
220 * is nearest half an hour.
221 */
222export type NearestMinutes =
223 | 1
224 | 2
225 | 3
226 | 4
227 | 5
228 | 6
229 | 7
230 | 8
231 | 9
232 | 10
233 | 11
234 | 12
235 | 13
236 | 14
237 | 15
238 | 16
239 | 17
240 | 18
241 | 19
242 | 20
243 | 21
244 | 22
245 | 23
246 | 24
247 | 25
248 | 26
249 | 27
250 | 28
251 | 29
252 | 30;
253/**
254 * Nearest hour type. Goes from 1 to 12, where 1 is the nearest hour and 12
255 * is nearest half a day.
256 */
257export type NearestHours = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
258/**
259 * The nearest minutes function options. Used to build function options.
260 *
261 * @deprecated Use {@link NearestToUnitOptions} instead.
262 */
263export type NearestMinutesOptions = NearestToUnitOptions<NearestMinutes>;
264/**
265 * The nearest unit function options. Used to build function options.
266 */
267export interface NearestToUnitOptions<Unit extends number> {
268 /** The nearest unit to round to. E.g. for minutes `15` to round to quarter
269 * hours. */
270 nearestTo?: Unit;
271}