Re: [ANN] Chronic-0.1.0
- From: Tom Werner <tom@xxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 8 Sep 2006 06:19:24 +0900
Mat Schaffer wrote:
On 9/7/06, Tom Werner <tom@xxxxxxxxxxxxxxxxxxxxx> wrote:Chronic is a natural language date/time parser written in pure Ruby. See below for the wide variety of formats Chronic will parse.
This is really really awesome. How did you implement stuff like "the
3rd tuesday in January"? I've been wrestling with that concept for
awhile not in a OS X Dashboard clock I made.
-Mat
Chronic uses a compiler approach, so the date is parsed, tokenized, and then run through a list of possible matches. The first matching rule fires off a handler that knows how to deal with that pattern. To handle things like "3rd tuesday in january", it goes something like this:
3rd [ordinal-3]
tuesday [repeater-dayname-tuesday]
in [pointer-future]
january [repeater-monthname-january]
Which matches a pattern that knows to look for the next future January, and beginning with the start of that month, look for the next future Tuesday three times. There are classes that represent each of the possible repeaters (there a lot of them!), and know everything about how to find the next, previous, or this span, and to do offsets. Examine the source code if you're really interested, it shouldn't be too hard to grok.
Tom
--
Tom Werner
Helmets to Hardhats
Software Developer
tom@xxxxxxxxxxxxxxxxxxxxx
www.helmetstohardhats.org
.
- Follow-Ups:
- Re: [ANN] Chronic-0.1.0
- From: Mat Schaffer
- Re: [ANN] Chronic-0.1.0
- From: Nathaniel Brown
- Re: [ANN] Chronic-0.1.0
- References:
- [ANN] Chronic-0.1.0
- From: Tom Werner
- Re: [ANN] Chronic-0.1.0
- From: Mat Schaffer
- [ANN] Chronic-0.1.0
- Prev by Date: Re: Thousands of words on Ruby
- Next by Date: Re: Crashing RubyConf
- Previous by thread: Re: [ANN] Chronic-0.1.0
- Next by thread: Re: [ANN] Chronic-0.1.0
- Index(es):
Relevant Pages
|