Package Exports
- human-date
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (human-date) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
human-date 
Making dates and times readable for humans. Plus a bunch of other date related goodies.
Quick Start
Install:
npm install human-date --saveUsage:
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")
// 270 days, 22 hours, 27 minutes, 55 seconds from now
hdate.monthName("8/16/2015")
// AugustMethods
.prettyPrint(datestring or jsdate or numseconds)
Arguments:
- datestring
stringthat can be parsed as a date (Eg."8/16/1987") - jsdate
objectwhich is a javascript Date (Eg.new Date("8/16/1987")) - numseconds
integerseconds to or from the current time (Eg.-32)
Returns:
stringrepresenting 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.relativeTime(datestring or jsdate or numseconds, [options])
Arguments:
- datestring
stringthat can be parsed as a date (Eg."8/16/1987") - jsdate
objectwhich is a javascript Date (Eg.new Date("8/16/1987")) - numseconds
integerseconds to or from the current time (Eg.-32) - options: object with the following keys
- futureSuffix
stringdefault:"from now" - pastSuffix
stringdefault:"from now" - returnObject
boolean: default:false
- futureSuffix
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 96 days 21 hours 47 minutes 2 seconds ago
hdate.relativeTime(new Date("8-16-1987"))
// 27 years 96 days 21 hours 47 minutes 2 seconds ago
hdate.relativeTime(new Date("8-16-1987"), {returnObject: true})
// { seconds: 31, minutes: 5, hours: 4, days: 101, years: 27, past: true }.monthName(datestring or jsdate or monthnum)
Arguments:
- datestring
stringthat can be parsed as a date (Eg."8/16/1987") - jsdate
objectwhich is a javascript Date (Eg.new Date("8/16/1987")) - monthnum
integerthe month number, not 0-indexed (Eg.12)
Returns:
string
Examples:
hdate.getHumanMonth(8)
// August
hdate.getHumanMonth("8-16-1987")
// August
hdate.getHumanMonth(new Date("8-16-1987"))
// August.startOfDay(datestring or jsdate)
Arguments:
- datestring
stringthat can be parsed as a date (Eg."8/16/1987") - jsdate
objectwhich is a javascript Date (Eg.new Date("8/16/1987")) - epochtime
integermilliseconds from the epoch (Eg.1416283449392)
Returns:
objectNative Date object set to the beginning of the given day
Examples:
hdate.startOfDay("8-16-1987")
// Mon Aug 10 1987 00:00:00 GMT-0700 (PDT)
hdate.startOfDay(new Date("8-16-1987"))
// Mon Aug 10 1987 00:00:00 GMT-0700 (PDT)
hdate.startOfDay(1416583449392)
// Fri Nov 21 2014 00:00:00 GMT-0800.startOfWeek(datestring or jsdate)
Arguments:
- datestring
stringthat can be parsed as a date (Eg."8/16/1987") - jsdate
objectwhich is a javascript Date (Eg.new Date("8/16/1987")) - epochtime
integermilliseconds from the epoch (Eg.1416283449392)
Returns:
objectNative Date object set to the beginning of the given week
Examples:
hdate.startOfWeek("8-16-1987")
// Mon Aug 10 1987 00:00:00 GMT-0700 (PDT)
hdate.startOfWeek(new Date("8-16-1987"))
// Mon Aug 10 1987 00:00:00 GMT-0700 (PDT)
hdate.startOfWeek(1416283449392)
// Mon Nov 17 2014 00:00:00 GMT-0800 (PST).startOfMonth(datestring or jsdate)
Arguments:
- datestring
stringthat can be parsed as a date (Eg."8/16/1987") - jsdate
objectwhich is a javascript Date (Eg.new Date("8/16/1987")) - epochtime
integermilliseconds from the epoch (Eg.1416283449392)
Returns:
objectNative Date object set to the beginning of the given month
Examples:
hdate.startOfMonth(new Date("8-16-1987"))
// Sat Aug 01 1987 00:00:00 GMT-0700 (PDT)
hdate.startOfMonth("8-16-1987")
// Sat Aug 01 1987 00:00:00 GMT-0700 (PDT)
hdate.startOfMonth(1416283449392)
// Sat Nov 01 2014 00:00:00 GMT-0700 (PDT).startOfYear(datestring or jsdate)
Arguments:
- datestring
stringthat can be parsed as a date (Eg."8/16/1987") - jsdate
objectwhich is a javascript Date (Eg.new Date("8/16/1987")) - epochtime
integermilliseconds from the epoch (Eg.1416283449392)
Returns:
objectNative Date object set to the beginning of the given year
Examples:
hdate.startOfYear(new Date("8-16-1987"))
// Thu Jan 01 1987 00:00:00 GMT-0800 (PST)
hdate.startOfYear("8-16-1987")
// Thu Jan 01 1987 00:00:00 GMT-0800 (PST)
hdate.startOfYear(1416283449392)
// Wed Jan 01 2014 00:00:00 GMT-0800 (PST).isLeapYear(datestring or jsdate)
Arguments:
- datestring
stringthat can be parsed as a date (Eg."8/16/1987") - jsdate
objectwhich is a javascript Date (Eg.new Date("8/16/1987")) - epochtime
integermilliseconds from the epoch (Eg.1416283449392)
Returns:
boolean: wether or not the given date is in a leap year
Examples:
hdate.isLeapYear("8/16/1987")
// false
hdate.isLeapYear("8/16/1988")
// true
hdate.isLeapYear(1416283449392)
// falseTodos
- Add various options and helpers (prefixes, suffixes, etc...)
- Add time information to prettyPrint (August 16th, 2014 at 5:00pm PST)
- Support different locales.
- Proper testing framework.
Contributing
Forks and pull requests are most welcomed.
Please add any methods to test.js and run npm test to make sure nothing has broken before submitting a pull request.