ez-local-time
Note: In Development! Expect Changes before March 1, 2018. The 1st Stable Version (for production use) will be 1.0.0..
This cut and dry speed demon of a Node.js module delivers your desired localized date and time. This codebase depends solely on the Javascript API. There are absolutely no dependent packages to keep up to date, just install and import/require ez-local-time and never deal with new Date
or Date.now()
again when trying to deal with local time or time zones. You provide the region and desired response format (time, date, or both) and get the local date/time.
The region parameter follows a logical protocol: County/City, i.e. America/New_York .
Note: If a country or city is more than a single word, all words are capitalized and are separated by an underscore (as you can see above).
For further reference on time zones and regions please refer to:
Internet Assigned Numbers Authority: https://www.iana.org/time-zones
Time Difference (to explore locations): https://www.zeitverschiebung.net/en/country/us
Getting Started
Install it via npm:
npm i ez-local-time
Require the Module:
const localTime = require('ez-local-time')
Now Put it To Work - It's Always On Time!
Get Localized Time:
const DenverTime = localTime('Mountain', 't')
Get Localized Date:
const HollywoodDate = localTime('pacific', 'd')
Get Localized Time & Date:
const BigAppleTimeAndDate = localTime('east', '*')
Parameters
const varName = localTime([region], [response])
[region] : 'Pacific' || 'Pac' || 'Mountain' || 'Mtn' || 'Central' || 'Cen' || 'East' || 'Eas' <> STRING
NOTE: If you want to work outside the US (or in Alaska or Hawaii) just use the convention 'Country_Name/City_Name' i.e. 'America/Anchorage' or 'Czech_Republic/Prague' as your region input. It has worldwide functionality and defaults to UTC time or GMT.
[response] : 'time' || 't' || 'date' || 'd' || '*' <> STRING
Example
Note: If you are using ES6, i.e. React, (import and not require) you must compile your application code before interacting with the ez-local-time module.
'use strict'
const localTime = require('ez-local-time')
const DenverDate = localTime('Mtn', 'd')
const DenverTime = localTime('mountain', 'time')
const DenverDateAndTime = localTime('America/Denver', '*')
In The Pipeline
I am developing version 1.0.0 as a proof of concept. Many features have been placed in the ice box (for now). I am placing a developmental priority on compatibility with ES6, allowing the React.js community access to a basic local time library, aside from Moment.js. Expect those updates in version 1.0.0 (the first stable production ready launch) by March 1, 2018. This is a community project, pull requests are welcome. Let's see where we can take this!
License
MIT