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 {
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(/(?<![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> {