Skip to content

Commit 8ce8d14

Browse files
authored
feat(datetime): add month and day of week constants (#6910)
1 parent 232ad45 commit 8ce8d14

File tree

1 file changed

+209
-0
lines changed

1 file changed

+209
-0
lines changed

datetime/constants.ts

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,212 @@ export const DAY: number = HOUR * 24;
5656
* ```
5757
*/
5858
export const WEEK: number = DAY * 7;
59+
/**
60+
* The month index for January.
61+
*
62+
* @example
63+
* ```ts
64+
* import { JAN } from "@std/datetime/constants";
65+
*
66+
* new Date(2025, JAN, 1); // 2025-01-01
67+
* ```
68+
*/
69+
export const JAN = 0;
70+
/**
71+
* The month index for February.
72+
*
73+
* @example
74+
* ```ts
75+
* import { FEB } from "@std/datetime/constants";
76+
*
77+
* new Date(2025, FEB, 1); // 2025-02-01
78+
* ```
79+
*/
80+
export const FEB = 1;
81+
/**
82+
* The month index for March.
83+
*
84+
* @example
85+
* ```ts
86+
* import { MAR } from "@std/datetime/constants";
87+
*
88+
* new Date(2025, MAR, 1); // 2025-03-01
89+
* ```
90+
*/
91+
export const MAR = 2;
92+
/**
93+
* The month index for April.
94+
*
95+
* @example
96+
* ```ts
97+
* import { APR } from "@std/datetime/constants";
98+
*
99+
* new Date(2025, APR, 1); // 2025-04-01
100+
* ```
101+
*/
102+
export const APR = 3;
103+
/**
104+
* The month index for May.
105+
*
106+
* @example
107+
* ```ts
108+
* import { MAY } from "@std/datetime/constants";
109+
*
110+
* new Date(2025, MAY, 1); // 2025-05-01
111+
* ```
112+
*/
113+
export const MAY = 4;
114+
/**
115+
* The month index for June.
116+
*
117+
* @example
118+
* ```ts
119+
* import { JUN } from "@std/datetime/constants";
120+
*
121+
* new Date(2025, JUN, 1); // 2025-06-01
122+
* ```
123+
*/
124+
export const JUN = 5;
125+
/**
126+
* The month index for July.
127+
*
128+
* @example
129+
* ```ts
130+
* import { JUL } from "@std/datetime/constants";
131+
*
132+
* new Date(2025, JUL, 1); // 2025-07-01
133+
* ```
134+
*/
135+
export const JUL = 6;
136+
/**
137+
* The month index for August.
138+
*
139+
* @example
140+
* ```ts
141+
* import { AUG } from "@std/datetime/constants";
142+
*
143+
* new Date(2025, AUG, 1); // 2025-08-01
144+
* ```
145+
*/
146+
export const AUG = 7;
147+
/**
148+
* The month index for September.
149+
*
150+
* @example
151+
* ```ts
152+
* import { SEP } from "@std/datetime/constants";
153+
*
154+
* new Date(2025, SEP, 1); // 2025-09-01
155+
* ```
156+
*/
157+
export const SEP = 8;
158+
/**
159+
* The month index for October.
160+
*
161+
* @example
162+
* ```ts
163+
* import { OCT } from "@std/datetime/constants";
164+
*
165+
* new Date(2025, OCT, 1); // 2025-10-01
166+
* ```
167+
*/
168+
export const OCT = 9;
169+
/**
170+
* The month index for November.
171+
*
172+
* @example
173+
* ```ts
174+
* import { NOV } from "@std/datetime/constants";
175+
*
176+
* new Date(2025, NOV, 1); // 2025-11-01
177+
* ```
178+
*/
179+
export const NOV = 10;
180+
/**
181+
* The month index for December.
182+
*
183+
* @example
184+
* ```ts
185+
* import { DEC } from "@std/datetime/constants";
186+
*
187+
* new Date(2025, DEC, 1); // 2025-12-01
188+
* ```
189+
*/
190+
export const DEC = 11;
191+
/**
192+
* The day of week index for Sunday.
193+
*
194+
* @example
195+
* ```ts
196+
* import { JAN, SUN } from "@std/datetime/constants";
197+
*
198+
* new Date(2025, JAN, 5).getDay() === SUN; // true
199+
* ```
200+
*/
201+
export const SUN = 0;
202+
/**
203+
* The day of week index for Monday.
204+
*
205+
* @example
206+
* ```ts
207+
* import { JAN, MON } from "@std/datetime/constants";
208+
*
209+
* new Date(2025, JAN, 6).getDay() === MON; // true
210+
* ```
211+
*/
212+
export const MON = 1;
213+
/**
214+
* The day of week index for Tuesday.
215+
*
216+
* @example
217+
* ```ts
218+
* import { JAN, TUE } from "@std/datetime/constants";
219+
*
220+
* new Date(2025, JAN, 7).getDay() === TUE; // true
221+
* ```
222+
*/
223+
export const TUE = 2;
224+
/**
225+
* The day of week index for Wednesday.
226+
*
227+
* @example
228+
* ```ts
229+
* import { JAN, WED } from "@std/datetime/constants";
230+
*
231+
* new Date(2025, JAN, 1).getDay() === WED; // true
232+
* ```
233+
*/
234+
export const WED = 3;
235+
/**
236+
* The day of week index for Thursday.
237+
*
238+
* @example
239+
* ```ts
240+
* import { JAN, THU } from "@std/datetime/constants";
241+
*
242+
* new Date(2025, JAN, 2).getDay() === THU; // true
243+
* ```
244+
*/
245+
export const THU = 4;
246+
/**
247+
* The day of week index for Friday.
248+
*
249+
* @example
250+
* ```ts
251+
* import { JAN, FRI } from "@std/datetime/constants";
252+
*
253+
* new Date(2025, JAN, 3).getDay() === FRI; // true
254+
* ```
255+
*/
256+
export const FRI = 5;
257+
/**
258+
* The day of week index for Saturday.
259+
*
260+
* @example
261+
* ```ts
262+
* import { JAN, SAT } from "@std/datetime/constants";
263+
*
264+
* new Date(2025, JAN, 4).getDay() === SAT; // true
265+
* ```
266+
*/
267+
export const SAT = 6;

0 commit comments

Comments
 (0)