Date() for humans

Related tags

Date and Time date
Overview

date Build Status Libscore

Date is an english language date parser for node.js and the browser. For examples and demos, see: http://matthewmueller.github.io/date/

Update: date.js now has much better NLP support thanks to @kengz

Installation

On the server or in the browser:

npm install date.js

Standalone:

Standalone is also AMD-compatible

Examples

date('10 minutes from now')
date('in 5 hours')
date('at 5pm')
date('at 12:30')
date('at 23:35')
date('in 2 days')
date('tuesday at 9am')
date('monday at 1:00am')
date('last monday at 1:00am')
date('tomorrow at 3pm')
date('yesterday at 12:30am')
date('5pm tonight')
date('tomorrow at noon')
date('next week tuesday')
date('next week tuesday at 4:30pm')
date('2 weeks from wednesday')
date('tomorrow night at 9')
date('tomorrow afternoon')
date('this morning at 9')
date('at 12:30pm')
date('tomorrow at 9 in the morning')
date('2 years from yesterday at 5pm')
date('last month')
date('2nd of January')
date('1st of March')
date('1 st of March')
date('31st of September 4:00am')
date('1st of January 4:00am')
date('9th of December 4:00am')
date('tomorrow afternoon at 4:30pm 1 month from now')
date('10 seconds ago')
date('1 minute ago')
date('2 hours ago')
date('5 weeks ago')
date('2 months ago')
date('1 year ago')
date('an hour later')
date('2w from wednesday')
date('2nd day of January')
date('two hours later')
date('a fortnight from wednesday')
date('a minute ago')

date('at 12:30')
date('at 12.30')
date('tuesday at 9')
date('tomorrow at 15')

API

date(str, [offset])

Create a Date from a str. You may also supply an optional offset to the starting date. offset defaults to the current date and time.

Tests

To run the tests, you'll need node.js:

npm install
make test

Contributors

 project  : date
 repo age : 2 years, 10 months
 active   : 39 days
 commits  : 87
 files    : 17
 authors  :
    27  Matt Mueller       31.0%
    12  Bulkan Evcimen     13.8%
     8  kengz              9.2%
     3  Eero Norri         3.4%
     2  thomas             2.3%
     2  Patrick Stadler    2.3%
     1  Christopher Blum   1.1%
     1  Federico Rampazzo  1.1%
     1  Timothy Cyrus      1.1%
     1  chencheng          1.1%
     1  HipsterBrown       1.1%
     1  Jimmy Gaussen      1.1%

License

(The MIT License)

Copyright (c) 2013 Matt Mueller mailto:[email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • "at X in the morning" defaults to 8am, rather than Xam

    Including morning after the time number overrides to 8am.

    Examples: date("tomorrow morning") // tomorrow morning at 8am correct-ish date("tomorrow morning at 9") // tomorrow morning at 9am correct date("tomorrow at 9 in the morning") // tomorrow morning at 8am wrong

    opened by catdad 9
  • NLP fix #2: arithmetics support, complete CFG features (suppressed now)

    NLP fix #2: arithmetics support, complete CFG features (suppressed now)

    This fixes issues #70 , #62 , #21

    I've removed all lodash dependencies, and wrote my own under subdash.

    Also I've finished the CFG implementation, which I call the Human Language for Time. I plan to attach the mathematical proof on the arithmetics and theories behind it soon.

    This PR doesn't fix as many problems since there's still several small but pesky issues to resolve, which basically are the inconsistencies between my CFG and the original datejs.

    For example, 'tomorrow' will be treated as the next day, defaulted to 9am. Also, I have to implement leap year, and proper carries for days across different months, as they have different number of days.

    That's it for now!

    opened by kengz 6
  • NLP-time implementation: language normalization

    NLP-time implementation: language normalization

    This is first of the series of coming NLP-based improvements. This implements a basic normalization module to process string tokens, and map them onto canonical words aka 'lemma', before parsing.

    I've added lodash as a requirement. You may wish to add it when publishing the demo site too. There's a list of Issues under work to keep track of next issues to fix. You may wish to update the changelog beneath after approving pr.

    Issues fixed: #66, #64, #28, #16, #15, #11, #4

    opened by kengz 6
  • Add spm support

    Add spm support

    A nicer package manager: http://spmjs.io Documentation: http://spmjs.io/documentation

    http://spmjs.io/package/date


    It is a package manager based on Sea.js which is a popular module loader in China.

    spmjs focus in browser side. We supply a complete lifecycle managment of package by using spm.

    If you need ownership of date in spmjs, I can add it for your account after signing in http://spmjs.io.

    opened by sorrycc 4
  • Error using standalone file in dist

    Error using standalone file in dist

    When using https://github.com/matthewmueller/date/blob/master/dist/date.js directly in the browser I get the following error:

    date.js:18 Uncaught Error: Failed to require "./norm" from "date/lib/parser.js"
        at require (date.js:18)
        at localRequire (date.js:171)
        at date.min.js:980
        at require (date.js:35)
        at localRequire (date.js:171)
        at date.min.js:707
        at require (date.js:35)
        at date.min.js:1633
        at date.min.js:1634
    

    That file at the previous commit sha (https://github.com/matthewmueller/date/blob/8fe7afbfb20d72e36f0a7864bd71bd1598401880/dist/date.js) does not have the error and works fine in the browser.

    opened by matthewhadley 3
  • drop support for old node versions

    drop support for old node versions

    Since LTS has finished for node versions older than 4 there's not really any point in still supporting them and one of the mocha deps doesn't work with older versions of node as it uses const in strict mode.

    For example the last build.

    /home/travis/build/matthewmueller/date/node_modules/mocha/node_modules/supports-color/index.js:2
    const os = require('os');
    ^^^^^
    SyntaxError: Use of const in strict mode.
        at exports.runInThisContext (vm.js:73:16)
        at Module._compile (module.js:443:25)
        at Object.Module._extensions..js (module.js:478:10)
        at Module.load (module.js:355:32)
        at Function.Module._load (module.js:310:12)
        at Module.require (module.js:365:17)
        at require (module.js:384:17)
        at Object.<anonymous> (/home/travis/build/matthewmueller/date/node_modules/mocha/lib/reporters/base.js:11:46)
        at Module._compile (module.js:460:26)
        at Object.Module._extensions..js (module.js:478:10)
    make: *** [test] Error 1
    
    opened by OmgImAlexis 3
  • Improvement regarding unparsable strings

    Improvement regarding unparsable strings

    Hi Matthew

    I made this improvement because that way it seems to make more sense to me.

    • Unparsable strings return the current date instead of tomorrow.
    • Better prediction if parsed date is close to now (same minute). If it's 10:24 and the string to parse is "10:24", the result will be the current date, not tomorrow.

    Great work by the way!

    PS: My changes are only on one line, the rest is the result of running make dist && make dist-minify against current master. Tests pass. I'll dive into the i18n subject soon.

    opened by pstadler 3
  • started removing lodash to bring down the build size

    started removing lodash to bring down the build size

    Unfortunately including some of lodash's iterators makes the build size jump up. The base-iterator (which is what most these methods depend on) is 52kb unminified.

    Not a huge deal since it's still relatively small, but I don't like when a dependency that doesn't do all that much has a larger weight than the library itself ;-).

    This is an effort to remove lodash from the build. Most were easily converted to ES5 and below functions, but the remaining are a little trickier:

    • [ ] findKey
    • [ ] partition

    /cc @kengz

    opened by matthewmueller 2
  • Add no extra day with months in the past

    Add no extra day with months in the past

    Context: When trying to parse a future date with a month, like today is "20th of November" and the future date being parsed is "9th of December". The returned date from date.js would be off by one, i.e. a Date object for the 8th of December.

    Solution: I added a test for '9th of December 4:00am' and got the same bug I was running into in my own app. To fix this issue, I modified parser.nextTime to look for a match with the rMonths regex and not add a day to the date.

    I hope this makes sense. I appreciate all the work that went into making this awesome library. Thanks for considering this PR.

    opened by HipsterBrown 2
  • Fix for issue 36

    Fix for issue 36

    I feel they're might be a better way of doing this. Something like to peek back one token when we find a numner see if the previous token is the string at.

    opened by bulkan 2
  • Doesn't support of " eg "Second Monday of July"">

    Doesn't support " of " eg "Second Monday of July"

    This is sort of similar to issue 23.

    nth = first, second, third, fourth, last day = (mon)day, (tue)sday, (wed)nesday, (thu)rsday, (fri)day, (sat)urday, (sun)day

    opened by colinj 2
  • Add TypeScript support

    Add TypeScript support

    It would be nice if there was TypeScript support for this library because a lot of project use TypeScript as their main language, and in some of those project, they depend on date.js for things like date time displaying and such. So I would really like to see this library getting add to DefinitelyTyped

    opened by QuanMCPC 0
  • Unofficial date.js has new v4.0.0 - possible malware

    Unofficial date.js has new v4.0.0 - possible malware

    The official package on npm is https://www.npmjs.com/package/date.js, on 0.3.3

    The unofficial package on npm is https://www.npmjs.com/package/@akepinski/date.js but that has version 4.0.0 - I can see from [History.md] that 0.3.3 was the last release.

    Does a version 4.0.0 exist? If not it would be worth taking down the https://www.npmjs.com/package/@akepinski/date.js.

    opened by mikemaccana 0
  • Why are you returning a default date when the supplied input is invalid?

    Why are you returning a default date when the supplied input is invalid?

    This is such a basic piece of functionality and it makes this package unusable in cases where input must be validated. So what is the thinking here and why has date.js been created in a way that faulty input like this:

    date("blah")
    

    actually returns a valid date?

    In use cases where an end user is trying to run a search for a time/date range it isn't desired to have every failed parsing default to now/today.

    So why is it built this way and why is there no configuration option to turn that off? If a bad date string is provided I wouldn't personally want any value returned.

    It's very easy for consumers of date.js to do this if they always want a date value:

    function parseDate(val) {
      return date(val) || date("now")
    }
    

    But there isn't a way for us to ensure that invalid date values are rejected.

    Can this be fixed?

    opened by arizonatribe 0
Create Persian Calendar as html helper with tag builder c# , and convert selected persian date to gregorian date

Persian-Calendar Use JS,Html,CSS,C# White theme for Persian Calendar , easy to use. Create Persian Calendar as html helper. Use Tag builder in c# for

Tareq Awwad 4 Feb 28, 2022
A date picker web component, and spiritual successor to duet date picker

<date-picker> A date picker web component, based on duet date picker, except authored with Lit and using shadow DOM. This is a work in progress. Todo:

Nick Williams 25 Aug 3, 2022
⏰ Day.js 2KB immutable date-time library alternative to Moment.js with the same modern API

English | 简体中文 | 日本語 | Português Brasileiro | 한국어 | Español (España) | Русский Fast 2kB alternative to Moment.js with the same modern API Day.js is a

null 41.7k Dec 28, 2022
⏳ Modern JavaScript date utility library ⌛️

date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js. ?? Documentation

date-fns 30.6k Dec 29, 2022
Reusable date picker component for React

React DayPicker DayPicker is a reusable date picker component for React. $ npm install react-day-picker@next Beta version ⚠️ This branch is for the ne

Giampaolo Bellavite 4.8k Dec 28, 2022
🕑 js-joda is an immutable date and time library for JavaScript.

js-joda is an immutable date and time library for JavaScript. It provides a simple, domain-driven and clean API based on the ISO8601 calendar.

null 1.5k Dec 27, 2022
DEPRECATED: Timezone-enabled JavaScript Date object. Uses Olson zoneinfo files for timezone data.

TimezoneJS.Date A timezone-enabled, drop-in replacement for the stock JavaScript Date. The timezoneJS.Date object is API-compatible with JS Date, with

Matthew Eernisse 830 Nov 20, 2022
:clock8: :hourglass: timeago.js is a tiny(2.0 kb) library used to format date with `*** time ago` statement.

timeago.js timeago.js is a nano library(less than 2 kb) used to format datetime with *** time ago statement. eg: '3 hours ago'. i18n supported. Time a

hustcc 4.9k Jan 4, 2023
Lightweight and simple JS date formatting and parsing

fecha Lightweight date formatting and parsing (~2KB). Meant to replace parsing and formatting functionality of moment.js. NPM npm install fecha --save

Taylor Hakes 2k Jan 5, 2023
A lightweight, locale aware formatter for strings containing unicode date tokens.

Date Token Format A lightweight (~2kB), locale aware formatter for strings containing unicode date tokens. Usage Install the package using: yarn add d

Donovan Hutchinson 1 Dec 24, 2021
CalendarPickerJS - A minimalistic and modern date-picker component/library 🗓️👨🏽‍💻 Written in Vanilla JS

CalendarPickerJS The simple and pretty way to let a user select a day! Supports all major browser. Entirely written in Vanilla JavaScript with no depe

Mathias Picker 15 Dec 6, 2022
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API

English | 简体中文 | 日本語 | Português Brasileiro | 한국어 | Español (España) | Русский Fast 2kB alternative to Moment.js with the same modern API Day.js is a

null 41.7k Dec 28, 2022
Nepali Date Picker jQuery Plugin 🇳🇵

Nepali Date Picker Nepali Date Picker jQuery Plugin for everyone. ???? Installation npm install nepali-date-picker Demo and Documentation https://leap

Leapfrog Technology 70 Sep 29, 2022
React Native Week Month Date Picker

React Native Week Month Date Picker Date picker with a week and month view Installation npm install react-native-week-month-date-picker Dependencies T

Noona 119 Dec 27, 2022
Easy to get a date.

date2data 테이블에 날짜별 데이터 넣을 때마다 새로 객체 만들어서 작업하기가 매우 귀찮아서 만들었다. moment.js를 쓰기에는 구현하고자 하는 내용이 너무 가벼웠음 Install npm i date2data Usage import {getMonthlyDate

Duho Kim 3 Apr 12, 2022
This library provide a fast and easy way to work with date.

Calendar.js Calendar.js provide a fast way to work with dates when you don't wanna deal with hours, minute, second and so on. It means that Calendar.j

ActuallyNotaDev 3 Apr 27, 2022
A tiny and fast zero-dependency date-picker built with vanilla Javascript and CSS.

A tiny zero-dependency and framework-agnostic date picker that is incredibly easy to use! Compatible with any web UI framework, vanilla JS projects, and even HTML-only projects!

Nezar 1 Jan 22, 2021
Duet Date Picker is an open source version of Duet Design System’s accessible date picker. Try live example at https://duetds.github.io/date-picker/

Duet Date Picker Duet Date Picker is an open source version of Duet Design System’s accessible date picker. Duet Date Picker can be implemented and us

Duet Design System 1.6k Jan 6, 2023
Nepali Multi Date Picker for jQuery. Supports both single date selections and multiple date selection.

Nepali Multi Date Picker A simple yet powerful date picker based in Nepali calendar. Supports both single date selections and multiple date selection.

Sanil Shakya 4 May 23, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022