Bug Fixes

This commit is contained in:
2025-11-22 20:26:18 +01:00
parent aeb1d62895
commit d4f2af179f

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> {