From 86dbe86227192782e8db9fefa09ffb967d43d78a Mon Sep 17 00:00:00 2001 From: Ozan Tellioglu Date: Sun, 12 Mar 2023 21:53:10 +0100 Subject: [PATCH] Custom Date Format Fix --- src/main.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 8007f54..2776dc1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import { CachedMetadata, Menu, Plugin, TAbstractFile, TFile, addIcon } from 'obsidian'; import { OZCalendarView, VIEW_TYPE } from 'view'; import dayjs from 'dayjs'; +import customParseFormat from 'dayjs/plugin/customParseFormat'; import { OZCalendarDaysMap } from 'types'; import { OZCAL_ICON } from './util/icons'; import { OZCalendarPluginSettings, DEFAULT_SETTINGS, OZCalendarPluginSettingsTab } from './settings/settings'; @@ -18,6 +19,8 @@ export default class OZCalendarPlugin extends Plugin { async onload() { addIcon('OZCAL_ICON', OZCAL_ICON); + dayjs.extend(customParseFormat); + // Load Settings this.addSettingTab(new OZCalendarPluginSettingsTab(this.app, this)); await this.loadSettings(); @@ -178,7 +181,7 @@ export default class OZCalendarPlugin extends Plugin { // Check the FM keys vs the provided key by the user in settings for (let k of Object.keys(fm)) { if (k === this.settings.yamlKey) { - let fmValue = fm[k]; + let fmValue = (fm[k] as string).substring(0, this.settings.dateFormat.length); // Parse the date with provided date format let parsedDayJsDate = dayjs(fmValue, this.settings.dateFormat); // Take only YYYY-MM-DD part fromt the date as String