-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8ff27fd
Showing
8 changed files
with
1,320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# date-fns UTC utils | ||
|
||
🚧 Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const getMethods: Array<keyof Date> = [ | ||
"getDate", | ||
"getDay", | ||
"getFullYear", | ||
"getHours", | ||
"getMilliseconds", | ||
"getMinutes", | ||
"getMonth", | ||
"getSeconds", | ||
]; | ||
|
||
export class UTCDate extends Date { | ||
constructor(); | ||
|
||
constructor(value: Date | number | string); | ||
|
||
constructor( | ||
year: number, | ||
month: number, | ||
date?: number, | ||
hours?: number, | ||
minutes?: number, | ||
seconds?: number, | ||
ms?: number | ||
); | ||
|
||
constructor() { | ||
super(); | ||
// @ts-ignore - how to type the arguments?! | ||
this.setTime(Date.UTC(...arguments)); | ||
|
||
for (const method of getMethods) { | ||
// @ts-ignore - how to type overload? | ||
this[method] = (...args) => { | ||
const utcMethod = method | ||
.toString() | ||
.replace("get", "getUTC") as keyof Date; | ||
// @ts-ignore - how to call the UTC method? | ||
return this[utcMethod](...args); | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.