Almanac
Plain-English dates that know every market holiday.
Plain-English dates that know every market holiday.
Almanac is a small TypeScript library that turns a person's date phrase into an actual date. It treats "business day" as a day the market is open, not just any weekday. Type "3 business days after Thanksgiving" and it counts forward through the NYSE calendar, skipping the weekend and any holiday it lands on, then hands back the real date.
Most natural-language date libraries parse the words but treat a business day as "not Saturday or Sunday." That breaks the moment a market holiday appears: the NYSE is closed on Good Friday, on Juneteenth, and on the day it observes a holiday that fell on a weekend. Almanac resolves every phrase through a calendar, so holiday awareness is the default, not an add-on you wire up later.
next trading day: the next day the market is openthe trading day before Christmas: holiday-relative, either direction3 business days after Thanksgiving: business-day math off a holidayin 2 weeks or in 10 days: plain calendar offsetsnext Friday or last Monday: weekday references
Import parse and the built-in nyseCalendar, then call
parse(phrase, calendar). It returns { ok: true, date } when it
understands the phrase, or { ok: false, reason } when it does not. It never
throws, so a form or a batch job can treat "didn't understand that" as data. Need a
different market or a company holiday list? Build a ListCalendar from your
own dates and pass it in; every phrase resolves against it with no NYSE-specific code
path.
ListCalendar
from any exchange or internal holiday list and the parser uses it directly.
ok: false with a reason, never a wrong guess.
ok: false. An oversized business-day count is
rejected before any calendar walk, so the page never hangs.