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

error on running #18

Closed
Mantou1233 opened this issue Dec 11, 2022 · 3 comments
Closed

error on running #18

Mantou1233 opened this issue Dec 11, 2022 · 3 comments

Comments

@Mantou1233
Copy link

image
this gives invaild parsed results (1y9d3h5m3s (which is 32346303000ms) -> { d: 374, h: 9, m: 5, s: 3, ms: 0 })

@Mantou1233
Copy link
Author

Mantou1233 commented Dec 11, 2022

test code:

export default function parseMilliseconds(milliseconds: number) {
    if (typeof milliseconds !== "number") {
        throw new TypeError("Expected a number");
    }

    return {
        days: Math.trunc(milliseconds / 86400000),
        hours: Math.trunc(milliseconds / 3600000) % 24,
        minutes: Math.trunc(milliseconds / 60000) % 60,
        seconds: Math.trunc(milliseconds / 1000) % 60,
        milliseconds: Math.trunc(milliseconds) % 1000,
        microseconds: Math.trunc(milliseconds * 1000) % 1000,
        nanoseconds: Math.trunc(milliseconds * 1e6) % 1000
    };
}

console.log(parseMilliseconds(32346303000));

image

@Mantou1233
Copy link
Author

@sindresorhus

@sindresorhus
Copy link
Owner

How exactly is it invalid? Looks correct to me.

@sindresorhus sindresorhus closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2024
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

2 participants