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

date-plus

v1.2.0

Published

Javascript dates extended with dateformat

Downloads

193

Readme

date-plus

CI

Javascript dates extended with dateformat

  • Tiny wrapper function to create dates
  • returns normal Date objects extended with .format()
  • uses the built-in date parser, fixes a parser annoyance in ES5
  • unlike dateformat, format() doesn't throw if the date is invalid
  • choice of language strings - currently de and en are included

installation

$ npm install date-plus

usage

var date = require('date-plus');

// parse using native javascript parser
var d = date('5/10/2015');

// format
var output = d.format('ddd, dd mmm yyyy HH:MM:ss Z');

// or use a predefined mask
var output = d.format('expiresHeaderFormat');

// shortcut for date(d).format(fmt) - 2nd arg format string
var output = date(d, fmt);

// non-truthy input means current date/time
var now = date('');

var d = date('inva/lid/date');
var isValid = d.valid;          // false
var output = d.format();        // 'No Date'

// set language to german
date.lang('de');

// access dateformat masks
date.dateformat.masks.shortDate = ('yyyy.mm.dd');

format patterns

| pattern | interpretation | | :---------- | :------------------------------ | | d | day | | dd | day with leading 0 | | ddd | day of week abbreviated | | dddd | day of week full | | m | month | | mm | month with leading 0 | | mmm | month abbreviated | | mmmm | month full | | yy | year 2 digit | | yyyy | year 4 digit | | h | hours (12) | | hh | hours (12) with leading 0 | | H | hours (24) | | HH | hours (24) with leading 0 | | M | minutes | | MM | minutes with leading 0 | | s | seconds | | ss | seconds with leading 0 | | l | milliseconds 3 digits | | L | milliseconds 2 digits | | t | a or p for am or pm | | tt | am or pm | | T | A or P for am or pm | | TT | AM or PM | | Z | US timezone or GMT-???? | | o | UTC offset e.g. +1000 or -0230 | | S | day suffix e.g. 'nd' for 2 | | W | week in year | | N | day in week | | UTC:fmt | render UTC instead of local |

format masks

| mask name | interpretation | | :-------------------- | :------------------------------ | | default | ddd mmm dd yyyy HH:MM:ss | | shortDate | m/d/yy | | mediumDate | mmm d, yyyy | | longDate | mmmm d, yyyy | | fullDate | dddd, mmmm d, yyyy | | shortTime | h:MM TT | | mediumTime | h:MM:ss TT | | longTime | h:MM:ss TT Z | | isoDate | yyyy-mm-dd | | isoTime | HH:MM:ss | | isoDateTime | yyyy-mm-dd'T'HH:MM:sso | | isoUtcDateTime | UTC:yyyy-mm-dd'T'HH:MM:ss'Z' | | expiresHeaderFormat | ddd, dd mmm yyyy HH:MM:ss Z |

parsing yyyy-mm-dd

ES5 interprets strings matching yyyy-mm-dd as UTC even when running in other timezones.

E.g. 2015-9-15 is assumed to be midnight on that date in the local timezone

But 2015-10-15 is interpreted as midnight on that date in the UTC timezone because the date uses an ISO format and has a 2-digit month. This is problematic e.g. for code parsing unpadded dates passed via JSON.

This module provides a small polyfill to parse yyyy-mm-dd dates as local even in ES5.

credits