Skip to content

Commit

Permalink
new semicolon syntax for date interpolating
Browse files Browse the repository at this point in the history
  • Loading branch information
dvargas92495 committed Oct 11, 2022
1 parent 46609c4 commit 84853ba
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 269 deletions.
233 changes: 0 additions & 233 deletions src/dateParser.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/dateProcessing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import parseNlpDate from "roamjs-components/date/parseNlpDate";
import * as chrono from "chrono-node";

const parseTextForDates = (str: string, reference_date?: Date) => {
const str_with_pages_removed = str.replace(/\[+\[[^)]+\]+\] */g, "");
const date = chrono.parse(str_with_pages_removed, reference_date);
// support parsing to return parse results
// also solve the `of` bug
// parseNlpDate(str_with_pages_removed, reference_date);

if (date.length) {
return date.reduce((prev, { text, index, start }) => {
const roamDate = `[${text}]([[${window.roamAlphaAPI.util.dateToPageTitle(
start.date()
)}]])`;
return `${prev.slice(0, index)}${roamDate}${prev.slice(
index + text.length
)}`;
}, str);
} else {
return str;
}
};

export default parseTextForDates;
Loading

0 comments on commit 84853ba

Please sign in to comment.