Skip to content

Weekday Parsing

Tempo provides a flexible way to parse Weekday inputs, allowing you to specify dates relative to the current day or a specific base date. This is particularly useful for phrases like "next Monday" or "3 Wednesdays ago".

Supported Formats

Weekday inputs typically consist of a modifier (optional), a count (optional), and the Weekday name.

1. Simple Weekday Names

You can provide the short or full name of a Weekday.

  • Mon, Monday
  • Wed, Wednesday
  • Sun, Sunday

When no modifier is provided, Tempo defaults to the Weekday in the current week.

2. Symbolic Modifiers

Symbols can be used to indicate relative weeks or specific directions in time.

ModifierMeaningExampleResults in...
+Next week+MonMonday of next week
-Previous week-TueTuesday of last week
<=Prior to<=WedThe Wednesday immediately preceding (or equal to) today
<Prior to (strict)<ThuThe Thursday strictly before today
>=Subsequent to>=FriThe Friday immediately following (or equal to) today
>Subsequent to (strict)>SatThe Saturday strictly after today

3. Keyword Modifiers

Keywords can be used for more natural language-like inputs.

KeywordMeaningExample
thisCurrent weekthis Wed
nextNext weeknext Monday
prevPrevious weekprev Fri
lastLast weeklast Sunday

4. Count Modifiers

You can specify a number of weeks to jump by adding a count after the modifier.

  • -3 Wed: Three Wednesdays ago
  • +2 Mon: Two Mondays from now

5. Relative Suffixes

You can also specify the direction of time using a suffix.

  • 3 Wed ago: Three Wednesdays ago
  • 2 Mon hence: Two Mondays hence
  • 2 Mon from now: Two Mondays from now

Time Suffixes

You can append time information to a Weekday string. Tempo will parse the Weekday first and then apply the time to that specific date.

  • Mon 10:00am
  • Friday noon
  • Wed 15:30:00

How it Works

  1. Normalization: Weekday names are normalized to their 3-letter proper-case prefix (e.g., monday -> Mon).
  2. Anchor: If no time-zone or base date is provided, Tempo uses "now" as the anchor.
  3. Calculation: The modifier and count determine the number of weeks to add or subtract from the anchor date to find the target Weekday.
  4. Constraint: If time components are provided, they are set on the calculated date. Otherwise, the time defaults to 00:00:00 if it's the first parsing pass.

Released under the MIT License.