1+ /*--------------------------------------------------------------------------
2+
3+ TypeBox
4+
5+ The MIT License (MIT)
6+
7+ Copyright (c) 2017-2025 Haydn Paterson
8+
9+ Permission is hereby granted, free of charge, to any person obtaining a copy
10+ of this software and associated documentation files (the "Software"), to deal
11+ in the Software without restriction, including without limitation the rights
12+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+ copies of the Software, and to permit persons to whom the Software is
14+ furnished to do so, subject to the following conditions:
15+
16+ The above copyright notice and this permission notice shall be included in
17+ all copies or substantial portions of the Software.
18+
19+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+ THE SOFTWARE.
26+
27+ ---------------------------------------------------------------------------*/
28+
29+ import Type from 'typebox'
30+
31+ // ------------------------------------------------------------------
32+ // Factory
33+ // ------------------------------------------------------------------
34+ export const Date = ( ) => Type . Object ( {
35+ [ Symbol . toPrimitive ] : Type . Never ( ) ,
36+ /** Returns a string representation of a date. The format of the string depends on the locale. */
37+ toString : Type . Function ( [ ] , Type . String ( ) ) ,
38+ /** Returns a date as a string value. */
39+ toDateString : Type . Function ( [ ] , Type . String ( ) ) ,
40+ /** Returns a time as a string value. */
41+ toTimeString : Type . Function ( [ ] , Type . String ( ) ) ,
42+ /** Returns a value as a string value appropriate to the host environment's current locale. */
43+ toLocaleString : Type . Function ( [ ] , Type . String ( ) ) ,
44+ /** Returns a date as a string value appropriate to the host environment's current locale. */
45+ toLocaleDateString : Type . Function ( [ ] , Type . String ( ) ) ,
46+ /** Returns a time as a string value appropriate to the host environment's current locale. */
47+ toLocaleTimeString : Type . Function ( [ ] , Type . String ( ) ) ,
48+ /** Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. */
49+ valueOf : Type . Function ( [ ] , Type . Number ( ) ) ,
50+ /** Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. */
51+ getTime : Type . Function ( [ ] , Type . Number ( ) ) ,
52+ /** Gets the year, using local time. */
53+ getFullYear : Type . Function ( [ ] , Type . Number ( ) ) ,
54+ /** Gets the year using Universal Coordinated Time (UTC). */
55+ getUTCFullYear : Type . Function ( [ ] , Type . Number ( ) ) ,
56+ /** Gets the month, using local time. */
57+ getMonth : Type . Function ( [ ] , Type . Number ( ) ) ,
58+ /** Gets the month of a Date object using Universal Coordinated Time (UTC). */
59+ getUTCMonth : Type . Function ( [ ] , Type . Number ( ) ) ,
60+ /** Gets the day-of-the-month, using local time. */
61+ getDate : Type . Function ( [ ] , Type . Number ( ) ) ,
62+ /** Gets the day-of-the-month, using Universal Coordinated Time (UTC). */
63+ getUTCDate : Type . Function ( [ ] , Type . Number ( ) ) ,
64+ /** Gets the day of the week, using local time. */
65+ getDay : Type . Function ( [ ] , Type . Number ( ) ) ,
66+ /** Gets the day of the week using Universal Coordinated Time (UTC). */
67+ getUTCDay : Type . Function ( [ ] , Type . Number ( ) ) ,
68+ /** Gets the hours in a date, using local time. */
69+ getHours : Type . Function ( [ ] , Type . Number ( ) ) ,
70+ /** Gets the hours value in a Date object using Universal Coordinated Time (UTC). */
71+ getUTCHours : Type . Function ( [ ] , Type . Number ( ) ) ,
72+ /** Gets the minutes of a Date object, using local time. */
73+ getMinutes : Type . Function ( [ ] , Type . Number ( ) ) ,
74+ /** Gets the minutes of a Date object using Universal Coordinated Time (UTC). */
75+ getUTCMinutes : Type . Function ( [ ] , Type . Number ( ) ) ,
76+ /** Gets the seconds of a Date object, using local time. */
77+ getSeconds : Type . Function ( [ ] , Type . Number ( ) ) ,
78+ /** Gets the seconds of a Date object using Universal Coordinated Time (UTC). */
79+ getUTCSeconds : Type . Function ( [ ] , Type . Number ( ) ) ,
80+ /** Gets the milliseconds of a Date, using local time. */
81+ getMilliseconds : Type . Function ( [ ] , Type . Number ( ) ) ,
82+ /** Gets the milliseconds of a Date object using Universal Coordinated Time (UTC). */
83+ getUTCMilliseconds : Type . Function ( [ ] , Type . Number ( ) ) ,
84+ /** Gets the difference in minutes between Universal Coordinated Time (UTC) and the time on the local computer. */
85+ getTimezoneOffset : Type . Function ( [ ] , Type . Number ( ) ) ,
86+ /**
87+ * Sets the date and time value in the Date object.
88+ * @param time A numeric value representing the number of elapsed milliseconds since midnight, January 1, 1970 GMT.
89+ */
90+ setTime : Type . Function ( [ Type . Number ( ) ] , Type . Number ( ) ) ,
91+ /**
92+ * Sets the milliseconds value in the Date object using local time.
93+ * @param ms A numeric value equal to the millisecond value.
94+ */
95+ setMilliseconds : Type . Function ( [ Type . Number ( ) ] , Type . Number ( ) ) ,
96+ /**
97+ * Sets the milliseconds value in the Date object using Universal Coordinated Time (UTC).
98+ * @param ms A numeric value equal to the millisecond value.
99+ */
100+ setUTCMilliseconds : Type . Function ( [ Type . Number ( ) ] , Type . Number ( ) ) ,
101+ /**
102+ * Sets the seconds value in the Date object using local time.
103+ * @param sec A numeric value equal to the seconds value.
104+ * @param ms A numeric value equal to the milliseconds value.
105+ */
106+ setSeconds : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
107+ /**
108+ * Sets the seconds value in the Date object using Universal Coordinated Time (UTC).
109+ * @param sec A numeric value equal to the seconds value.
110+ * @param ms A numeric value equal to the milliseconds value.
111+ */
112+ setUTCSeconds : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
113+ /**
114+ * Sets the minutes value in the Date object using local time.
115+ * @param min A numeric value equal to the minutes value.
116+ * @param sec A numeric value equal to the seconds value.
117+ * @param ms A numeric value equal to the milliseconds value.
118+ */
119+ setMinutes : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
120+ /**
121+ * Sets the minutes value in the Date object using Universal Coordinated Time (UTC).
122+ * @param min A numeric value equal to the minutes value.
123+ * @param sec A numeric value equal to the seconds value.
124+ * @param ms A numeric value equal to the milliseconds value.
125+ */
126+ setUTCMinutes : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
127+ /**
128+ * Sets the hour value in the Date object using local time.
129+ * @param hours A numeric value equal to the hours value.
130+ * @param min A numeric value equal to the minutes value.
131+ * @param sec A numeric value equal to the seconds value.
132+ * @param ms A numeric value equal to the milliseconds value.
133+ */
134+ setHours : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) , Type . Optional ( Type . Number ( ) ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
135+ /**
136+ * Sets the hours value in the Date object using Universal Coordinated Time (UTC).
137+ * @param hours A numeric value equal to the hours value.
138+ * @param min A numeric value equal to the minutes value.
139+ * @param sec A numeric value equal to the seconds value.
140+ * @param ms A numeric value equal to the milliseconds value.
141+ */
142+ setUTCHours : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) , Type . Optional ( Type . Number ( ) ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
143+ /**
144+ * Sets the numeric day-of-the-month value of the Date object using local time.
145+ * @param date A numeric value equal to the day of the month.
146+ */
147+ setDate : Type . Function ( [ Type . Number ( ) ] , Type . Number ( ) ) ,
148+ /**
149+ * Sets the numeric day of the month in the Date object using Universal Coordinated Time (UTC).
150+ * @param date A numeric value equal to the day of the month.
151+ */
152+ setUTCDate : Type . Function ( [ Type . Number ( ) ] , Type . Number ( ) ) ,
153+ /**
154+ * Sets the month value in the Date object using local time.
155+ * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively.
156+ * @param date A numeric value representing the day of the month. If this value is not supplied, the value from a call to the getDate method is used.
157+ */
158+ setMonth : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
159+ /**
160+ * Sets the month value in the Date object using Universal Coordinated Time (UTC).
161+ * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively.
162+ * @param date A numeric value representing the day of the month. If it is not supplied, the value from a call to the getUTCDate method is used.
163+ */
164+ setUTCMonth : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
165+ /**
166+ * Sets the year of the Date object using local time.
167+ * @param year A numeric value for the year.
168+ * @param month A zero-based numeric value for the month (0 for January, 11 for December). Must be specified if numDate is specified.
169+ * @param date A numeric value equal for the day of the month.
170+ */
171+ setFullYear : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
172+ /**
173+ * Sets the year value in the Date object using Universal Coordinated Time (UTC).
174+ * @param year A numeric value equal to the year.
175+ * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. Must be supplied if numDate is supplied.
176+ * @param date A numeric value equal to the day of the month.
177+ */
178+ setUTCFullYear : Type . Function ( [ Type . Number ( ) , Type . Optional ( Type . Number ( ) ) , Type . Optional ( Type . Number ( ) ) ] , Type . Number ( ) ) ,
179+ /** Returns a date converted to a string using Universal Coordinated Time (UTC). */
180+ toUTCString : Type . Function ( [ ] , Type . String ( ) ) ,
181+ /** Returns a date as a string value in ISO format. */
182+ toISOString : Type . Function ( [ ] , Type . String ( ) ) ,
183+ /** Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. */
184+ toJSON : Type . Function ( [ Type . Optional ( Type . String ( ) ) ] , Type . String ( ) ) ,
185+ } )
0 commit comments