Created
November 1, 2023 11:05
-
-
Save shaedrich/92a0a4704aa85e43479502c5dcdd52cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty(Number.prototype, "milliseconds", { | |
get() { | |
return this / 1000; | |
}, | |
configurable: true, | |
}); | |
Object.defineProperty(Number.prototype, "seconds", { | |
get() { | |
return this; | |
}, | |
configurable: true, | |
}); | |
Object.defineProperty(Number.prototype, "minutes", { | |
get() { | |
return this * 60; | |
}, | |
configurable: true, | |
}); | |
Object.defineProperty(Number.prototype, "hours", { | |
get() { | |
return this * 60 * 60; | |
}, | |
configurable: true, | |
}); | |
Object.defineProperty(Number.prototype, "days", { | |
get() { | |
return this * 60 * 60 * 24; | |
}, | |
configurable: true, | |
}); | |
// Use it like this | |
(3).milliseconds; // => 0.003 | |
(3).seconds; // => 3 | |
(3).minutes; // => 180 | |
(3).hours; // => 10_800 | |
(3).days; // => 259_200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment