1

I am trying to create a 24hr timer on a database using quick.db, but my timer isn't ticking, and time logs negative number.

const db = require('quick.db');
const Discord = require('discord.js');
const ms = require('parse-ms');

let timer = await db.fetch(`daily_timer`);
let timeout = 86400000;

if (timer !== null && timeout - (Date.now() * -2 - timer) > 0) {
    let time = ms(timeout - (Date.now() * -2 - timer));
    console.log(time);
    etc..
};

If the * -2 is removed from let time = .. then it logs everything as negative. Date.now() returns as normal.

console.log for time: { days: -18950, hours: -9, minutes: -56, seconds: -51, milliseconds: -673, microseconds: -0, nanoseconds: -936 }

console.log for Date.now(): 1637488611676

Any help would be appreciated, as I really have no idea why the time is negative.

MrLlamaDev
  • 21
  • 5

1 Answers1

1

The unix timestamp 86400000 represents the 27th of September 1972. With timeout - Date.now() you are asking, how much time do i need to add to the current date, to get to the 27th of September 1972. Since the current date is FAR beyond 27th of September 1972, the time you need to add will be negative.

Olian04
  • 6,480
  • 2
  • 27
  • 54