diff --git a/main.ts b/main.ts index 3bac087..e050800 100644 --- a/main.ts +++ b/main.ts @@ -118,7 +118,8 @@ function formatSpan(from: M, to: M, verbose: boolean): { text: string; isNegativ const years = b.diff(a, "years"); a.add(years, "years"); const months = b.diff(a, "months"); a.add(months, "months"); const days = b.diff(a, "days"); a.add(days, "days"); - const hours = b.diff(a, "hours"); + const hours = b.diff(a, "hours"); a.add(hours, "hours"); + const minutes = b.diff(a, "minutes"); if (verbose) { const parts: string[] = []; @@ -126,14 +127,16 @@ function formatSpan(from: M, to: M, verbose: boolean): { text: string; isNegativ if (months) parts.push(`${months} month${months === 1 ? "" : "s"}`); if (days) parts.push(`${days} day${days === 1 ? "" : "s"}`); if (hours && parts.length < 3) parts.push(`${hours} hour${hours === 1 ? "" : "s"}`); - return { text: parts.join(", ") || "0 days", isNegative }; + if (minutes && parts.length < 3) parts.push(`${minutes} minute${minutes === 1 ? "" : "s"}`); + return { text: parts.join(", ") || "0 minutes", isNegative }; } else { const parts: string[] = []; if (years) parts.push(`${years}y`); if (months) parts.push(`${months}mo`); if (days) parts.push(`${days}d`); if (hours && parts.length < 3) parts.push(`${hours}h`); - return { text: parts.join(" ") || "0d", isNegative }; + if (minutes && parts.length < 3) parts.push(`${minutes}m`); + return { text: parts.join(" ") || "0m", isNegative }; } } @@ -668,6 +671,14 @@ class DateCalcSettingTab extends PluginSettingTab { containerEl.createEl("h2", { text: "Date Calc" }); + // Add documentation link + const docsDiv = containerEl.createDiv({ cls: "setting-item-description" }); + docsDiv.createEl("a", { + text: "📖 View Full Documentation", + href: "https://github.com/thelegend09/date-calculator", + }); + docsDiv.style.marginBottom = "1em"; + new Setting(containerEl) .setName("Debug logging") .setDesc("Logs decoration activity to the console.") @@ -690,7 +701,7 @@ class DateCalcSettingTab extends PluginSettingTab { new Setting(containerEl) .setName("Verbose output") - .setDesc("When enabled, show longer/wordier messages.") + .setDesc("When enabled, show longer/wordier messages. Can be overridden per-calculation with verbose=true/false.") .addToggle((t) => t.setValue(this.plugin.settings.verbose).onChange(async (v) => { this.plugin.settings.verbose = v; @@ -698,8 +709,69 @@ class DateCalcSettingTab extends PluginSettingTab { }) ); + // Usage examples section containerEl.createEl("h3", { text: "Usage Examples" }); - containerEl.createEl("p", { text: "Inline: `date-calc: birthday=1992-08-16`" }); - containerEl.createEl("p", { text: "Block: ```date-calc with YAML inside" }); + + const examplesDiv = containerEl.createDiv({ cls: "date-calc-examples" }); + examplesDiv.style.fontSize = "0.9em"; + examplesDiv.style.lineHeight = "1.6"; + + // 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)" }); + + const blockExample1 = examplesDiv.createEl("pre"); + blockExample1.style.background = "var(--background-secondary)"; + blockExample1.style.padding = "8px"; + blockExample1.style.borderRadius = "4px"; + blockExample1.style.marginBottom = "8px"; + blockExample1.setText( + "```date-calc\n" + + "type: birthday\n" + + "birthday: 1992-08-16\n" + + "```" + ); + + const blockExample2 = examplesDiv.createEl("pre"); + blockExample2.style.background = "var(--background-secondary)"; + blockExample2.style.padding = "8px"; + blockExample2.style.borderRadius = "4px"; + blockExample2.style.marginBottom = "8px"; + blockExample2.setText( + "```date-calc\n" + + "type: countdown\n" + + "to: 2026-12-31 23:59\n" + + "label: New Year\n" + + "verbose: true\n" + + "```" + ); + + const blockExample3 = examplesDiv.createEl("pre"); + blockExample3.style.background = "var(--background-secondary)"; + blockExample3.style.padding = "8px"; + blockExample3.style.borderRadius = "4px"; + blockExample3.setText( + "```date-calc\n" + + "type: diff\n" + + "from: 2024-01-01\n" + + "to: 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"); } }