* Define Timestamp type * Implement Timestamp utils * Implement Timespan input * Use timestamp input on config page * Add timespan type to config services * Refactor maxExpiration to use timespan type across services and components * Update sessionDuration to use timespan type in config and adjust token expiration logic * Update localized strings
30 lines
718 B
TypeScript
30 lines
718 B
TypeScript
import * as moment from "moment";
|
|
|
|
export function parseRelativeDateToAbsolute(relativeDate: string) {
|
|
if (relativeDate == "never") return moment(0).toDate();
|
|
|
|
return moment()
|
|
.add(
|
|
relativeDate.split("-")[0],
|
|
relativeDate.split("-")[1] as moment.unitOfTime.DurationConstructor,
|
|
)
|
|
.toDate();
|
|
}
|
|
|
|
type Timespan = {
|
|
value: number;
|
|
unit: "minutes" | "hours" | "days" | "weeks" | "months" | "years";
|
|
};
|
|
|
|
export function stringToTimespan(value: string): Timespan {
|
|
const [time, unit] = value.split(" ");
|
|
return {
|
|
value: parseInt(time),
|
|
unit: unit as Timespan["unit"],
|
|
};
|
|
}
|
|
|
|
export function timespanToString(timespan: Timespan) {
|
|
return `${timespan.value} ${timespan.unit}`;
|
|
}
|