Skip to content

Commit

Permalink
fix: to allow year 0000 (#178)
Browse files Browse the repository at this point in the history
* fix: to allow year 0000

* fix

* Create moody-books-poke.md
  • Loading branch information
ota-meshi committed Nov 10, 2023
1 parent f47ef27 commit 397c6c6
Show file tree
Hide file tree
Showing 8 changed files with 1,902 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-books-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"toml-eslint-parser": patch
---

fix: to allow year 0000
18 changes: 9 additions & 9 deletions src/tokenizer/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,16 +1397,16 @@ function isNonAscii(cp: number): boolean {
* Check whether the given values is valid date
*/
function isValidDate(y: number, m: number, d: number): boolean {
if (y <= 0 || m > 12 || m <= 0 || d <= 0) {
return false;
if (y >= 0 && m <= 12 && m >= 1 && d >= 1) {
const maxDayOfMonth =
m === 2
? y & 3 || (!(y % 25) && y & 15)
? 28
: 29
: 30 + ((m + (m >> 3)) & 1);
return d <= maxDayOfMonth;
}
const maxDayOfMonth =
m === 2
? y & 3 || (!(y % 25) && y & 15)
? 28
: 29
: 30 + ((m + (m >> 3)) & 1);
return d <= maxDayOfMonth;
return false;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/parser/ast/datetime01-input.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[datetime-list]
first-date = 0000-12-31
first-local = 0000-12-31T15:00:00
first-offset = 0001-01-01T00:00:00Z
last-date = 9999-12-30
last-local = 9999-12-31T14:59:59
last-offset = 9999-12-31T23:59:59Z

0 comments on commit 397c6c6

Please sign in to comment.