Skip to content

Commit

Permalink
Enable different constructor variants
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jun 11, 2022
1 parent d4bff0b commit 4b20faa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export class UTCDate extends Date {

constructor() {
super();
// @ts-ignore - how to type the arguments?!
this.setTime(Date.UTC(...arguments));
if (arguments.length)
this.setTime(
// @ts-ignore - how to type the arguments?!
arguments.length === 1 ? arguments[0] : Date.UTC(...arguments)
);

for (const method of getMethods) {
// @ts-ignore - how to type overload?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@date-fns/utc",
"version": "0.3.0",
"version": "0.4.0",
"description": "UTC date utils",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ describe("UTCDate", () => {
);
});

describe("constructor", () => {
it("allows to create current date", () => {
expect(new UTCDate().getTime() - Date.now()).toBeLessThan(100);
});

it("allows to create date using timestamp", () => {
expect(new UTCDate(540000000000).getTime()).toBe(540000000000);
});
});

describe("getDate", () => {
it("returns UTC date", () => {
expect(new UTCDate(1987, 1, 11, 23).getDate()).toBe(11);
Expand Down

0 comments on commit 4b20faa

Please sign in to comment.