Files
ihaleist/src/services/reminderPreferences.js
T

14 lines
956 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export function validateReminderPreferences(value) {
if(!value || typeof value!=='object' || Array.isArray(value))throw new Error('Bildirim ayarları geçersiz.');
for(const key of ['pushEnabled','quietEnabled'])if(typeof value[key]!=='boolean')throw new Error('Bildirim seçimini kontrol edin.');
for(const key of ['quietStart','quietEnd'])if(typeof value[key]!=='string'||!/^([01]\d|2[0-3]):[0-5]\d$/.test(value[key]))throw new Error('Sessiz saatleri saat:dakika biçiminde girin.');
return value;
}
export function quietNow(preferences,now=new Date()) {
if(!preferences?.quietEnabled)return false;
try {validateReminderPreferences(preferences);}catch{return true;}
const minute=text=>Number(text.slice(0,2))*60+Number(text.slice(3));
const start=minute(preferences.quietStart),end=minute(preferences.quietEnd),current=now.getHours()*60+now.getMinutes();
return start<=end ? current>=start&&current<end : current>=start||current<end;
}