Skip to content

Commit beaa804

Browse files
committed
improve date parsing
1 parent 6224315 commit beaa804

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/utils/load_date.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export function parseDateString(dateString: string) {
9393
}
9494

9595
// Remove "st" , "nd" , "rd", "th", etc.
96-
const filtered = dateString.replace(/\b(\d+)(st|nd|rd|th)\b/g, "$1");
96+
const filtered = dateString
97+
.replace(/\b(\d+)(st|nd|rd|th)\b/g, "$1")
98+
.replace(/\s+at\s+/i, " ");
9799
const date = new Date(filtered);
98100
if (isNaN(date.getTime())) {
99101
const translated = tryTranslate(dateString);

tests/rmidi_date_detection_test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as fs from "fs/promises";
2+
import * as path from "node:path";
3+
import { BasicMIDI, SpessaSynthLogging } from "../src";
4+
5+
// Process arguments
6+
const args = process.argv.slice(2);
7+
if (args.length !== 1) {
8+
console.info("Usage: tsx index.ts <directory path>");
9+
process.exit();
10+
}
11+
const midPath = args[0];
12+
13+
SpessaSynthLogging(false, false, false);
14+
15+
const entries = await fs.readdir(midPath, { recursive: true });
16+
17+
const dec = new TextDecoder();
18+
for (const entry of entries) {
19+
const fullPath = path.join(midPath, entry);
20+
const stat = await fs.stat(fullPath);
21+
22+
if (stat.isFile()) {
23+
const bin = await fs.readFile(fullPath);
24+
if (dec.decode(bin.buffer.slice(8, 12)) !== "RMID") continue;
25+
const rmid = BasicMIDI.fromArrayBuffer(bin.buffer);
26+
if (!rmid.rmidiInfo.creationDate) continue;
27+
console.info(
28+
dec.decode(rmid.rmidiInfo.creationDate),
29+
" decoded as date -> ",
30+
rmid.getRMIDInfo("creationDate")!.toISOString()
31+
);
32+
}
33+
}

0 commit comments

Comments
 (0)