From 537198c4f1d8e9351892b4bce0438598592d13a1 Mon Sep 17 00:00:00 2001 From: Olivier Date: Mon, 7 Sep 2026 12:09:55 -0400 Subject: [PATCH] Add remaining type aliases, rewrite settings tab as syntax TL;DR - Add age (birthday), remaining (countdown), elapsed (since) aliases, alongside the existing bday/until/difference. - README: document new aliases in each type's header and the Type Aliases section. - Settings tab rewritten: drop the stale GitHub doc link and hardcoded pre-redesign examples (countdown+from, auto-colon labels). Replace with a compact syntax TL;DR \u2014 all four types with their aliases, fields, and one-line descriptions, plus relative dates, frontmatter fallback, and inline/fenced examples \u2014 and link to the README on Gitea (was pointing at a stale GitHub URL). Verified: aliases tested against the real shipped config parser; the settings tab's actual display() (found via app.setting.pluginTabs) was invoked live in Obsidian and rendered exactly the intended content with no errors. --- README.md | 13 +++--- src/config.ts | 5 ++- src/settings-tab.ts | 97 ++++++++++++++++++++++++++++----------------- 3 files changed, 70 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 0327c08..20fcd23 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Use inline code for quick calculations: `date-calc: birthday=1992-08-16` ## Supported Calculation Types -### Birthday (`birthday`) +### Birthday (`birthday`, `bday`, `age`) Calculates age and time until next birthday. @@ -45,7 +45,7 @@ birthday: 2000-05-21 label: "John's age:" ``` -### Countdown (`countdown` or `until`) +### Countdown (`countdown`, `until`, `remaining`) Time remaining until a target date, **always measured from now**. For a comparison between two fixed dates, use `diff` instead. @@ -64,7 +64,7 @@ label: "New Year:" to: 2025-12-31 23:59 ``` -### Since (`since`) +### Since (`since`, `elapsed`) Time elapsed since an event (or time until, if the event is in the future) — always measured against now. @@ -81,7 +81,7 @@ type: since since: 2024-12-20 ``` -### Difference (`diff`) +### Difference (`diff`, `difference`) The time difference between two fixed dates — neither has to be "now". For a countdown relative to the present moment, use `countdown` instead. @@ -187,8 +187,9 @@ Settings → "Hide result while cursor inside" prevents rendered output from sho For convenience, use these shortcuts: -- `birthday` = `bday` -- `countdown` = `until` +- `birthday` = `bday` = `age` +- `countdown` = `until` = `remaining` +- `since` = `elapsed` - `diff` = `difference` ## Custom Styling diff --git a/src/config.ts b/src/config.ts index 516f746..7e48d99 100644 --- a/src/config.ts +++ b/src/config.ts @@ -87,9 +87,10 @@ export function normalizeConfig( else if (resolved.since || resolved.from) type = "since"; } - if (type === "bday") type = "birthday"; - if (type === "until") type = "countdown"; + if (type === "bday" || type === "age") type = "birthday"; + if (type === "until" || type === "remaining") type = "countdown"; if (type === "difference") type = "diff"; + if (type === "elapsed") type = "since"; return { type, cfg: resolved }; } diff --git a/src/settings-tab.ts b/src/settings-tab.ts index 4bfa0da..5857f65 100644 --- a/src/settings-tab.ts +++ b/src/settings-tab.ts @@ -1,6 +1,8 @@ import { App, PluginSettingTab, Setting } from "obsidian"; import type DateCalcPlugin from "../main"; +const README_URL = "https://gitea.mithrilforge.dev/olivier/date-calculator"; + export class DateCalcSettingTab extends PluginSettingTab { constructor(app: App, private plugin: DateCalcPlugin) { super(app, plugin); @@ -12,14 +14,10 @@ export class DateCalcSettingTab extends PluginSettingTab { containerEl.createEl("h2", { text: "Date Calc" }); - // Documentation link const docsDiv = containerEl.createDiv({ cls: "setting-item-description date-calc-settings-docs", }); - docsDiv.createEl("a", { - text: "📖 View Full Documentation", - href: "https://github.com/thelegend09/date-calculator", - }); + docsDiv.createEl("a", { text: "📖 Full syntax reference (README)", href: README_URL }); new Setting(containerEl) .setName("Debug logging") @@ -53,43 +51,68 @@ export class DateCalcSettingTab extends PluginSettingTab { }) ); - // Usage examples section - containerEl.createEl("h3", { text: "Usage Examples" }); + containerEl.createEl("h3", { text: "Syntax at a glance" }); + const tldr = containerEl.createDiv({ cls: "date-calc-examples" }); - const examplesDiv = containerEl.createDiv({ cls: "date-calc-examples" }); + tldr.createEl("p", { + text: "Use `date-calc: ...` inline, or a fenced ```date-calc block with type: set explicitly (or inferred from which fields you give).", + }); - // Inline examples - examplesDiv.createEl("h4", { text: "Inline Code (single backticks)" }); - const inlineList = examplesDiv.createEl("ul"); - inlineList.createEl("li").setText("`date-calc: birthday=2003-02-15`"); - inlineList.createEl("li").setText("`date-calc: countdown to=2026-12-31 label=\"New Year\"`"); - inlineList.createEl("li").setText("`date-calc: since=2024-01-01`"); - inlineList.createEl("li").setText("`date-calc: diff from=2024-01-01 to=2024-12-31`"); - inlineList.createEl("li").setText("`date-calc: birthday=1992-08-16 verbose=true`"); + // Types table + const typesList = tldr.createEl("ul"); + const addType = (name: string, aliases: string, desc: string, fields: string) => { + const li = typesList.createEl("li"); + li.createEl("strong", { text: name }); + li.appendText(` (${aliases}) — ${desc} `); + li.createEl("br"); + li.createEl("code", { text: fields }); + }; + addType( + "birthday", "bday, age", + "age + days until next birthday.", + "birthday/birthdate/date, label" + ); + addType( + "countdown", "until, remaining", + "time until a date, always from now.", + "to/until/date, label" + ); + addType( + "since", "elapsed", + "time since a date, always from now.", + "since/from/date" + ); + addType( + "diff", "difference", + "time between two fixed dates (neither has to be now).", + "from/start, to/end" + ); - // Block examples - examplesDiv.createEl("h4", { text: "Fenced Blocks (triple backticks)" }); + tldr.createEl("h4", { text: "Relative dates" }); + tldr.createEl("p", { + text: "today, now, tomorrow, yesterday, or an offset like +7d / -3mo / +2w (always relative to now).", + }); - examplesDiv + tldr.createEl("h4", { text: "Frontmatter fallback" }); + tldr.createEl("p", { + text: "Every type reads its date(s) from frontmatter if not given inline: birthday/birthdate, to/deadline, since/created, from/start + to/end.", + }); + + tldr.createEl("h4", { text: "Examples" }); + const examplesList = tldr.createEl("ul"); + examplesList.createEl("li").createEl("code", { text: "date-calc: birthday=1992-08-16" }); + examplesList.createEl("li").createEl("code", { text: "date-calc: to=2026-12-31 label=\"New Year:\"" }); + examplesList.createEl("li").createEl("code", { text: "date-calc: since=2024-01-01" }); + examplesList.createEl("li").createEl("code", { text: "date-calc: from=2024-01-01 to=today" }); + + examplesList + .createEl("li") .createEl("pre", { cls: "date-calc-example-block" }) - .setText("```date-calc\ntype: birthday\nbirthday: 1992-08-16\n```"); + .setText("```date-calc\ntype: countdown\nto: +30d\nlabel: \"Sprint:\"\nverbose: true\n```"); - examplesDiv - .createEl("pre", { cls: "date-calc-example-block" }) - .setText( - "```date-calc\ntype: countdown\nto: 2026-12-31 23:59\nlabel: New Year\nverbose: true\n```" - ); - - examplesDiv - .createEl("pre", { cls: "date-calc-example-block" }) - .setText("```date-calc\ntype: diff\nfrom: 2024-01-01\nto: 2024-12-31\n```"); - - // Tips section - examplesDiv.createEl("h4", { text: "Tips" }); - const tipsList = examplesDiv.createEl("ul"); - tipsList.createEl("li").setText("Use YYYY-MM-DD format for dates"); - tipsList.createEl("li").setText("Add time with YYYY-MM-DD HH:mm for precise countdowns"); - tipsList.createEl("li").setText("Supported types: birthday, countdown, since, diff"); - tipsList.createEl("li").setText("Add verbose=true/false to override global setting"); + const fullDocs = tldr.createEl("p"); + fullDocs.appendText("Full field reference, custom styling, and more examples: "); + fullDocs.createEl("a", { text: "README on Gitea", href: README_URL }); + fullDocs.appendText("."); } }