Skip to content

Commit

Permalink
Add support for parsing strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Oct 4, 2023
1 parent 0fba660 commit e6d052c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ This change log follows the format documented in [Keep a CHANGELOG].
[semantic versioning]: http://semver.org/
[keep a changelog]: http://keepachangelog.com/

## v1.1.0 - 2023-04-10

### Added

- Added support for string parsing.

## v1.0.0 - 2022-07-10

Initial version
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": "1.0.0",
"version": "1.1.0",
"description": "UTC date utils",
"scripts": {
"test": "env TZ=Asia/Kolkata vitest",
Expand Down
6 changes: 5 additions & 1 deletion src/date/mini.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ export class UTCDateMini extends Date {

if (arguments.length)
this.setTime(
arguments.length === 1 ? arguments[0] : Date.UTC(...arguments)
arguments.length === 1
? typeof arguments[0] === "string"
? +new Date(arguments[0])
: arguments[0]
: Date.UTC(...arguments)
);
}

Expand Down
11 changes: 10 additions & 1 deletion src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ describe("UTCDate", () => {
});

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

it("allows to parse the string", () => {
expect(+new UTCDate("2023-05-03")).toBe(+new Date("2023-05-03"));
});

it("allows to create date from another date", () => {
const date = new Date();
expect(+new UTCDate(date)).toBe(+date);
});
});

Expand Down

0 comments on commit e6d052c

Please sign in to comment.