npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

utc-date

v0.0.11

Published

Experimental Date object overwrite for always using UTC / GMT date and time.

Downloads

3

Readme

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.