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

human-date

v1.4.0

Published

Return dates and times in easily readable formats

Downloads

14,014

Readme

human-date NPM Version wercker continuous integration testing

Making dates and times readable for humans.

Quick Start

Install:
npm install human-date --save
Usage:
var hdate = require('human-date')

hdate.prettyPrint("8/16/1987")
// August 16th, 1987

hdate.relativeTime(60 * 60 * 24 * 2 * -1)
// 2 days ago

hdate.relativeTime("8/16/2015")
// 125 days from now

hdate.monthName("8/16/2015")
// August

Methods

.prettyPrint(datestring or jsdate or numseconds, [options])

Arguments:
  • datestring string that can be parsed as a date (Eg. "8/16/1987")
  • jsdate object which is a javascript Date (Eg. new Date("8/16/1987"))
  • numseconds integer seconds to or from the current time (Eg. -32)
  • options: object with the following keys
    • showTime boolean: default: false
Returns:
  • string representing the date. (Eg. "August 16th, 1987")
Examples:
hdate.prettyPrint('8-16-1987')
// August 16th, 1987

hdate.prettyPrint(new Date('8-16-1987'))
// August 16th, 1987

hdate.prettyPrint(-6400)
// November 17th, 2014 (at the time)

hdate.prettyPrint(new Date(1416448704578), { showTime: true })
// November 19th, 2014 at 5:58 pm

.relativeTime(datestring or jsdate or numseconds, [options])

Arguments:
  • datestring string that can be parsed as a date (Eg. "8/16/1987")
  • jsdate object which is a javascript Date (Eg. new Date("8/16/1987"))
  • numseconds integer seconds to or from the current time (Eg. -32)
  • options: object with the following keys
    • futureSuffix string default: "from now"
    • pastSuffix string default: "from now"
    • presentText string default: "now"
    • returnObject boolean: default: false
    • allUnits boolean: default: false
Returns:

Depending on the option returnObject you will get a string or an object:

  • default string "27 years 96 days 21 hours 47 minutes 2 seconds ago"
  • object { seconds: 31, hours: 4, days: 101, years: 27, past: true }
Examples:
hdate.relativeTime(4)
// 4 seconds from now

hdate.relativeTime(4, {futureSuffix: "in the future"})
// 4 seconds in the future

hdate.relativeTime("8-16-1987")
// 27 years ago

hdate.relativeTime(new Date("8-16-1987"))
// 27 years ago

hdate.relativeTime(new Date("8-16-1987"), {returnObject: true})
// { seconds: 31, minutes: 5, hours: 4, days: 101, years: 27, past: true }

hdate.relativeTime(75, {allUnits: true})
// 1 minute, 15 seconds from now

.monthName(datestring or jsdate or monthnum)

Arguments:
  • datestring string that can be parsed as a date (Eg. "8/16/1987")
  • jsdate object which is a javascript Date (Eg. new Date("8/16/1987"))
  • monthnum integer the month number, not 0-indexed (Eg. 12)
Returns:
  • string
Examples:
hdate.monthName(8)
// August

hdate.monthName("8-16-1987")
// August

hdate.monthName(new Date("8-16-1987"))
// August

.toUTC(datestring or jsdate or monthnum)

Arguments:
  • datestring string that can be parsed as a date (Eg. "8/16/1987")
  • jsdate object which is a javascript Date (Eg. new Date("8/16/1987"))
  • epochtime integer time since epoch, in milliseconds (Eg. 1416451096261)
Returns:
  • object native Date object modified to UTC timezone.
Examples:
hdate.toUTC(1000000000000)
// '2001-09-09T08:46:40.000Z'

hdate.toUTC(1000000000000).getFullYear()
// 2001

hdate.toUTC("8-16-1987")
// Sun Aug 16 1987 07:00:00 GMT-0700 (PDT)

hdate.toUTC(new Date("8-16-1987"))
// Sun Aug 16 1987 07:00:00 GMT-0700 (PDT)

hdate.toUTC(new Date("8-16-1987")).toISOString()
// 1987-08-16T14:00:00.000Z

Todos

  • Add various options (prefixes, etc...)
  • Support different locales.

Contributing

Forks and pull requests are most welcomed.

Please add any methods to test.js and run npm test before sending a pull request.

MIT license

Copyright (c) 2014-2016, Montana Flynn (http://anonfunction.com/)