Norm
9dddb1eb6d
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
Constants were borrowed from `const.ts` from the backend but also includes `WEEK`, `MONTH`, and `YEAR` constants as well. Co-authored-by: Francis Dinh <normandy@biribiri.dev> Reviewed-on: #183
16 lines
454 B
TypeScript
16 lines
454 B
TypeScript
import { DAY, HOUR } from '@/const';
|
|
|
|
const dateTimeIntervals = {
|
|
'day': DAY,
|
|
'hour': HOUR,
|
|
'ms': 1,
|
|
};
|
|
|
|
export function addTime(x: Date, value: number, span: keyof typeof dateTimeIntervals = 'ms'): Date {
|
|
return new Date(x.getTime() + (value * dateTimeIntervals[span]));
|
|
}
|
|
|
|
export function subtractTime(x: Date, value: number, span: keyof typeof dateTimeIntervals = 'ms'): Date {
|
|
return new Date(x.getTime() - (value * dateTimeIntervals[span]));
|
|
}
|