127.0.0.1:8000 budget / master src / js / utils / time.js
master

Tree @master (Download .tar.gz)

time.js @masterraw · history · blame

const daily_queue = [];

const one_day = 86400000; // 1000 * 60 * 60 * 24
const today = new Date() // get today's date
const tomorrow = new Date(today)
tomorrow.setDate(today.getDate() + 1)
tomorrow.setHours(0, 0, 0, 0)
const timeout_remaining = tomorrow.getTime() - today.getTime();
setTimeout(process_daily_queue, timeout_remaining);

function process_daily_queue() {
    daily_queue.forEach(function(callback) {
        callback();
    });
    setTimeout(process_daily_queue, one_day);
}

module.exports = {
    add_to_daily_queue: function(callback) {
        daily_queue.push(callback);
    }
};