MCPcopy Create free account
hub / github.com/angular/angular / createDate

Function createDate

packages/common/src/i18n/format_date.ts:181–201  ·  view source on GitHub ↗

* Create a new Date object with the given date value, and the time set to midnight. * * We cannot use `new Date(year, month, date)` because it maps years between 0 and 99 to 1900-1999. * See: https://github.com/angular/angular/issues/40377 * * Note that this function returns a Date object whose

(year: number, month: number, date: number)

Source from the content-addressed store, hash-verified

179 * considerable breaking change.
180 */
181function createDate(year: number, month: number, date: number): Date {
182 // The `newDate` is set to midnight (UTC) on January 1st 1970.
183 // - In PST this will be December 31st 1969 at 4pm.
184 // - In GMT this will be January 1st 1970 at 1am.
185 // Note that they even have different years, dates and months!
186 const newDate = new Date(0);
187
188 // `setFullYear()` allows years like 0001 to be set correctly. This function does not
189 // change the internal time of the date.
190 // Consider calling `setFullYear(2019, 8, 20)` (September 20, 2019).
191 // - In PST this will now be September 20, 2019 at 4pm
192 // - In GMT this will now be September 20, 2019 at 1am
193
194 newDate.setFullYear(year, month, date);
195 // We want the final date to be at local midnight, so we reset the time.
196 // - In PST this will now be September 20, 2019 at 12am
197 // - In GMT this will now be September 20, 2019 at 12am
198 newDate.setHours(0, 0, 0);
199
200 return newDate;
201}
202
203function getNamedFormat(locale: string, format: string): string {
204 const localeId = getLocaleId(locale);

Callers 3

getFirstThursdayOfYearFunction · 0.85
getThursdayThisIsoWeekFunction · 0.85
toDateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected