https://github.com/RoamJS/roamjs-components/blob/main/src/date
Utilities for parsing and manipulating dates and times within the Roam Research application are provided in the https://github.com/RoamJS/roamjs-components/blob/main/src/date
directory. Key functionalities include:
-
Natural Language Date Parsing: The
parseNlpDate
function leverages thechrono-node
library to interpret natural language dates (e.g., "yesterday", "next Monday"). Custom parsing and refinement logic enhance its robustness. ThestartOfWeek
,endOfWeek
,startOfMonth
,endOfMonth
,startOfYear
, andendOfYear
functions fromdate-fns
determine the start and end of various periods. TheORDINAL_WORD_DICTIONARY
andORDINAL_REGEX
assist in parsing ordinal words and numbers. TheassignDay
function assigns year, month, and day components to aParsingComponents
object. -
Roam Date UID Parsing: The
parseRoamDateUid
function converts Roam Research date UIDs (formatted as "month-date-year") into JavaScriptDate
objects. It splits the input string, converts the components to numbers, and constructs aDate
object, adjusting the month value to match JavaScript's zero-indexed months. -
Constants: The
constants.ts
file provides constants likeMONTHS
, an array of month names, and regular expressions (DAILY_NOTE_PAGE_REGEX
andDAILY_NOTE_PAGE_TITLE_REGEX
) for matching and validating daily note page titles in Roam Research.
For detailed discussions on constants and parsing functions, refer to the subsections Constants and Date Parsing.