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.
This commit is contained in:
@@ -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
|
||||
|
||||
+3
-2
@@ -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 };
|
||||
}
|
||||
|
||||
+61
-38
@@ -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`");
|
||||
|
||||
// Block examples
|
||||
examplesDiv.createEl("h4", { text: "Fenced Blocks (triple backticks)" });
|
||||
|
||||
examplesDiv
|
||||
.createEl("pre", { cls: "date-calc-example-block" })
|
||||
.setText("```date-calc\ntype: birthday\nbirthday: 1992-08-16\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```"
|
||||
// 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"
|
||||
);
|
||||
|
||||
examplesDiv
|
||||
.createEl("pre", { cls: "date-calc-example-block" })
|
||||
.setText("```date-calc\ntype: diff\nfrom: 2024-01-01\nto: 2024-12-31\n```");
|
||||
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).",
|
||||
});
|
||||
|
||||
// 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");
|
||||
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: countdown\nto: +30d\nlabel: \"Sprint:\"\nverbose: true\n```");
|
||||
|
||||
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(".");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user