Skip to content

os.uptime is completely broken #2358

Description

@amyipdev

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?

Activity

  1. richardlau commented on Dec 16, 2019

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

    os.uptime():

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

  2. transferred this issue fromnodejs/nodeon Dec 16, 2019
  3. amyipdev commented on Dec 16, 2019

    @amyipdev
    Author

    Ahh I see

  4. addaleax commented on Dec 18, 2019

    @addaleax
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions