7.7 KiB
Date Calc
This plugin adds a date-calc fenced code block you can embed in your notes to render date calculations.
Example (birthday):
type: birthday
birthday: 1992-08-16
Supported types and fields:
-
birthday
- birthday (or birthdate or date): YYYY-MM-DD
- If not provided in the block/inline config, the plugin will also look for a
birthday(orbirthdate) property in the note’s frontmatter. - Output: Age in years and time until next birthday (days, or months if > 31 days, with half-month rounding)
-
countdown / until
- to (or date or until): target date/time
- from (optional): starting date/time (defaults to now)
- label (optional): prefix label
- Output: Humanized time until target, or how long ago if past
-
diff
- from (or start): start date/time
- to (or end): end date/time
- Output: Humanized difference between the two dates
-
since
- since (or from or date): date/time of the event
- Output: Humanized time since that date (or time until if it’s in the future)
Notes:
- Dates are interpreted in your local timezone. For birthdays, calculations use local midnight to avoid timezone inconsistencies.
- YAML inside the code block must be valid. The plugin will show an error if the YAML cannot be parsed.
More examples:
- Birthday basics
type: birthday
birthday: 2000-05-21
Aliases for the date field also work:
type: birthday
birthdate: 2000-05-21
- Countdown to a date (future)
type: countdown
label: New Year
to: 2025-12-31 23:59
- Until (alias of countdown)
type: until
to: 2030-01-01
- Countdown from a custom start time
type: countdown
label: Sprint ends
to: 2025-10-15 17:00
from: 2025-10-01 09:00
- Since an event (past)
type: since
since: 2024-12-20
If the date is in the future, the text will say "In: ..." instead of "Since: ... ago".
- Difference between two dates
type: diff
from: 2024-02-29
to: 2025-03-01
- Use times as well as dates
type: diff
from: 2025-09-19 08:00
to: 2025-09-19 16:30
- Friendly birthday messages near the day
type: birthday
birthday: 1992-08-16
- If today is the birthday: "Wish them Happy Birthday!"
- If tomorrow is the birthday: "Their birthday is tomorrow!"
- If the birthday is > 31 days away: months are shown, with a 0.5 month added when roughly half a month remains.
- Error handling examples
Invalid YAML:
this: is: not: valid
Missing required fields:
type: diff
from: 2025-01-01
# missing: to
The plugin will show a helpful error message in these cases.
Inline usage:
- You can also use inline code like:
\date-calc: birthday=1992-08-16`` → renders a birthday summary.\date-calc: to=2025-12-31 label=NewYear`` → renders a countdown.\date-calc: since=2024-12-20`` → time since.\date-calc: from=2025-09-19 to=2025-09-20`` → difference between two dates.
- Inline also accepts YAML/inline-map after the colon, e.g.
\date-calc: {type: birthday, birthday: 1992-08-16}``. - For inline birthday, if no date is given, the note’s frontmatter
birthday/birthdateis used when present.
Tips:
- You can style the rendered line using the CSS class
date-calcin your snippet or theme. - ISO-like date strings (YYYY-MM-DD or YYYY-MM-DD HH:mm) work well and are interpreted in your local timezone.
- For birthdays, calculations are normalized to local midnight to avoid off-by-one day issues due to timezones.
Date Calc
This plugin adds a date-calc fenced code block you can embed in your notes to render date calculations.
Example (birthday):
type: birthday
birthday: 1992-08-16
Supported types and fields:
-
birthday
- birthday (or birthdate or date): YYYY-MM-DD
- If not provided in the block/inline config, the plugin will also look for a
birthday(orbirthdate) property in the note’s frontmatter. - Output: Age in years and time until next birthday (days, or months if > 31 days, with half-month rounding)
-
countdown / until
- to (or date or until): target date/time
- from (optional): starting date/time (defaults to now)
- label (optional): prefix label
- Output: Humanized time until target, or how long ago if past
-
diff
- from (or start): start date/time
- to (or end): end date/time
- Output: Humanized difference between the two dates
-
since
- since (or from or date): date/time of the event
- Output: Humanized time since that date (or time until if it’s in the future)
Notes:
- Dates are interpreted in your local timezone. For birthdays, calculations use local midnight to avoid timezone inconsistencies.
- YAML inside the code block must be valid. The plugin will show an error if the YAML cannot be parsed.
More examples:
- Birthday basics
type: birthday
birthday: 2000-05-21
Aliases for the date field also work:
type: birthday
birthdate: 2000-05-21
- Countdown to a date (future)
type: countdown
label: New Year
to: 2025-12-31 23:59
- Until (alias of countdown)
type: until
to: 2030-01-01
- Countdown from a custom start time
type: countdown
label: Sprint ends
to: 2025-10-15 17:00
from: 2025-10-01 09:00
- Since an event (past)
type: since
since: 2024-12-20
If the date is in the future, the text will say "In: ..." instead of "Since: ... ago".
- Difference between two dates
type: diff
from: 2024-02-29
to: 2025-03-01
- Use times as well as dates
type: diff
from: 2025-09-19 08:00
to: 2025-09-19 16:30
- Friendly birthday messages near the day
type: birthday
birthday: 1992-08-16
- If today is the birthday: "Wish them Happy Birthday!"
- If tomorrow is the birthday: "Their birthday is tomorrow!"
- If the birthday is > 31 days away: months are shown, with a 0.5 month added when roughly half a month remains.
- Error handling examples
Invalid YAML:
this: is: not: valid
Missing required fields:
type: diff
from: 2025-01-01
# missing: to
The plugin will show a helpful error message in these cases.
Inline usage:
- You can also use inline code like:
\date-calc: birthday=1992-08-16`` → renders a birthday summary.\date-calc: to=2025-12-31 label=NewYear`` → renders a countdown.\date-calc: since=2024-12-20`` → time since.\date-calc: from=2025-09-19 to=2025-09-20`` → difference between two dates.
- Inline also accepts YAML/inline-map after the colon, e.g.
\date-calc: {type: birthday, birthday: 1992-08-16}``. - For inline birthday, if no date is given, the note’s frontmatter
birthday/birthdateis used when present.
Troubleshooting inline rendering:
- Inline replacements only run in Reading view and in Live Preview (rendered sections). In Source mode, you’ll just see the literal inline code.
- Type it exactly with a single pair of backticks, e.g.
\date-calc:birthday`or`date-calc: birthday=1992-08-16`` (no triple backticks). - If it still shows as literal code, try: toggle the note to Reading view and back, or reload the app, or disable/enable the plugin. The plugin’s inline processor now runs late to avoid conflicts with other processors.
- Inline code inside fenced code blocks is intentionally ignored by the plugin so you can document examples in notes and the README.
Tips:
- You can style the rendered line using the CSS class
date-calcin your snippet or theme. - ISO-like date strings (YYYY-MM-DD or YYYY-MM-DD HH:mm) work well and are interpreted in your local timezone.
- For birthdays, calculations are normalized to local midnight to avoid off-by-one day issues due to timezones.