Skip to content

Commit

Permalink
Hello, cruel world!
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jun 11, 2022
0 parents commit 8ff27fd
Show file tree
Hide file tree
Showing 8 changed files with 1,320 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# date-fns UTC utils

🚧 Work in progress
43 changes: 43 additions & 0 deletions index.ts
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);
};
}
}
}
Loading

0 comments on commit 8ff27fd

Please sign in to comment.