feat: Reminders #44

Merged
Anri merged 54 commits from feat/reminders into main 2023-01-17 12:15:15 +01:00
Showing only changes of commit 21e69cf0c2 - Show all commits

View file

@ -10,16 +10,34 @@ export const showDate = (
locale: Map<string, unknown>,
date: Date
) => {
return date.toLocaleString(tz).replace(' ', ` ${
locale.get('u_time_at')
} `);
return date.toLocaleString(tz).replace(' ', ` ${locale.get('u_time_at')} `);
};
enum TimeSecond {
Year = 31536000,
Week = 604800,
Day = 86400,
Hour = 3600,
Minute = 60,
Second = 1
}
/**
* Take a cooldown, for example 2min and transform it to seconds, here: 120s
* @param time time in human format
* @returns time in seconds
*/
export const strToSeconds = (time: string) => {
return 0;
const regex = new RegExp(`(?<${TimeSecond[TimeSecond.Year]}>[0-9]+(?=[y|a]))|(?<${TimeSecond[TimeSecond.Week]}>[0-9]+(?=[w]))|(?<${TimeSecond[TimeSecond.Day]}>[0-9]+(?=[d|j]))|(?<${TimeSecond[TimeSecond.Hour]}>[0-9]+(?=[h]))|(?<${TimeSecond[TimeSecond.Minute]}>[0-9]+(?=[m]))|(?<${TimeSecond[TimeSecond.Second]}>[0-9]+(?=[s]?))`);
const data = Object.assign({}, regex.exec(time)?.groups);
let res = 0;
Object.entries(data).forEach(([key, value]) => {
if (value) {
res += +value * TimeSecond[key as keyof typeof TimeSecond];
}
});
return res;
};