GithubHelp home page GithubHelp logo

date's Introduction

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.

date's People

Contributors

bulkan avatar framp avatar hipsterbrown avatar kengz avatar matthewmueller avatar nettofarah avatar nmussy avatar norri avatar omgimalexis avatar pstadler avatar sorrycc avatar tcyrus avatar tholum avatar tiff avatar tkreis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

date's Issues

Demo clicks broken in FireFox

Win7, FF24 & Aurora28.0a2
Typing the text box works as intended, but clicking on the pre-rolled examples below causes undefined & a freeze up.
Works fine in Chrome Beta & IE10 on same machine.
TIA

Support for date-specific times

I would love for this library to support tokens that calculate the time. To be concrete, it would be brilliant if I could, for example, get the sunrise time for a particular date, or the sunset time (e.g. 'next week monday at sunrise'). This depends on a) the date and b) the location. (See also https://github.com/mourner/suncalc) Another example could be 'wakeuptime' that's set to 7:00 during the week and 10:00 in the weekends.

I can imagine something along the lines of registering a token (e.g. 'sunset') with the parser with a callback function that gets passed the determined date and returns the appropriate time.

Easy example (registering 'midnight' as a token):

date.register('midnight', function(d) { return d.setHours(0, 0, 0) });

I know 'midnight' already exists, but it's just an example. This feature could also make 'evening', 'night', and so on more dynamic and user customizable.

Thanks.

Liscense

I don't see a license of any sort attached to this. Would make it easier to use on projects without worry.

Support for before/after

As a follow up to issue #54, I would like to request relative times to be added. This library would become part of an automation system where I would like to schedule actions based on sunrise and sunset times, but with an offset. Examples would be:

10 minutes after sunset

or

next monday 1 hour before sunrise 

So, 'sunrise' and 'sunset' would be calculated as specified in issue #54. This issue would probably only be needed if #54 was implemented.

Thanks again!

Abbreviations

Such as;
1m for 1 month, or 3w for 3 weeks, etc.
It would be great.

favour current day (optionally?)

tough call for this I guess, if you enter something like "1pm" I guess it's ambiguous, for my cases favouring the recently-passed 1pm would be better than the next, right now we'd have to use "last 1pm" which is a little awkward haha. Anyway let me know what you think or if you have any ideas

Support for non-relative date-time strings

It would be useful if this library could also parse non-relative strings. I was rather perplexed to find:

> d("September 11, 2014");
> Fri Sep 12 2014 11:45:01 GMT+1000 (EST)

I know the plain old Date constructor will handle that, but it'd be nice not to have to worry about whether a date is relative or not and still have the other natural-language advantages this library has.

Fun change - support overmorrow and ereyesterday!

This is not an issue or bug, but it might be fun to support the (sadly) no longer used English words "overmorrow" (the day after tomorrow) and "ereyesterday" (the day before yesterday).

Other languages have words for this, e.g. übermorgen and vorgestern in German, so it might be useful (especially if you add multilanguage support in the future?)

They can also be used to mean things like "the day after the day after tomorrow" : overovermorrow and "the day before the day before yesterday" : ereereyesterday.

As I said, more for a bit of fun rather than an issue with this very useful library!

holidays?

Could be cool to use holidays as an anchor: "I'll be back in the office tuesday after thanksgiving"

Bonus points: combine with #32 and do something like "I'll be gone thanksgiving weekend" ==> Thurs Nov 28 - Sun Dec 1

"Tomorrow"

Seems odd to me that date supports "next week tuesday", but not other day-only-type dates, like "Tomorrow." In my ideal world, this would use some natural UX like date pickers in calendars, where it automatically assumes "This time tomorrow." Would also +1 the other ticket suggestions (like being able to return null on no-match).

Thanks for such a great lib!

Support of EDTF?

Is there any interest in extending the date representation used to support EDTF?

As far as I can see there is nothing in the date representation to indicate that any given date represents an approximate date/time. It would be great to retain this aspect of parsed date/time strings.

For example parsing a date like "Tomorrow afternoon" is useful, however to then output this date again without distorting meaning we need to know that the 2pm part of the resulting date object is inferred and approximate.

Making a guess at "tomorrow at 11"

When you enter at a time without specifying AM or PM or something to frame that time (e.g. morning), it ignores the time value.

tomorrow morning at 11
tomorrow at 11am
tomorrow at 11:00
tomorrow at 11

Of those 4 examples, the first 3 give the same result, the last one ignores the time.

I would have thought presuming someone is using a 24 hour clock format is the best way to handle this, so tomorrow at 11 always defaults to 11am?

Doesn't recognize "next <month>"

For example, "next july 1" or "next july". Neither work. I know I use this type of relative date notation often in conversation.

"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

Midnight

I see that noon was supported, but not midnight. Great work by the way! 👍

test fails at certain times of the day

Need to be more explicit with this test case:

describe('parse context if its a string (fixes: #38)', function () {
  it('string context', function () {
    var today = new Date();
    var date = parse('today at 11', "yesterday");
    assert(d(date) == d(today));
    assert('11:00:00' == t(date));
  });
});

"3.99" is interpreted as 4.39am

var date = require('date.js'); console.log(date('3.99'));

This gives the output Wed Jan 06 2016 04:39:00 GMT+0530 (India Standard Time)

Shouldn't such strings indicate invalid time? What do you think?

Timezone question

Hi,

Have you considered adding timezone support e.g:in 30 minutes EEST ?
This would make it really nice.

Thanks!

same results for "ago" and "from now"

  console.log(date('50 minutes ago'));
  console.log(date('50 minutes from now'));

Tue Feb 04 2014 19:47:44 GMT-0800 (PST)
Tue Feb 04 2014 19:47:44 GMT-0800 (PST)

going to use this for a badass log query language :D

Add context extensions.

Consider setting up beginning and end date for tasks

Start: Next Monday
End: Two weeks from Start

and start value to take from context.

2 hours work but not 'two' hours

Hi,
There should be a mapping of 2 with the word two so that it recognizes when someone types two hours from now, and extending it to 0 to 60

Thanks,
Fakhruddin

tonight at 9:30

tonight at 9 parses correctly to 09:00PM
add the minutes it goes cray cray, tonight at 9:30 parses to 09:30AM

return null if can't parse a date

by default, date appears to return the new Date() if it couldn't make sense of the input.
this isn't really ideal.
it's pretty easy to do

var d = date(string) || new Date()

Otherwise, there isn't an easy way to tell if it's a valid time or not.

i18n?

First of all - good job on the plugin.

Any plans to allow easy translating to different languages and switching between them?

Regards

Crashes when entering non-english characters

Trying to enter Cyrillic into the input box causes the JS/page to become un-responsive.

For example trying to enter завтра will crash after the first two characters are entered.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.