mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 21:33:02 +01:00
* feat: begin upgrading deps, still very buggy * feat: progress * feat: sort all type issues * fix: sort type issues * fix: import sonner styles * fix: nuxt is the enemy * fix: try sorting issue with workflows * fix: update vitest config for dynamic import of path and defineConfig * fix: add missing import * fix: add time out to try and fix issues * fix: add ui:ci:preview task for frontend build in CI mode * fix: i was silly * feat: add go:ci:with-frontend task for CI mode and remove ui:ci:preview from e2e workflow * fix: update baseURL in Playwright config for local testing to use port 7745 * fix: update E2E_BASE_URL and remove wait for timeout in login test for smoother execution
37 lines
907 B
TypeScript
37 lines
907 B
TypeScript
import { addDays } from "date-fns";
|
|
|
|
/*
|
|
* Formats a date as a string
|
|
* */
|
|
export function format(date: Date | string): string {
|
|
if (typeof date === "string") {
|
|
return date;
|
|
}
|
|
return date.toISOString().split("T")[0]!;
|
|
}
|
|
|
|
export function zeroTime(date: Date): Date {
|
|
return new Date(
|
|
new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - date.getTimezoneOffset() * 60000
|
|
);
|
|
}
|
|
|
|
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]));
|
|
}
|