1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| // Fonction pour ajouter du temps
function dateAdd( date, units ){
let ret = new Date( date );
//ret.setDate(ret.getDate() + units); // ajouter jours
ret.setMinutes( ret.getMinutes() + units); // ajouter minutes
return ret;
}
// Vérifier si 'firstLog' est déjà dans localStorage
const firstLog = localStorage.getItem('firstLog');
// Créer 'todayLog' dans localStorage avec la date du jour
localStorage.setItem('todayLog', new Date());
const todayLog = localStorage.getItem('todayLog' );
// Création de la variable 'notifFive' pour ajouter du temps à 'firstLog' avec la fonction 'dateAdd'
// Puis ajout de 'notifFive' au localStorage
let notifFive = dateAdd( firstLog, 1 );
localStorage.setItem( 'notifFive', notifFive );
notifFive = localStorage.getItem( 'notifFive' );
let notification = "";
// Si firstLog n'existe pas, le créer et l'enregistrer
if ( firstLog == null ){
localStorage.setItem( 'firstLog', new Date() );
} else {
if ( todayLog > notifFive ){
localStorage.setItem( 'notification', 'Show notification' );
notification = localStorage.getItem( 'notification' );
} else {
localStorage.setItem( 'notification', 'Hide notification' );
notification = localStorage.getItem( 'notification' );
}
console.log( "firstLog = ", firstLog );
console.log( "todayLog = ", todayLog );
console.log( "notifFive = ", notifFive );
console.log( "notification = ", notification );
} |
Partager