TSK-418: Added working day option (#2393)

Signed-off-by: Anton Brechka <anton.brechka@xored.com>
This commit is contained in:
mrsadman99
2022-11-24 23:50:55 +07:00
committed by GitHub
parent 3578f2b90d
commit 34c3d07e5c
13 changed files with 135 additions and 11 deletions
+34 -1
View File
@@ -33,12 +33,19 @@ import { ViewOptionModel } from '@hcengineering/view-resources'
import {
AnyComponent,
AnySvelteComponent,
areDatesEqual,
getMillisecondsInMonth,
isWeekend,
MILLISECONDS_IN_WEEK
} from '@hcengineering/ui'
import tracker from './plugin'
import { defaultPriorities, defaultProjectStatuses, defaultSprintStatuses, issuePriorities } from './types'
import {
defaultPriorities,
defaultProjectStatuses,
defaultSprintStatuses,
issuePriorities,
WorkDaysType
} from './types'
export * from './types'
@@ -641,3 +648,29 @@ export async function moveIssuesToAnotherSprint (
return false
}
}
export function getWorkDate (type: WorkDaysType): number {
const date = new Date(Date.now())
if (type === WorkDaysType.PREVIOUS) {
date.setDate(date.getDate() - 1)
}
// if currentDate is day off then set date to last working day
while (isWeekend(date)) {
date.setDate(date.getDate() - 1)
}
return date.valueOf()
}
export function getWorkDayType (timestamp: number): WorkDaysType | undefined {
const date = new Date(timestamp)
const currentWorkDate = new Date(getWorkDate(WorkDaysType.CURRENT))
const previousWorkDate = new Date(getWorkDate(WorkDaysType.PREVIOUS))
if (areDatesEqual(date, currentWorkDate)) {
return WorkDaysType.CURRENT
} else if (areDatesEqual(date, previousWorkDate)) {
return WorkDaysType.PREVIOUS
}
}