mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-31 04:38:02 +00:00
UBERF-4238: Fix calendar utils (#4092)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
32b48d516b
commit
77c2b029b3
@ -229,7 +229,8 @@ export type DocData<T extends Doc> = T extends AttachedDoc ? AttachedData<T> : D
|
|||||||
export enum DateRangeMode {
|
export enum DateRangeMode {
|
||||||
DATE = 'date',
|
DATE = 'date',
|
||||||
TIME = 'time',
|
TIME = 'time',
|
||||||
DATETIME = 'datetime'
|
DATETIME = 'datetime',
|
||||||
|
TIMEONLY = 'timeonly'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,13 +104,17 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#if value !== null && value !== undefined}
|
{#if value !== null && value !== undefined}
|
||||||
{#if shouldShowLabel}
|
{#if shouldShowLabel}
|
||||||
{new Date(value).getDate()}
|
{#if mode !== DateRangeMode.TIMEONLY}
|
||||||
{getMonthName(new Date(value), 'short')}
|
{new Date(value).getDate()}
|
||||||
{#if new Date(value).getFullYear() !== today.getFullYear()}
|
{getMonthName(new Date(value), 'short')}
|
||||||
{new Date(value).getFullYear()}
|
{#if new Date(value).getFullYear() !== today.getFullYear()}
|
||||||
|
{new Date(value).getFullYear()}
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{#if withTime}
|
{#if withTime}
|
||||||
<div class="time-divider" />
|
{#if mode !== DateRangeMode.TIMEONLY}
|
||||||
|
<div class="time-divider" />
|
||||||
|
{/if}
|
||||||
{new Date(value).getHours().toString().padStart(2, '0')}
|
{new Date(value).getHours().toString().padStart(2, '0')}
|
||||||
<span class="separator">:</span>
|
<span class="separator">:</span>
|
||||||
{new Date(value).getMinutes().toString().padStart(2, '0')}
|
{new Date(value).getMinutes().toString().padStart(2, '0')}
|
||||||
|
@ -57,7 +57,7 @@ function generateDailyValues (
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (bySetPos == null || bySetPos.includes(getSetPos(currentDate))) {
|
if (bySetPos == null || bySetPos.includes(getSetPos(currentDate))) {
|
||||||
const res = currentDate.getTime()
|
const res = currentDate.getTime()
|
||||||
if (res > from && res < to) {
|
if (res >= from && res <= to) {
|
||||||
values.push(res)
|
values.push(res)
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
@ -66,7 +66,7 @@ function generateDailyValues (
|
|||||||
currentDate.setDate(currentDate.getDate() + (interval ?? 1))
|
currentDate.setDate(currentDate.getDate() + (interval ?? 1))
|
||||||
if (count !== undefined && i === count) break
|
if (count !== undefined && i === count) break
|
||||||
if (endDate != null && currentDate.getTime() > endDate) break
|
if (endDate != null && currentDate.getTime() > endDate) break
|
||||||
if (currentDate.getTime() > to) break
|
if (currentDate.getTime() >= to) break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ function generateWeeklyValues (
|
|||||||
while (date < end) {
|
while (date < end) {
|
||||||
if ((byDay == null || matchesByDay(date, byDay)) && (bySetPos == null || bySetPos.includes(getSetPos(date)))) {
|
if ((byDay == null || matchesByDay(date, byDay)) && (bySetPos == null || bySetPos.includes(getSetPos(date)))) {
|
||||||
const res = date.getTime()
|
const res = date.getTime()
|
||||||
if (res > from && res < to) {
|
if (res >= from && res <= to) {
|
||||||
values.push(res)
|
values.push(res)
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
@ -100,7 +100,7 @@ function generateWeeklyValues (
|
|||||||
date = new Date(date.setDate(date.getDate() + 1))
|
date = new Date(date.setDate(date.getDate() + 1))
|
||||||
if (count !== undefined && i === count) return
|
if (count !== undefined && i === count) return
|
||||||
if (endDate != null && date.getTime() > endDate) return
|
if (endDate != null && date.getTime() > endDate) return
|
||||||
if (date.getTime() > to) return
|
if (date.getTime() >= to) return
|
||||||
}
|
}
|
||||||
|
|
||||||
currentDate = new Date(next)
|
currentDate = new Date(next)
|
||||||
@ -172,7 +172,7 @@ function generateMonthlyValues (
|
|||||||
(bySetPos == null || bySetPos.includes(getSetPos(currentDate)))
|
(bySetPos == null || bySetPos.includes(getSetPos(currentDate)))
|
||||||
) {
|
) {
|
||||||
const res = currentDate.getTime()
|
const res = currentDate.getTime()
|
||||||
if (res > from && res < to) {
|
if (res >= from && res <= to) {
|
||||||
values.push(res)
|
values.push(res)
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
@ -181,7 +181,7 @@ function generateMonthlyValues (
|
|||||||
|
|
||||||
if (count !== undefined && i === count) return
|
if (count !== undefined && i === count) return
|
||||||
if (endDate != null && date.getTime() > endDate) return
|
if (endDate != null && date.getTime() > endDate) return
|
||||||
if (date.getTime() > to) return
|
if (date.getTime() >= to) return
|
||||||
}
|
}
|
||||||
currentDate = new Date(next)
|
currentDate = new Date(next)
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ function generateYearlyValues (
|
|||||||
(bySetPos == null || bySetPos.includes(getSetPos(currentDate)))
|
(bySetPos == null || bySetPos.includes(getSetPos(currentDate)))
|
||||||
) {
|
) {
|
||||||
const res = currentDate.getTime()
|
const res = currentDate.getTime()
|
||||||
if (res > from && res < to) {
|
if (res >= from && res <= to) {
|
||||||
values.push(res)
|
values.push(res)
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
@ -220,7 +220,7 @@ function generateYearlyValues (
|
|||||||
date = new Date(date.setDate(date.getDate() + 1))
|
date = new Date(date.setDate(date.getDate() + 1))
|
||||||
if (count !== undefined && i === count) return
|
if (count !== undefined && i === count) return
|
||||||
if (endDate != null && date.getTime() > endDate) return
|
if (endDate != null && date.getTime() > endDate) return
|
||||||
if (date.getTime() > to) return
|
if (date.getTime() >= to) return
|
||||||
}
|
}
|
||||||
currentDate = new Date(next)
|
currentDate = new Date(next)
|
||||||
}
|
}
|
||||||
@ -310,8 +310,9 @@ export function getAllEvents (events: Event[], from: Timestamp, to: Timestamp):
|
|||||||
arr.push(instance)
|
arr.push(instance)
|
||||||
instancesMap.set(instance.recurringEventId, arr)
|
instancesMap.set(instance.recurringEventId, arr)
|
||||||
} else {
|
} else {
|
||||||
if (from > event.dueDate) continue
|
if (from >= event.dueDate) continue
|
||||||
if (event.date > to) continue
|
if (event.date >= to) continue
|
||||||
|
|
||||||
base.push(event)
|
base.push(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -325,7 +326,7 @@ export function getAllEvents (events: Event[], from: Timestamp, to: Timestamp):
|
|||||||
...instances.filter((p) => {
|
...instances.filter((p) => {
|
||||||
return from <= p.dueDate && p.date <= to && p.isCancelled !== true
|
return from <= p.dueDate && p.date <= to && p.isCancelled !== true
|
||||||
})
|
})
|
||||||
]
|
].map((it) => ({ ...it, date: Math.max(from, it.date), dueDate: Math.min(to, it.dueDate) }))
|
||||||
res.sort((a, b) => a.date - b.date)
|
res.sort((a, b) => a.date - b.date)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user