Skip to content

Instantly share code, notes, and snippets.

@shaedrich
Created November 1, 2023 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaedrich/92a0a4704aa85e43479502c5dcdd52cb to your computer and use it in GitHub Desktop.
Save shaedrich/92a0a4704aa85e43479502c5dcdd52cb to your computer and use it in GitHub Desktop.
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