0.0.11 • Published 3 years ago

utc-date v0.0.11

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

UTC Date

GitHub version downloads license GitHub code size in bytes

npm release node-current Build Status Coverage Status

Experimental Date object overwrite for always using UTC dates by default.

Tested on:

  • Windows = Node.js 12.x, 13.x, 14.x, 15.x and 16.x with ESM
  • Linux = Node.js 12.x and 14.x with ESM

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.

Why?

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.

Ok but this code is terrible!

Feel free to improve it and make a PR. Bug reports are always welcome too.

Updates Changelog

Installing

npm i utc-date --save

Usage

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.

Getting the native Date object

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.

Settings

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 imports when using these options, making sure the ENV variables are loaded into process.env before utc-date is imported.

Incompatibility

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.

0.0.10

3 years ago

0.0.11

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago