Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.uptime is completely broken #2358

Closed
amyipdev opened this issue Dec 16, 2019 · 3 comments
Closed

os.uptime is completely broken #2358

amyipdev opened this issue Dec 16, 2019 · 3 comments

Comments

@amyipdev
Copy link

Trying to make a function that sends the server uptime. When I run uptime, I get:

11:35:04 up 18 days, 17:39,  7 users,  load average: 0.09, 0.10, 0.09

So this is saying my server has been up for 18 days, 17 hours, and 39 minutes, correct? So, my script for calculating time is this (its the same as my discord.js client.uptime script, which ive proved over 72 hours works fine in internal testing) is:

var serverUptime = os.uptime();
let serverSeconds = (serverUptime / 1000);
let sdays = Math.floor(serverSeconds / 86400);
let shours = Math.floor(serverSeconds / 3600) - (sdays * 24);
serverSeconds %= 3600;
let sminutes = Math.floor(serverSeconds / 60);
let sseconds = Math.floor(serverSeconds % 60);
var serverUptimeCalc = `${sdays} days, ${shours} hours, ${sminutes} minutes and ${sseconds} seconds`;

This should give me the uptime, correct? Well, no. When I print serverUptimeCalc, I get:
0 days, 0 hours, 26 minutes and 59 seconds
I ran this 10 minutes ago, and it gave me 26 minutes 58 seconds.
Is this a bug, or am I just terrible at making time scripts?

@richardlau
Copy link
Member

var serverUptime = os.uptime();
let serverSeconds = (serverUptime / 1000);
...

os.uptime():

The os.uptime() method returns the system uptime in number of seconds.

@richardlau richardlau transferred this issue from nodejs/node Dec 16, 2019
@amyipdev
Copy link
Author

Ahh I see

@addaleax
Copy link
Member

@ProgrammerPlays It seems like this has been answered? :) I’m closing this, let us know if you’d like to reopen this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants