-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcommon.ts
More file actions
24 lines (18 loc) · 795 Bytes
/
common.ts
File metadata and controls
24 lines (18 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { formatTimeYMD } from '@util/time'
export const GROUP_PREFIX = "_g_"
export const cvtGroupId2Host = (groupId: number): string => `${GROUP_PREFIX}${groupId}`
export const formatDateStr = (date: string | Date): string => {
if (typeof date === 'string') return date
return formatTimeYMD(date)
}
export const zeroResult = (): timer.core.Result => ({ focus: 0, time: 0 })
export const zeroRow = (host: string, date: string): timer.core.Row => ({ host, date, focus: 0, time: 0 })
export const increase = (a: timer.core.Result, b: timer.core.Result | undefined) => {
const res: timer.core.Result = {
focus: a.focus + (b?.focus ?? 0),
time: a.time + (b?.time ?? 0),
}
const run = (a.run ?? 0) + (b?.run ?? 0)
run && (res.run = run)
return res
}