Skip to content

Commit 7df7c65

Browse files
authored
fix: support for Japanese slash date without year (#16)
1 parent 92de447 commit 7df7c65

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/textlint-rule-date-weekday-mismatch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ const detectLang = (tags, preferLang) => {
5858
* @returns {string}
5959
*/
6060
const addYearToDateText = (dateText, year, lang) => {
61-
// Japanese: 4月23日(月) → 2024年4月23日(月)
62-
if (lang === "ja") {
63-
return `${year}${dateText}`;
64-
}
6561
// Slash: 4/23(月) → 2024/4/23(月)
6662
if (/^[0-9]{1,2}\/[0-9]{1,2}/.test(dateText)) {
6763
return `${year}/${dateText}`;
@@ -70,6 +66,10 @@ const addYearToDateText = (dateText, year, lang) => {
7066
if (/^[0-9]{1,2}-[0-9]{1,2}/.test(dateText)) {
7167
return `${year}-${dateText}`;
7268
}
69+
// Japanese: 4月23日(月) → 2024年4月23日(月)
70+
if (lang === "ja") {
71+
return `${year}${dateText}`;
72+
}
7373
// Default: prepend year and a space
7474
return `${year} ${dateText}`;
7575
}

test/textlint-rule-date-weekday-mismatch-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ tester.run("rule", rule, {
3131
options: { useCurrentYearIfMissing: true, currentYear: 2025, lang: "en" },
3232
// 2025-04-23 is Wednesday
3333
},
34+
{
35+
text: "6/20(金)",
36+
options: { useCurrentYearIfMissing: true, currentYear: 2025, lang: "ja" },
37+
// 2025/06/20は金曜日
38+
},
3439
],
3540
invalid: [
3641
// single match
@@ -159,5 +164,17 @@ tester.run("rule", rule, {
159164
}
160165
]
161166
},
167+
{
168+
text: "6/20(木)",
169+
output: "6/20(金)",
170+
options: { useCurrentYearIfMissing: true, currentYear: 2025, lang: "ja" },
171+
errors: [
172+
{
173+
message: "6/20(木) mismatch weekday.\n6/20(木) => 6/20(金)",
174+
line: 1,
175+
column: 6
176+
}
177+
]
178+
},
162179
]
163180
});

0 commit comments

Comments
 (0)