diff options
author | bobzel <zzzman@gmail.com> | 2024-09-04 22:58:40 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-09-04 22:58:40 -0400 |
commit | 9014cc474a039f0daef6cc0ee2011329da7703ac (patch) | |
tree | 12f45bb9b20d8ee435ad8d7dc9d1b505a493b03a /src/ClientUtils.ts | |
parent | df5217eea01b6ee3ce03ceede030306d05f19c58 (diff) |
more fixes for calendarBox to preserve selection when view changes.
Diffstat (limited to 'src/ClientUtils.ts')
-rw-r--r-- | src/ClientUtils.ts | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/ClientUtils.ts b/src/ClientUtils.ts index d149c2eae..01eda7e98 100644 --- a/src/ClientUtils.ts +++ b/src/ClientUtils.ts @@ -648,24 +648,14 @@ export function DivWidth(ele: HTMLElement | null): number { } export function dateRangeStrToDates(dateStr: string) { + const toDate = (str: string) => { + return !str.includes('T') && str.includes('-') ? new Date(Number(str.split('-')[0]), Number(str.split('-')[1]) - 1, Number(str.split('-')[2])) : new Date(str); + }; // dateStr in yyyy-mm-dd format const dateRangeParts = dateStr.split('|'); // splits into from and to date - if (dateRangeParts.length < 2) return { startDate: new Date(), endDate: new Date() }; - return { startDate: new Date(dateRangeParts[0]), endDate: new Date(dateRangeParts[1]) }; - const fromParts = dateRangeParts[0].split('-'); - const toParts = dateRangeParts[1].split('-'); - - const fromYear = parseInt(fromParts[0]); - const fromMonth = parseInt(fromParts[1]) - 1; - const fromDay = parseInt(fromParts[2]?.split('T')[0]); - const fromHour = parseInt(fromParts[2]?.split('T')[1]?.split(':')[0] || '12'); - - const toYear = parseInt(toParts[0]); - const toMonth = parseInt(toParts[1]) - 1; - const toDay = parseInt(toParts[2]?.split('T')[0]); - const toHour = parseInt(fromParts[2]?.split('T')[1]?.split(':')[0] || '12'); - - return { startDate: new Date(fromYear, fromMonth, fromDay, fromHour), endDate: new Date(toYear, toMonth, toDay, toHour) }; + if (dateRangeParts.length < 2 && !dateRangeParts[0]) return { start: new Date(), end: new Date() }; + if (dateRangeParts.length < 2) return { start: toDate(dateRangeParts[0]), end: toDate(dateRangeParts[0]) }; + return { start: new Date(dateRangeParts[0]), end: new Date(dateRangeParts[1]) }; } function replaceCanvases(oldDiv: HTMLElement, newDiv: HTMLElement) { |