diff options
author | aidahosa1 <aisosa_idahosa@brown.edu> | 2024-09-17 13:12:08 -0400 |
---|---|---|
committer | aidahosa1 <aisosa_idahosa@brown.edu> | 2024-09-17 13:12:08 -0400 |
commit | 597ad3716286e9eff29316605514218889690da5 (patch) | |
tree | 4cda12c38e289a4b1c462d614ea8f44b267c12af /src/ClientUtils.ts | |
parent | 313b3d3e67689b175cdc85426ff6af809d476622 (diff) | |
parent | 62eb66ca7d3404f9977acdf73f815f4920fb964d (diff) |
Merge branch 'master' into aisosa-starter
Diffstat (limited to 'src/ClientUtils.ts')
-rw-r--r-- | src/ClientUtils.ts | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/ClientUtils.ts b/src/ClientUtils.ts index 844419e4e..58648c5b6 100644 --- a/src/ClientUtils.ts +++ b/src/ClientUtils.ts @@ -682,20 +682,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 - 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]); - - const toYear = parseInt(toParts[0]); - const toMonth = parseInt(toParts[1]) - 1; - const toDay = parseInt(toParts[2]); - - return [new Date(fromYear, fromMonth, fromDay), new Date(toYear, toMonth, toDay)]; + 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) { |