You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add useCurrentYearIfMissing option to support dates without year (#14)
* feat: add useCurrentYearIfMissing option to support dates without year
* refactor: convert addYearToDateText to arrow function and improve readability
* chore: add sinon for mocking current date to test `useCurrentYearIfMissing` option
* add: currentYear option and remove sinon dependency
* refactor: avoid using `let`
Copy file name to clipboardExpand all lines: README.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,6 +87,46 @@ But, You can specify `2016-12-30` is `ja-JP` text by options
87
87
}
88
88
```
89
89
90
+
-`useCurrentYearIfMissing`: boolean
91
+
- Default: false
92
+
- If true, when the year is missing in the date string (e.g. `4月23日(月)`), the current year will be automatically added for validation.
93
+
- This is useful for documents that often omit the year in dates.
94
+
95
+
Example:
96
+
97
+
```json
98
+
{
99
+
"rules": {
100
+
"date-weekday-mismatch": {
101
+
"useCurrentYearIfMissing": true
102
+
}
103
+
}
104
+
}
105
+
```
106
+
107
+
If the text contains `4月23日(水)`, and the current year is 2025, it will be interpreted as `2025年4月23日(水)` for the weekday check.
108
+
109
+
-`currentYear`: number
110
+
- Default: the current year (from system date)
111
+
- If specified, this value will be used as the year when supplementing missing years in date strings (used only when `useCurrentYearIfMissing` is true).
112
+
- This is useful for testing or for documents that should always use a specific year for validation.
113
+
114
+
Example (using both options):
115
+
116
+
```json
117
+
{
118
+
"rules": {
119
+
"date-weekday-mismatch": {
120
+
"useCurrentYearIfMissing": true,
121
+
"currentYear": 2025
122
+
}
123
+
}
124
+
}
125
+
```
126
+
127
+
If the text contains `4月23日(水)`, it will always be interpreted as `2025年4月23日(水)` for the weekday check, regardless of the actual system year.
0 commit comments