[RFC PATCH 0/2] natural language date range search

Jani Nikula jani at nikula.org
Sat Feb 25 11:53:27 PST 2012


On Sat, 25 Feb 2012 17:05:44 +0200, Tomi Ollila <tomi.ollila at iki.fi> wrote:
> On Mon, 20 Feb 2012 00:55:50 +0200, Jani Nikula <jani at nikula.org> wrote:
> > Hi all, these patches add support for natural language date range search
> > of the form date:since..until, where since and until can be fairly free
> > form date/time expressions in English.
> > 
> > Examples:
> > 
> > date:two-days..yesterday (all mail in the two days before today)
> > date:12h.. (all mail since 12 hrs ago)
> > date:november..november (all mail in previous november)
> > date:2011.. (all mail since the beginning of 2011)
> > date:last-week..this-week (all mail over last and current week)
> > date:5/10/2011-12:34:55..10pm_2012-01-14
> > 
> > Plus plenty more and combinations of the above.
> 
> Pretty c00l, the above and the code.

Thanks! :)

> > 
> > The repository for the date/time parser with a command line tool is at
> > [1], and there's a README [2] with a bunch of details too.
> 
> By seeing the thoughts thrown in IRC there seems to be plenty if things
> to resolve until something like this is going to be available in stock
> notmuch. In the meanwhile I provide some ideas into the soup; maybe
> our collective mind can have some use of this.
> 
> 
> Q: Could 'date:timestr' be converted to 'date:timestr..timestr' ?

AFAICT this would require the custom query parser.

> In this idea -<timestr> means relative time and <timestr> absolute
> time. The the time string consists of number and letter and assume
> the above suggestion for date:timestr (<- == date:timestr..timestr)
> Letters are s seconds  h hours  d days  w weeks  m months (more
> useful than for minutes) and  y years.

I'll put it bluntly: show me the code! ;)

I'll comment below how your examples can be expressed with working code
in this series, just for comparison, and to show what can be done with
this.

> date:-2000s     email exactly 2000 seconds ago (not very useful)

date:2000s..2000s

> date:-2000s..   since 2000 secs in past

date:2000s..
date:1000s500s500s.. (all accumulated)

> date:..-2000s   up to 2000 secs in past

date:..2000s

> date:3600s      email with date 01:00 -- today if (local) time is
>                 more than 1am. yesterday if less. If there is not
>                 mail with date exactly that then no email matches
>                 (i.e. same usefullness applies as above)
> date:3600s..    email with date since 01:00 (same today/yesterday
>                 resolvation like above)

Okay, there's no easy way to express it like this.

> date:12h..      since noon, either yesterday (time less than 12pm)
>                 or today (currently afternoon)

date:noon.. 
date:12pm..
date:12:00..
date:12:00:00..

(I think in my implementation currently refers to today regardless of
current time; there's a REVISIT comment about that. Not difficult to
fix.)

> date:12h        like above, but since 12:00 to 13:00
> date:12h..12h   ditto

For example date:noon..13:00

> date:6pm..      since 18:00 either today (current time > 6pm) or yesterday

The same.

> date:-12h..     since 12 hours ago

date:12h..

> date:-12h       since 12 hours ago to 11 hours ago

date:12h..11hrs

> date:-1h        last hour

date:1h..

> date:0h         today 12am - 01am 

For example date:00:00..01am

> date:-0d        today

To cover the whole day, date:today..today

> date:-0d..      ditto

date:0d..0d (from zero days ago to zero days ago, rounded accordingly)

In fact, in my implementation "today" is simply the same as 0 days ago.

> date:-1d        yesterday

date:yesterday..yesterday

> date:-1d..      yesterday & today

date:1d..

> date:-2d        2 days ago

For example date:two-days..2d

> date:-2d..      day before yesterday, yesterday & today

date:2d..

> date:0d         last sunday (if today sunday, today (so being consistent))

date:sunday..sunday (if today sunday, one week ago)

> date:1d         last monday (like above)
> date:6d         last saturday (like above)
> date:7d         last sunday (same as 0d)

Just weekday names.

> date:-0w        current week (does week start sun or mon)

For example date:0w...this-week

> date:-1w        last week (same as above)

For example date:last-week..1w

> date:-2w..      since beginning of 2 weeks ago

date:2w..

> date:1w         (ISO) week number ? current week it this is same week  
>                 number. this week last year if current week is less.
> date:1w..	since the above date resolved.

N/A, my parser does not support week numbers.

> date:11m	last november (m is more useable in month than in minute)

date:november..november, or by specifying the year date:2011-11..2011-11

> date:11m..      since last november

date:november..

> date:-11m       whole month 11 months ago

date:11mon..11M (lower case m is minutes)

> date:-11m..	since beginning of 11 months ago

date:11months..

> date:70y	year 1970

date:1970..1970

> date:69y        year 2069

date:2069..2069

> date:0y         year 2000

date:2000..2000

> date:99y..      since beginning of 1999

date:2000..

(It's possible to use 2-digit years in combination with some more
context, e.g. 1.1.99)

> date:-0y        this year

date:this-year..this-year

> date:-1y        last year

date:last-year..1y

> This is incomplete, but pretty easy to use format. Letters from English
> language. What is missing letter for month (M?) ar mday (D?). All thought
> as in local time...
> 
> ... strings could be concatenated: for example: -3d11h (meaning second
> always absolute). Need to be in granularity order (or something). Timezone
> could be added (pst, utc, eest, z -- and even like -11 or +4
> ( -2y11m+7 meaning year 2010 november in timezone utc + 7 (this year: 2012))

My implementation allows adding any number of relative dates, and they
are accumulated, but only towards past. Relative date can be combined
with absolute date, as long as the same absolute unit is not specified
twice (can't say "january february", but "january one month" is one
month back from january).

(With a couple of small further patches still in my local tree) you can
specify time zone for all of the above.


BR,
Jani.



> 
> Of course range date:-2d..-5h would be supported.
> 
> > BR,
> > Jani.
> > 
> > 
> > [1] https://gitorious.org/parse-time-string/parse-time-string
> > [2] https://gitorious.org/parse-time-string/parse-time-string/blobs/master/README
> > 
> 
> Tomi
> 


More information about the notmuch mailing list