Coder Social home page Coder Social logo

chrono's People

Contributors

alexkwolfe avatar benaubin avatar bootseller avatar chaseontheweb avatar denouche avatar gecko655 avatar georgd avatar gimenete avatar gregeinfrank avatar guillegette avatar hendrikjan avatar james-bench avatar jdicarlo-dh avatar jeroenvdb avatar joakimnil avatar jonshaffer avatar larissa avatar liamcain avatar lostfictions avatar matthias-christen avatar mikemikhaylov avatar mvolz avatar penne12 avatar philgooch avatar samin avatar sferadev avatar thymo avatar victor36max avatar wanasit avatar yuichkun 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  avatar  avatar  avatar  avatar

chrono's Issues

Avoid requiring files in the browser minified version

Hi! Your library seems to be exactly what I’m looking for, with one caveat though: the require and eval function calls in the browser minified version. Is there a way to avoid them and only have one fully-featured file?

Add Bower support

Please add a bower.json manifest and make a tag so that Bower can pull a canonical version of your library.

Thanks!

Access moment.

Is there a way to access moment through chrono. Like chrono.moment() ?

Support for hour(s) and minute(s)

Support for hour(s) and minute(s) like for days would be great:

Here are some examples (only the first is supported, yet)

  • 3 days ago (already working)
  • in 3 days
  • 5 minutes ago
  • 1 hour ago
  • 4 hours ago
  • in 5 hours

You see the pattern. Would be great if you could enhance it.

Add brazilian portuguese localization

I'm struggling to add a brazilian portuguese localization to Chrono. I guess the instructions in #27 are pretty outdated, right? How can I do to achieve that nowadays?

Tag new release

There have been 7 commits since the last tag. Could you tag a new release soon? Thanks!

ISO8601 time zone is parsed wrong

Hi,

There seems to be a time zone bug in parsing ISO timestamps:
2015-03-23T12:00:00+00:00 is correctly parsed to 1427112000000 ms since epoch (Mon Mar 23 2015 13:00:00 GMT+0100 (CET)).
2015-03-30T12:00:00+00:00 however, is incorrectly parsed to 1427713200000 ms since epoch (Mon Mar 30 2015 13:00:00 GMT+0200 (CEST)), i.e. one hour earlier than the text indicates.

I guess that the issue has something to do that, by March 30th, my timezone will have shifted from GMT+1 to GMT+2, even though the timestamps indicate the timezone to be used.

Additional data points: if I change the timezone on the timestamp after March 29th, they all seem to be 1 hour wrong. Other dates during DST also seem to have the 1 hour offset.

July 42nd = August 11th, etc

To replicate:
alert(chrono.parseDate("July 42nd"));

This should respond with some kind of error. Instead, it returns an actual date, albeit one not in July.

Doesn't appear to parse ISO local times

chrono.parseDate("2015-07-31T12:00:00")
Date {Wed Jul 15 2015 20:15:00 GMT-0500 (Central Standard Time)} (Date)

If I give it 2016-07-31..., the time is displayed as 20:16:00.

It'd be great if this ISO format was supported, since I'm using a library that expects it. Thanks!

Parsing of UTC time offset

There seems to be a problem with parsing the offset from UTC:

try parsing these dates: Sat, 21 Feb 2015 11:50:48 -0500, 22 Feb 2015 04:12:00 -0000

Chrono parses it as Sat Feb 21 2015 11:50:48 GMT-0800 (PST) should be parsed in EST time

if you try Sat, 21 Feb 2015 11:50:48 -0500 EST it works as expected.

Default to upcoming day of the week

There is perhaps a good reason for this behavior, so forgive me if this is intentional! My thought is that something like Friday should 'assume' [this] Friday, in that I am more likely to refer to an upcoming date than a past date by the day-of-the-week alone. (I think one would be more likely to refer to a past Friday as last Friday, even if it was only two or three days ago.)

I'm looking through the code now to see if I can PR; let me know if I should abandon!

Deprecated moment.js warnings

Deprecation warning: moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779
Error:
  at deprecate node_modules/moment/moment.js:738:42)
  at node_modules/moment/moment.js:2554:37
  at hookCallback (node_modules/moment/moment.js:8:85)
  at Object.<anonymous> (node_modules/moment/moment.js:11:2)
  ...
  at Object.<anonymous> (node_modules/chrono-node/src/parsers/EN/ENISOFormatParser.js:10:14)
  ...
  at Object.<anonymous> (node_modules/chrono-node/src/options.js:1:87)
  ...
  at Object.<anonymous> (node_modules/chrono-node/src/chrono.js:2:33)
  ...

relative date parsing error on '10 days ago'

No clue why yet, but for some reason chrono doesn't like "10 days ago"

> var chrono = require('chrono-node');
undefined
> chrono.parse('10 days ago')
[]
> chrono.parse('12 days ago')
[ { start: 
     { year: 2013,
       month: 9,
       day: 9,
       hour: undefined,
       minute: undefined,
       second: undefined,
       timezoneOffset: undefined,
       dayOfWeek: undefined,
       isCertain: [Function],
       date: [Function] },
    startDate: Wed Oct 09 2013 12:00:00 GMT-0400 (EDT),
    referenceDate: Mon Oct 21 2013 20:41:13 GMT-0400 (EDT),
    index: 0,
    text: '12 days ago',
    concordance: '12 days ago' } ]
> chrono.parse('9 days ago')
[ { start: 
     { year: 2013,
       month: 9,
       day: 12,
       hour: undefined,
       minute: undefined,
       second: undefined,
       timezoneOffset: undefined,
       dayOfWeek: undefined,
       isCertain: [Function],
       date: [Function] },
    startDate: Sat Oct 12 2013 12:00:00 GMT-0400 (EDT),
    referenceDate: Mon Oct 21 2013 20:41:22 GMT-0400 (EDT),
    index: 0,
    text: '9 days ago',
    concordance: '9 days ago' } ]
> chrono.parse('11 days ago')
[ { start: 
     { year: 2013,
       month: 9,
       day: 10,
       hour: undefined,
       minute: undefined,
       second: undefined,
       timezoneOffset: undefined,
       dayOfWeek: undefined,
       isCertain: [Function],
       date: [Function] },
    startDate: Thu Oct 10 2013 12:00:00 GMT-0400 (EDT),
    referenceDate: Mon Oct 21 2013 20:41:26 GMT-0400 (EDT),
    index: 0,
    text: '11 days ago',
    concordance: '11 days ago' } ]

Support for multiple time zones with same name

Hello @wanasit, thank you for the fantastic library! I am using it in a project and am very happy with it.

In the project I am using it for, I would like to be able to handle the case where the parsed time zone is ambiguous. For example, CST can match:

  • Central Standard Time (North America)
  • China Standard Time
  • Central Standard Time (Australia)
  • Central Summer Time (Australia)

At the moment, CST chooses Central Standard Time (North America), but it would be fantastic if it could match more than one and we could choose which one.

Do you think it would be possible to support matching all possible time zones and returning all?

"2013-02-07" recognition?

I found chrono doesn't recognize "2013-02-07", so I just commet out below lines in InternationalStandardParser.js:

      //Impossible Date or Invalid Date
      var date = moment(text, 'YYYY-MM-DD');
      // if(date.format('YYYY-M-D') != text){
      //   return null;
      // } 

Is it really useful for invalid date? Why "2013-02-07" is invalid?

Thanks for the great work. Chrono really helps :)

Time zone is lost while parsing ISO 8601 date

In the below example, I would expect the Z character in the ISO 8601 date to be treated as a time zone offset of zero hours (UTC). It looks like that isn't happening because the timezoneOffset is undefined. As a result, the parsed date is in my local time zone (-4 hours) rather than UTC.

var chrono = require('chrono-node');

var string = '2014-07-07T04:00:00.000Z';
var parsed = chrono.parse(string)[0];

// expected to log "true" but instead logs "false"
console.log(string == parsed.startDate.toISOString());

// expected to log "0" but instead logs "undefined"
console.log(parsed.timezoneOffset);

// expected to log "2014-07-07T04:00:00.000Z" but instead logs "2014-07-07T08:00:00.000Z"
console.log(parsed.startDate.toISOString());

City support

Is it possible to add another Refiner plugin to extract timezone information from city?

Example:

  • 5pm Tokyo17:00 UTC+09:00
  • 5pm Moscow17:00 UTC+04:00

Support for weeks

There should be support for weeks. Some test cases:

Current date: 9th August 2013

  1. 1 week later: 16 August 2013
  2. in 1 week: 16 August 2013
  3. next week: 16 August 2013

Update npm package?

Looks like the version in npm is still from ~ 6 months ago. Mind pushing up some of the latest stable stuff? Loving the changes.

i18n ?

Just a question. Do you know if there is some i18n implementation ?

Day of the week sets start hour to 12:00:00

When trying to parse Wednesday (or any other day) it always sets the time to 12:00:00:

{
  "ref":"2015-09-16T08:17:55.652Z",
  "index":0,
  "text":"Monday",
  "tags":{

  },
  "start":{
    "knownValues":{
      "weekday":1
    },
    "impliedValues":{
      "day":14,
      "month":9,
      "year":2015,
      "hour":12,
      "minute":0,
      "second":0,
      "millisecond":0
    }
  }
}

Is there a way I can either override the impliedValue(s) for hour or shouldn't chrono just give back a range with a start and end date like this:

{
  "ref":"2015-09-16T08:22:48.836Z",
  "index":0,
  "text":"Monday",
  "tags":{
    "ENTimeExpressionParser":true,
    "ENMergeDateAndTimeRefiner":true,
    "":true
  },
  "start":{
    "knownValues":{
      "weekday":1,
      "meridiem":1
    },
    "impliedValues":{
      "day":14,
      "month":9,
      "year":2015,
      "hour":0,
      "minute":0,
      "second":0,
      "millisecond":0
    }
  },
  "end":{
    "knownValues":{
      "weekday":1,
      "meridiem":1
    },
    "impliedValues":{
      "day":14,
      "month":9,
      "year":2015,
      "hour":23,
      "minute":59,
      "second":59,
      "millisecond":0
    }
  }
}

I'd rather not specify the begin and end time explicitly.

Thanks

Using chrono without a browser or node

I'm in need of a JavaScript natural language library for use in a JavaScript for Automation ( AppleScript ) library I'm writing. How could I modify chrono to stop looking for module-related stuff if I'm just including chrono.min.js at the top of the library?

Allow implied past or future

Depending on the context, if today is 2013-12-02, "Thursday" might mean 2013-11-28 (last Thursday) or it might mean 2013-12-05 (next Thursday). It'd be cool if you could tell chrono to prefer past dates instead of future ones, or vice versa.

(As an example, I am using chrono to parse a command line option for downloading old files created before a certain date. So all of the dates that someone gives me will be in the past, never the future.)

Also, see #5.

PS: Thank you for this library, it is awesome!

How to add localization

I tested all date parsers that I could find and chrono it is by far the best. I want to localise it to pt-BR (Brazilian portuguese). I see that there is already some languages supported on the "parsers" folder but I am not sure how to add another language into chrono. I can copy one, translate it and then what? What do I need to do so chrono use the new localization?

Use of chrono within browserify

This line in chrono.js seems to cause problems when used within browserify+node.

if(typeof moment == 'undefined') eval("var moment = require('./moment');");

Any idea why? Because it is "evaled" like that, it ends up hitting the runtime require method instead of the browserify-time eval method and it will fail in assorted ways. Why does that eval need to be used?

Feature request: Support for hours and minutes

Hi,

Have you considered adding support for hours and minutes? Ideally, I'm looking for something that can understand most/all of these formats:

  • Five hours
  • 30 minutes
  • 15min
  • One hour thirty minutes
  • 1:30
  • 1h30m
  • 1,5h

Is this perhaps something that could be built using custom parsers? If so I might take a stab at it.

Thanks for your time!

"DAY of MONTH" doesn't parse correctly

Currently 12th of July at 19:00 incorrectly parses as June 12th 2014 at 7:00pm.

Would it be possible to support this alternative way of declaring a date?

Unexpected behavior when TZ environment variable is defined

When the TZ environment variable is defined, chrono ignores time zone component in the parsed string. In the example below, TZ is set to GMT, so startDate should be "Sat Jun 14 2014 18:27:33 GMT+0000 (GMT)":

$ TZ=GMT node -e "console.log(require('chrono-node').parse('Sat Jun 14 2014 13:27:33 GMT-0500 (CDT)')[0].startDate)"
Sat Jun 14 2014 13:27:33 GMT+0000 (GMT)

License Information

What license is this code released with? I would like to use this in an AGPL application.

Reference date as start date.

The start.month and end.month are correct, however, startDate and endDate are wrong.

Please see the example below:

console.log(chrono.parse('9:00 AM to 5:00 PM, Tuesday, 20 May 2013'));
[ { start:
{ year: 2013,
month: 4,
day: 20,
hour: 9,
minute: 0,
second: 0,
timezoneOffset: undefined,
dayOfWeek: 2,
meridiem: 'am',
isCertain: [Function],
date: [Function],
impliedComponents: [] },
startDate: Thu Sep 26 2013 09:00:00 GMT+1000 (EST),
end:
{ year: 2013,
month: 4,
day: 20,
hour: 17,
minute: 0,
second: 0,
timezoneOffset: undefined,
dayOfWeek: 2,
meridiem: 'am',
isCertain: [Function],
date: [Function] },
endDate: Thu Sep 26 2013 17:00:00 GMT+1000 (EST),
referenceDate: Thu Sep 26 2013 11:35:20 GMT+1000 (EST),
index: 0,
text: '9:00 AM to 5:00 PM, Tuesday, 20 May 2013',
concordance: '9:00 AM to 5:00 PM, Tuesday, 20 May 2013' } ]

Parsing of german date format 30.11.2013

Hi there i like your natural parsing of text lot and i would like to implement an iOS like email parsing to get dates/times out of plaintext mails to create events on mobile phones webOS (http://en.wikipedia.org/wiki/WebOS) .

The problem i see on your testsite: http://wanasit.github.io/pages/chrono/ is that our german date format and weekday names are not parsed correctly.

30.11.2014 should be Sun Nov 30 2014
or
30.11. should be Sat Nov 30 2013 if parsed this year

dateElementOrder:"dmy",formatPatterns:{shortDate:"dd.MM.yyyy"

Could that be implemented ?

I looked around and in the date.js project (http://code.google.com/p/datejs/downloads/list) there is a CultureInfo file (date-de-DE.js) which explains the formats in germany.

Date.CultureInfo={name:"de-DE",englishName:"German (Germany)",nativeName:"Deutsch (Deutschland)",dayNames:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],abbreviatedDayNames:["So","Mo","Di","Mi","Do","Fr","Sa"],shortestDayNames:["So","Mo","Di","Mi","Do","Fr","Sa"],firstLetterDayNames:["S","M","D","M","D","F","S"],monthNames:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],abbreviatedMonthNames:["Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],amDesignator:"",pmDesignator:"",firstDayOfWeek:1,twoDigitYearMax:2029,dateElementOrder:"dmy",formatPatterns:{shortDate:"dd.MM.yyyy",longDate:"dddd, d. MMMM yyyy",shortTime:"HH:mm",longTime:"HH:mm:ss",fullDateTime:"dddd, d. MMMM yyyy HH:mm:ss",sortableDateTime:"yyyy-MM-ddTHH:mm:ss",universalSortableDateTime:"yyyy-MM-dd HH:mm:ssZ",rfc1123:"ddd, dd MMM yyyy HH:mm:ss GMT",monthDay:"dd MMMM",yearMonth:"MMMM yyyy"},regexPatterns:{jan:/^jan(uar)?/i,feb:/^feb(ruar)?/i,mar:/^märz/i,apr:/^apr(il)?/i,may:/^mai/i,jun:/^jun(i)?/i,jul:/^jul(i)?/i,aug:/^aug(ust)?/i,sep:/^sep(t(ember)?)?/i,oct:/^okt(ober)?/i,nov:/^nov(ember)?/i,dec:/^dez(ember)?/i,sun:/^sonntag/i,mon:/^montag/i,tue:/^dienstag/i,wed:/^mittwoch/i,thu:/^donnerstag/i,fri:/^freitag/i,sat:/^samstag/i,future:/^next/i,past:/^last|past|prev(ious)?/i,add:/^(\+|after|from)/i,subtract:/^(\-|before|ago)/i,yesterday:/^yesterday/i,today:/^t(oday)?/i,tomorrow:/^tomorrow/i,now:/^n(ow)?/i,millisecond:/^ms|milli(second)?s?/i,second:/^sec(ond)?s?/i,minute:/^min(ute)?s?/i,hour:/^h(ou)?rs?/i,week:/^w(ee)?k/i,month:/^m(o(nth)?s?)?/i,day:/^d(ays?)?/i,year:/^y((ea)?rs?)?/i,shortMeridian:/^(a|p)/i,longMeridian:/^(a\.?m?\.?|p\.?m?\.?)/i,timezone:/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\s*(\+|\-)\s*\d\d\d\d?)|gmt)/i,ordinalSuffix:/^\s*(st|nd|rd|th)/i,timeContext:/^\s*(\:|a|p)/i},abbreviatedTimeZoneStandard:{GMT:"-000",EST:"-0400",CST:"-0500",MST:"-0600",PST:"-0700"},abbreviatedTimeZoneDST:{GMT:"-000",EDT:"-0500",CDT:"-0600",MDT:"-0700",PDT:"-0800"}};

So you have the nice fulltext parser and they have my language options. Perhaps you can implement this into your project.

Greets from europe

Parsing error "for" vs "in"

When parsing "set a timer for 2 minutes" will fail but "set a timer in 2 minutes" will pass. Any idea why the word "for" vs "in" would cause the parser to give different results?

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.