feat: move amount second calculation to mapping const

This commit is contained in:
kolaente 2022-09-29 18:20:43 +02:00
parent e65c286730
commit 7725de7483
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -1,5 +1,12 @@
const DEFAULT_REMINDER_KEY = 'defaultReminder'
const AMOUNTS_IN_SECONDS: { [key: string]: number } = {
minutes: 60,
hours: 60 * 60,
days: 60 * 60 * 24,
months: 60 * 60 * 24 * 30,
}
interface DefaultReminderSettings {
enabled: boolean,
amount: number,
@ -12,18 +19,7 @@ interface SavedReminderSettings {
}
function calculateDefaultReminderSeconds(type: string, amount: number): number {
switch (type) {
case 'minutes':
return amount * 60
case 'hours':
return amount * 60 * 60
case 'days':
return amount * 60 * 60 * 24
case 'months':
return amount * 60 * 60 * 24 * 30
}
return 0
return amount * (AMOUNTS_IN_SECONDS[type] || 0)
}
export function saveDefaultReminder(enabled: boolean, type: string, amount: number) {