Skip to content

Commit

Permalink
[FIX] date: properly type reference dates
Browse files Browse the repository at this point in the history
Remove `any`

Task: 3666703
X-original-commit: 668e65b
Part-of: #3397
  • Loading branch information
LucasLefevre committed Jan 10, 2024
1 parent 06cc0c1 commit c5a0c15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/helpers/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ type ReadonlyDate = Readonly<
// Parsing
// -----------------------------------------------------------------------------

export const INITIAL_1900_DAY = new Date(1899, 11, 30) as any;
export const INITIAL_1900_DAY = new Date(1899, 11, 30);
export const MS_PER_DAY = 24 * 60 * 60 * 1000;
const CURRENT_MILLENIAL = 2000; // note: don't forget to update this in 2999
const CURRENT_YEAR = new Date().getFullYear();
const INITIAL_JS_DAY = new Date(0) as any;
const DATE_JS_1900_OFFSET = INITIAL_JS_DAY - INITIAL_1900_DAY;
const INITIAL_JS_DAY = new Date(0);
const DATE_JS_1900_OFFSET = INITIAL_JS_DAY.getTime() - INITIAL_1900_DAY.getTime();

export const mdyDateRegexp = /^\d{1,2}(\/|-|\s)\d{1,2}((\/|-|\s)\d{1,4})?$/;
export const ymdDateRegexp = /^\d{3,4}(\/|-|\s)\d{1,2}(\/|-|\s)\d{1,2}$/;
Expand Down Expand Up @@ -134,7 +134,7 @@ function parseDate(str: string, dateFormat: Format): InternalDate | null {
// invalid date
return null;
}
const delta = (jsDate as any) - INITIAL_1900_DAY;
const delta = jsDate.getTime() - INITIAL_1900_DAY.getTime();

let format = leadingZero ? `mm${sep}dd` : `m${sep}d`;
if (parts[yearIndex]) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ function formatJSTime(jsDate: Date, format: Format): FormattedValue {
switch (p) {
case "hhhh":
const helapsedHours = Math.floor(
(jsDate.getTime() - INITIAL_1900_DAY) / (60 * 60 * 1000)
(jsDate.getTime() - INITIAL_1900_DAY.getTime()) / (60 * 60 * 1000)
);
return helapsedHours.toString();
case "hh":
Expand Down

0 comments on commit c5a0c15

Please sign in to comment.