2 Commits

Author SHA1 Message Date
9014f086d6 Bug Fixes 2025-11-22 20:26:48 +01:00
d4f2af179f Bug Fixes 2025-11-22 20:26:18 +01:00
2 changed files with 40 additions and 18 deletions

17
main.js
View File

@@ -924,9 +924,20 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
formatDailyNoteDate(format) { formatDailyNoteDate(format) {
const now = new Date(); const now = new Date();
const year = now.getFullYear(); const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, "0"); const month = now.getMonth() + 1;
const day = now.getDate().toString().padStart(2, "0"); const day = now.getDate();
return format.replace("YYYY", year.toString()).replace("YY", year.toString().slice(-2)).replace("MM", month).replace("M", (now.getMonth() + 1).toString()).replace("DD", day).replace("D", now.getDate().toString()).replace("dddd", now.toLocaleDateString("en-US", { weekday: "long" })).replace("ddd", now.toLocaleDateString("en-US", { weekday: "short" })).replace("MMMM", now.toLocaleDateString("en-US", { month: "long" })).replace("MMM", now.toLocaleDateString("en-US", { month: "short" })); let result = format;
result = result.replace(/YYYY/g, year.toString());
result = result.replace(/YY/g, year.toString().slice(-2));
result = result.replace(/MMMM/g, now.toLocaleDateString("en-US", { month: "long" }));
result = result.replace(/MMM/g, now.toLocaleDateString("en-US", { month: "short" }));
result = result.replace(/MM/g, month.toString().padStart(2, "0"));
result = result.replace(/(?<![A-Za-z])M(?![A-Za-z])/g, month.toString());
result = result.replace(/dddd/g, now.toLocaleDateString("en-US", { weekday: "long" }));
result = result.replace(/ddd/g, now.toLocaleDateString("en-US", { weekday: "short" }));
result = result.replace(/DD/g, day.toString().padStart(2, "0"));
result = result.replace(/(?<![A-Za-z])D(?![A-Za-z])/g, day.toString());
return result;
} }
async getOrCreateDailyNote() { async getOrCreateDailyNote() {
const { vault } = this.app; const { vault } = this.app;

View File

@@ -598,21 +598,32 @@ export default class FocusTaskPlugin extends Plugin {
formatDailyNoteDate(format: string): string { formatDailyNoteDate(format: string): string {
const now = new Date(); const now = new Date();
const year = now.getFullYear(); const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, '0'); const month = now.getMonth() + 1;
const day = now.getDate().toString().padStart(2, '0'); const day = now.getDate();
// Handle common date format tokens // Use placeholders to avoid replacement conflicts
return format // Replace longer tokens first, use unique placeholders
.replace('YYYY', year.toString()) let result = format;
.replace('YY', year.toString().slice(-2))
.replace('MM', month) // Year tokens
.replace('M', (now.getMonth() + 1).toString()) result = result.replace(/YYYY/g, year.toString());
.replace('DD', day) result = result.replace(/YY/g, year.toString().slice(-2));
.replace('D', now.getDate().toString())
.replace('dddd', now.toLocaleDateString('en-US', { weekday: 'long' })) // Month tokens (longer first)
.replace('ddd', now.toLocaleDateString('en-US', { weekday: 'short' })) result = result.replace(/MMMM/g, now.toLocaleDateString('en-US', { month: 'long' }));
.replace('MMMM', now.toLocaleDateString('en-US', { month: 'long' })) result = result.replace(/MMM/g, now.toLocaleDateString('en-US', { month: 'short' }));
.replace('MMM', now.toLocaleDateString('en-US', { month: 'short' })); result = result.replace(/MM/g, month.toString().padStart(2, '0'));
// Only replace standalone M, not part of other tokens
result = result.replace(/(?<![A-Za-z])M(?![A-Za-z])/g, month.toString());
// Day tokens (longer first)
result = result.replace(/dddd/g, now.toLocaleDateString('en-US', { weekday: 'long' }));
result = result.replace(/ddd/g, now.toLocaleDateString('en-US', { weekday: 'short' }));
result = result.replace(/DD/g, day.toString().padStart(2, '0'));
// Only replace standalone D, not part of other tokens
result = result.replace(/(?<![A-Za-z])D(?![A-Za-z])/g, day.toString());
return result;
} }
async getOrCreateDailyNote(): Promise<TFile | null> { async getOrCreateDailyNote(): Promise<TFile | null> {