mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
* chore: ignore all .data directories * fix: date locale for unit tests * test: disable parallelism to prevent database locks * chore: fix lint errors * chore: remove unused function --------- Co-authored-by: zebrapurring <> Co-authored-by: Tonya <tonya@tokia.dev>
27 lines
668 B
TypeScript
27 lines
668 B
TypeScript
import { addDays } from "date-fns";
|
|
|
|
export function zeroTime(date: Date): Date {
|
|
const result = new Date(date.getTime());
|
|
result.setHours(0, 0, 0, 0);
|
|
return result;
|
|
}
|
|
|
|
export function factorRange(offset: number = 7): [Date, Date] {
|
|
const date = zeroTime(new Date());
|
|
|
|
return [date, addDays(date, offset)];
|
|
}
|
|
|
|
export function factory(offset = 0): Date {
|
|
if (offset) {
|
|
return addDays(zeroTime(new Date()), offset);
|
|
}
|
|
|
|
return zeroTime(new Date());
|
|
}
|
|
|
|
export function parse(yyyyMMdd: string): Date {
|
|
const parts = yyyyMMdd.split("-") as [string, string, string];
|
|
return new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]));
|
|
}
|