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

orc-date

v1.0.4

Published

A small date converter tool for converting to and from JS Date() and different format strings.

Downloads

8

Readme

Orc-Date

npm version Download Count

A small date converter tool for converting to and from JS Date() and different format strings.

Install

npm i orc-date --save

Usage

import OrcDate from 'orc-date';

var formatted = OrcDate.convert('May 25, 1977', 'MMMM DD, YYYY', 'DD/MM/YYYY');

console.info(formatted); // outputs '25/05/1977'

API

OrcDate.convert(date, originalFormatString, newFormatString, correctToZulu)

Converts a date represented as a string or a Date() object into a newly formatted string or Date() object.

Parameters

string | Date date: Either a Date() object or a string representation of a date that follows the pattern listed in originalFormatString.

string originalFormatString: The format that date corresponds to. If it's a Date() this must be "Date". The format needs to match the pattern used by date.

  • 'DD' represents the date of the month.

  • 'MM' represents the month, displayed as a number.

  • 'MMM' represents the month, displayed as its short name in English. (e.g. December is 'Dec').

  • 'MMMM' represents the month, displayed as its long name in English. (e.g. 'December').

  • 'YYYY' represents the year with its full four digits.

    For a format to be valid it must include 'DD', 'YYYY', and one of the month options (and only one). All other content inside the format is treated as separators. Month names are case sensitive.

    If a date of 'May 25, 1977' was passed in, the expected `originalFormat' should be 'MMMM DD, YYYY'.

string newFormatString: The format that the date should be returned as. Uses the same rules as the format of oldFormatString. If May 25, 1977 was used and the newFormatString is set to 'DD/MM/YYYY' the function will return '25/05/1977'. If newFormatString's value is 'Date', it will return the date as a new Date() object.

boolean? correctToZulu: Optional, and defaults to true. If set to true, then OrcDate will compensate for timezone offsets on the user's machine to prevent it from converting a Date() object into the wrong day based on timezone. Only used when converting to/from a Date() object.

Examples

var date = new Date(); // pretend this is done 01 June, 2019.
var formatted = OrcDate.convert(date, 'Date', 'YYYY-MM-DD');
console.info(formatted); // returns '2019-06-01'.
var date = OrcDate.convert('June 01, 2016', 'MMMM DD, YYYY', 'Date');
console.info(date); // returns '> Date 2019-06-01T00:00:00Z'.

OrcDate.convertMonth(month, key)

Converts a month's number (using 1-based index), short name in English (such as 'Dec'), or long name in English (such as 'December') into one of those representations for a month as desired per key.

Params

number | string month: Either a number from 1 - 12, or a short or long name for a month (such as 'Dec' or 'December'). Case sensitive.

string key: The desired format to return for the month. 'MM' for number, 'MMM' for short name, and 'MMMM' for long name.

Examples

var month = OrcDate.convertMonth(2, 'MMM');
console.info(month); // returns 'Feb'.
var month = OrcDate.convertMonth('August', 'MM');
console.info(month); // returns 8.

OrcDate.correctDateToZulu(date)

Returns a Date() object that has been corrected to Zulu time to avoid the date displaying wrong due to local timezone offsets.

Params

Date date: A Date() object to correct.

Examples

var uncorrectedDate = new Date();
var correctedDate = OrcDate.correctDateToZulu(uncorrectedDate);
// correctedDate will adjust for the timezone offset, preventing Date() from possibly showing wrong due to timezone.