Skip to content

Commit 1715553

Browse files
committed
MBS-12229: Parse Japanese letter code dates as proper year numbers
See https://reference.discogs.com/wiki/japanese-release-dates#date-format
1 parent c0b9a2c commit 1715553

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

root/static/scripts/common/utility/parseNaturalDate.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ function cleanDateString(
2626
},
2727
);
2828

29+
// See https://reference.discogs.com/wiki/japanese-release-dates#date-format
30+
const japaneseYearCodes = {
31+
/* eslint-disable sort-keys */
32+
N: '1984',
33+
I: '1985',
34+
H: '1986',
35+
O: '1987',
36+
R: '1988',
37+
E: '1989',
38+
C: '1990',
39+
D: '1991',
40+
K: '1992',
41+
L: '1993',
42+
/* eslint-enable sort-keys */
43+
};
44+
cleanedString = cleanedString.replace(
45+
/([NIHORECDKL])-([0-9]{1,2}-[0-9]{1,2})/,
46+
function (match, year, date) {
47+
return japaneseYearCodes[year] + '-' + date;
48+
},
49+
);
50+
2951
return cleanedString;
3052
}
3153

root/static/scripts/tests/utility.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ test('parseDate', function (t) {
305305
});
306306

307307
test('parseNaturalDate', function (t) {
308-
t.plan(10);
308+
t.plan(12);
309309

310310
const parseDateTests = [
311311
// Nothing
@@ -325,6 +325,10 @@ test('parseNaturalDate', function (t) {
325325
{date: '1999-01-02', expected: {year: '1999', month: '01', day: '02'}},
326326
{date: '1999-01-02', expected: {year: '1999', month: '01', day: '02'}},
327327
{date: '1999 01 02', expected: {year: '1999', month: '01', day: '02'}},
328+
329+
// Japanese year codes
330+
{date: 'O-2-25', expected: {year: '1987', month: '2', day: '25'}},
331+
{date: 'D-12-10', expected: {year: '1991', month: '12', day: '10'}},
328332
];
329333

330334
for (const test of parseDateTests) {

0 commit comments

Comments
 (0)