diff --git a/src/main.ts b/src/main.ts index 0b50185..7a41eaa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -598,21 +598,32 @@ export default class FocusTaskPlugin extends Plugin { formatDailyNoteDate(format: string): string { const now = new Date(); const year = now.getFullYear(); - const month = (now.getMonth() + 1).toString().padStart(2, '0'); - const day = now.getDate().toString().padStart(2, '0'); + const month = now.getMonth() + 1; + const day = now.getDate(); - // Handle common date format tokens - 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' })); + // Use placeholders to avoid replacement conflicts + // Replace longer tokens first, use unique placeholders + let result = format; + + // Year tokens + result = result.replace(/YYYY/g, year.toString()); + result = result.replace(/YY/g, year.toString().slice(-2)); + + // Month tokens (longer first) + 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')); + // Only replace standalone M, not part of other tokens + result = result.replace(/(? { @@ -965,4 +976,4 @@ class FocusTaskSettingTab extends PluginSettingTab {

`; } -} \ No newline at end of file +}