Create and delete tokens from web ui
This commit is contained in:
20
moneymgr_web/src/utils/DateUtils.tsx
Normal file
20
moneymgr_web/src/utils/DateUtils.tsx
Normal file
@ -0,0 +1,20 @@
|
||||
import dayjs, { Dayjs } from "dayjs";
|
||||
|
||||
export function timeToDate(time: number | undefined): Dayjs | undefined {
|
||||
if (!time) return undefined;
|
||||
return dayjs(new Date(time * 1000));
|
||||
}
|
||||
|
||||
export function dateToTime(date: Dayjs | undefined): number | undefined {
|
||||
if (!date) return undefined;
|
||||
return Math.floor(date.toDate().getTime() / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UNIX time
|
||||
*
|
||||
* @returns Number of seconds since Epoch
|
||||
*/
|
||||
export function time(): number {
|
||||
return Math.floor(new Date().getTime() / 1000);
|
||||
}
|
32
moneymgr_web/src/utils/FormUtils.tsx
Normal file
32
moneymgr_web/src/utils/FormUtils.tsx
Normal file
@ -0,0 +1,32 @@
|
||||
import { LenConstraint } from "../api/ServerApi";
|
||||
|
||||
/**
|
||||
* Check if a constraint was respected or not
|
||||
*
|
||||
* @returns An error message appropriate for the constraint
|
||||
* violation, if any, or undefined otherwise
|
||||
*/
|
||||
export function checkConstraint(
|
||||
constraint: LenConstraint,
|
||||
value: string | undefined
|
||||
): string | undefined {
|
||||
value = value ?? "";
|
||||
if (value.length < constraint.min)
|
||||
return `Please specify at least ${constraint.min} characters !`;
|
||||
|
||||
if (value.length > constraint.max)
|
||||
return `Please specify at least ${constraint.min} characters !`;
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether a given URL is valid or not
|
||||
*/
|
||||
export function checkURL(s: string): boolean {
|
||||
try {
|
||||
return Boolean(new URL(s));
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user