-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move factory fromString to parsePlainDate util
- Loading branch information
Showing
7 changed files
with
29 additions
and
38 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 |
---|---|---|
|
@@ -229,5 +229,3 @@ export function ExPlainDate( | |
|
||
return exPlainDate; | ||
} | ||
|
||
ExPlainDate.fromString = PlainDate.fromString; |
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
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
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
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
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,13 @@ | ||
import { ComPlainDate, PlainDate } from "../PlainDate.ts"; | ||
import { dateParts } from "../support/dateParts.ts"; | ||
|
||
/** | ||
* Create a new plain-date object from an ISO date string. | ||
*/ | ||
export function parsePlainDate(isoDateString: string): ComPlainDate { | ||
const parts = dateParts(isoDateString); | ||
if (!parts) { | ||
throw TypeError(`No date parts found in string: ${isoDateString}`); | ||
} | ||
return PlainDate(parts); | ||
} |
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,10 @@ | ||
import { parsePlainDate } from "./parsePlainDate.ts"; | ||
import { assertEquals, assertThrows } from "../dev_deps.ts"; | ||
|
||
Deno.test("can create plain-date from ISO string", () => { | ||
assertEquals(String(parsePlainDate("2022-02-02")), "2022-02-02"); | ||
}); | ||
|
||
Deno.test("throws error when string only contains year part", () => { | ||
assertThrows(() => parsePlainDate("2022")); | ||
}); |