Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Experimental Date object overwrite for always using UTC / GMT date and time.
Experimental Date
object overwrite for always using UTC dates by default.
Tested on:
Guaranteed to NOT work on Node.js 11.x and lower, this won't be fixed.
Guaranteed to NOT work with CommonJS, a.k.a require(), this WILL be fixed in the future.
On MacOS and Linux, if you wanted to achieve this, all you need to do is set process.env.TZ
to Etc/GMT
, however Windows does not respect this, forcing you to either change your entire system's timezone with a package like set-tz
, which personally I found vastly inconvenient when trying to selfhost apps on my personal computer, or overwritting the entire Date
object to force it to output only UTC values, which is what this package does for you.
*This package probably does work on MacOS (untested) and Linux, but it is only truly needed on Windows.
Feel free to improve it and make a PR. Bug reports are always welcome too.
npm i utc-date --save
On your main file:
import 'utc-date';
This must be placed as early as possible, prior to even other imports to ensure full utc-date usage even within other imports.
All Date
instances from here on will now be using utc-date. This includes sub-files and modules. Does NOT include Date
instances created before utc-date
is loaded.
If for some reason while using utc-date you require using the native Date object, you can import a clone of it from utc-date with:
import { NativeDate } from 'utc-date'
Keep in mind that unlike the Date
overwrite, this is not global and NativeDate
will only be accessible on the file it's imported on.
utc-date supports a few customization settings through the use of ENV variables:
Setting | Description |
---|---|
UTCDATE_NO_OVERWRITE | When set to any value, does not automatically overwrite the Date object with the UTCDate one. (Defaults to overwriting if not set) |
UTCDATE_PATCH_CONSOLE | When set to any value, will patch the console methods to make the logged UTC dates match what you expect from logging the native Date object. (Defaults to not patching when not set) |
UTCDATE_PATCH_INSPECT | When set to any value, will patch the util.inspect method to make the returned values for dates from utc-date match the return values of native dates. (Defaults to not patching when not set) |
Remember to keep in mind load order of
import
s when using these options, making sure the ENV variables are loaded intoprocess.env
before utc-date is imported.
Due to the nature of this package, it is naturally incompatible with any other package or local code that also overwrites/modifies the native Date
object. Extending the Date
object is fine as long as it's done after utc-date is loaded.
Version 0.0.11
UTCDATE_NO_OVERWRITE
: When set to any value, does not automatically overwrite the Date
object with the UTCDate
one. (Defaults to overwriting if not set)UTCDATE_PATCH_CONSOLE
: When set to any value, will patch the console methods to make the logged dates from utc-date match how native dates are logged. (Defaults to not patching when not set)UTCDATE_PATCH_INSPECT
: When set to any value, will patch the util.inspect
method to make the returned values for dates from utc-date match the return values of native dates. (Defaults to not patching when not set)FAQs
Experimental Date object overwrite for always using UTC / GMT date and time.
The npm package utc-date receives a total of 0 weekly downloads. As such, utc-date popularity was classified as not popular.
We found that utc-date demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.