chronic 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +76 -0
- data/LICENSE +21 -0
- data/README.md +165 -0
- data/Rakefile +145 -18
- data/benchmark/benchmark.rb +13 -0
- data/chronic.gemspec +85 -0
- data/lib/chronic.rb +21 -19
- data/lib/chronic/chronic.rb +59 -49
- data/lib/chronic/grabber.rb +2 -2
- data/lib/chronic/handlers.rb +167 -112
- data/lib/{numerizer → chronic/numerizer}/numerizer.rb +17 -23
- data/lib/chronic/ordinal.rb +6 -6
- data/lib/chronic/pointer.rb +3 -3
- data/lib/chronic/repeater.rb +26 -12
- data/lib/chronic/repeaters/repeater_day.rb +17 -12
- data/lib/chronic/repeaters/repeater_day_name.rb +17 -12
- data/lib/chronic/repeaters/repeater_day_portion.rb +13 -12
- data/lib/chronic/repeaters/repeater_fortnight.rb +14 -9
- data/lib/chronic/repeaters/repeater_hour.rb +15 -10
- data/lib/chronic/repeaters/repeater_minute.rb +15 -10
- data/lib/chronic/repeaters/repeater_month.rb +20 -15
- data/lib/chronic/repeaters/repeater_month_name.rb +21 -16
- data/lib/chronic/repeaters/repeater_season.rb +136 -9
- data/lib/chronic/repeaters/repeater_season_name.rb +38 -17
- data/lib/chronic/repeaters/repeater_second.rb +15 -10
- data/lib/chronic/repeaters/repeater_time.rb +49 -42
- data/lib/chronic/repeaters/repeater_week.rb +16 -11
- data/lib/chronic/repeaters/repeater_weekday.rb +77 -0
- data/lib/chronic/repeaters/repeater_weekend.rb +14 -9
- data/lib/chronic/repeaters/repeater_year.rb +19 -13
- data/lib/chronic/scalar.rb +16 -14
- data/lib/chronic/separator.rb +25 -10
- data/lib/chronic/time_zone.rb +4 -3
- data/test/helper.rb +7 -0
- data/test/test_Chronic.rb +17 -18
- data/test/test_DaylightSavings.rb +118 -0
- data/test/test_Handler.rb +37 -38
- data/test/test_Numerizer.rb +8 -5
- data/test/test_RepeaterDayName.rb +15 -16
- data/test/test_RepeaterFortnight.rb +16 -17
- data/test/test_RepeaterHour.rb +18 -19
- data/test/test_RepeaterMinute.rb +34 -0
- data/test/test_RepeaterMonth.rb +16 -17
- data/test/test_RepeaterMonthName.rb +17 -18
- data/test/test_RepeaterTime.rb +20 -22
- data/test/test_RepeaterWeek.rb +16 -17
- data/test/test_RepeaterWeekday.rb +55 -0
- data/test/test_RepeaterWeekend.rb +21 -22
- data/test/test_RepeaterYear.rb +17 -18
- data/test/test_Span.rb +5 -6
- data/test/test_Time.rb +11 -12
- data/test/test_Token.rb +5 -6
- data/test/test_parsing.rb +300 -204
- metadata +74 -52
- data/History.txt +0 -53
- data/README.txt +0 -149
- data/test/suite.rb +0 -9
metadata
CHANGED
@@ -1,42 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: chronic
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
rubyforge_project: chronic
|
14
|
-
description: Chronic is a natural language date/time parser written in pure Ruby. See below for the wide variety of formats Chronic will parse.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
25
11
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
12
|
authors:
|
30
13
|
- Tom Preston-Werner
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-22 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Chronic is a natural language date/time parser written in pure Ruby.
|
23
|
+
email: tom@mojombo.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.md
|
30
|
+
- HISTORY.md
|
31
|
+
- LICENSE
|
31
32
|
files:
|
32
|
-
-
|
33
|
+
- HISTORY.md
|
34
|
+
- LICENSE
|
33
35
|
- Manifest.txt
|
34
|
-
- README.
|
36
|
+
- README.md
|
35
37
|
- Rakefile
|
38
|
+
- benchmark/benchmark.rb
|
39
|
+
- chronic.gemspec
|
36
40
|
- lib/chronic.rb
|
37
41
|
- lib/chronic/chronic.rb
|
38
42
|
- lib/chronic/grabber.rb
|
39
43
|
- lib/chronic/handlers.rb
|
44
|
+
- lib/chronic/numerizer/numerizer.rb
|
40
45
|
- lib/chronic/ordinal.rb
|
41
46
|
- lib/chronic/pointer.rb
|
42
47
|
- lib/chronic/repeater.rb
|
@@ -53,66 +58,83 @@ files:
|
|
53
58
|
- lib/chronic/repeaters/repeater_second.rb
|
54
59
|
- lib/chronic/repeaters/repeater_time.rb
|
55
60
|
- lib/chronic/repeaters/repeater_week.rb
|
61
|
+
- lib/chronic/repeaters/repeater_weekday.rb
|
56
62
|
- lib/chronic/repeaters/repeater_weekend.rb
|
57
63
|
- lib/chronic/repeaters/repeater_year.rb
|
58
64
|
- lib/chronic/scalar.rb
|
59
65
|
- lib/chronic/separator.rb
|
60
66
|
- lib/chronic/time_zone.rb
|
61
|
-
-
|
62
|
-
- test/suite.rb
|
67
|
+
- test/helper.rb
|
63
68
|
- test/test_Chronic.rb
|
69
|
+
- test/test_DaylightSavings.rb
|
64
70
|
- test/test_Handler.rb
|
65
71
|
- test/test_Numerizer.rb
|
66
72
|
- test/test_RepeaterDayName.rb
|
67
73
|
- test/test_RepeaterFortnight.rb
|
68
74
|
- test/test_RepeaterHour.rb
|
75
|
+
- test/test_RepeaterMinute.rb
|
69
76
|
- test/test_RepeaterMonth.rb
|
70
77
|
- test/test_RepeaterMonthName.rb
|
71
78
|
- test/test_RepeaterTime.rb
|
72
79
|
- test/test_RepeaterWeek.rb
|
80
|
+
- test/test_RepeaterWeekday.rb
|
73
81
|
- test/test_RepeaterWeekend.rb
|
74
82
|
- test/test_RepeaterYear.rb
|
75
83
|
- test/test_Span.rb
|
76
84
|
- test/test_Time.rb
|
77
85
|
- test/test_Token.rb
|
78
86
|
- test/test_parsing.rb
|
87
|
+
has_rdoc: true
|
88
|
+
homepage: http://github.com/mojombo/chronic
|
89
|
+
licenses: []
|
90
|
+
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options:
|
93
|
+
- --charset=UTF-8
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project: chronic
|
117
|
+
rubygems_version: 1.3.7
|
118
|
+
signing_key:
|
119
|
+
specification_version: 2
|
120
|
+
summary: Natural language date/time parsing.
|
79
121
|
test_files:
|
80
122
|
- test/test_Chronic.rb
|
123
|
+
- test/test_DaylightSavings.rb
|
81
124
|
- test/test_Handler.rb
|
82
125
|
- test/test_Numerizer.rb
|
83
|
-
- test/test_parsing.rb
|
84
126
|
- test/test_RepeaterDayName.rb
|
85
127
|
- test/test_RepeaterFortnight.rb
|
86
128
|
- test/test_RepeaterHour.rb
|
129
|
+
- test/test_RepeaterMinute.rb
|
87
130
|
- test/test_RepeaterMonth.rb
|
88
131
|
- test/test_RepeaterMonthName.rb
|
89
132
|
- test/test_RepeaterTime.rb
|
90
133
|
- test/test_RepeaterWeek.rb
|
134
|
+
- test/test_RepeaterWeekday.rb
|
91
135
|
- test/test_RepeaterWeekend.rb
|
92
136
|
- test/test_RepeaterYear.rb
|
93
137
|
- test/test_Span.rb
|
94
138
|
- test/test_Time.rb
|
95
139
|
- test/test_Token.rb
|
96
|
-
|
97
|
-
- --main
|
98
|
-
- README.txt
|
99
|
-
extra_rdoc_files:
|
100
|
-
- History.txt
|
101
|
-
- Manifest.txt
|
102
|
-
- README.txt
|
103
|
-
executables: []
|
104
|
-
|
105
|
-
extensions: []
|
106
|
-
|
107
|
-
requirements: []
|
108
|
-
|
109
|
-
dependencies:
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: hoe
|
112
|
-
version_requirement:
|
113
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 1.2.1
|
118
|
-
version:
|
140
|
+
- test/test_parsing.rb
|
data/History.txt
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
= 0.2.3
|
2
|
-
|
3
|
-
* fixed 12am/12pm (by Nicholas Schlueter)
|
4
|
-
|
5
|
-
= 0.2.2
|
6
|
-
|
7
|
-
* added missing files (damn you manifest)
|
8
|
-
|
9
|
-
= 0.2.1
|
10
|
-
|
11
|
-
* fixed time overflow issue
|
12
|
-
* implemented "next" for minute repeater
|
13
|
-
* generalized time dealiasing to dealias regardless of day portion and time position
|
14
|
-
* added additional token match for cases like "friday evening at 7" and "tomorrow evening at 7"
|
15
|
-
* added support for Time#to_s output format: "Mon Apr 02 17:00:00 PDT 2007"
|
16
|
-
|
17
|
-
= 0.2.0 2007-03-20
|
18
|
-
|
19
|
-
* implemented numerizer, allowing the use of number words (e.g. five weeks ago) (by shalev)
|
20
|
-
|
21
|
-
= 0.1.6 2006-01-15
|
22
|
-
|
23
|
-
* added 'weekend' support (by eventualbuddha)
|
24
|
-
|
25
|
-
= 0.1.5 2006-12-20
|
26
|
-
|
27
|
-
* fixed 'aug 20' returning next year if current month is august
|
28
|
-
* modified behavior of 'from now'
|
29
|
-
* added support for seconds on times, and thus db timestamp format: "2006-12-20 18:04:23"
|
30
|
-
* made Hoe compliant
|
31
|
-
|
32
|
-
= 0.1.4
|
33
|
-
|
34
|
-
* removed verbose error checking code. oops. :-/
|
35
|
-
|
36
|
-
= 0.1.3
|
37
|
-
|
38
|
-
* improved regexes for word variations (by Josh Goebel)
|
39
|
-
* fixed a bug that caused "today at 3am" to return nil if current time is after 3am
|
40
|
-
|
41
|
-
= 0.1.2
|
42
|
-
|
43
|
-
* removed Date dependency (now works on windows properly without fiddling)
|
44
|
-
|
45
|
-
= 0.1.1
|
46
|
-
|
47
|
-
* run to_s on incoming object
|
48
|
-
* fixed loop loading of repeaters files (out of order on some machines)
|
49
|
-
* fixed find_within to use this instead of next (was breaking "today at 6pm")
|
50
|
-
|
51
|
-
= 0.1.0
|
52
|
-
|
53
|
-
* initial release
|
data/README.txt
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
Chronic
|
2
|
-
http://chronic.rubyforge.org/
|
3
|
-
by Tom Preston-Werner
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Chronic is a natural language date/time parser written in pure Ruby. See below for the wide variety of formats Chronic will parse.
|
8
|
-
|
9
|
-
== INSTALLATION:
|
10
|
-
|
11
|
-
Chronic can be installed via RubyGems:
|
12
|
-
|
13
|
-
$ sudo gem install chronic
|
14
|
-
|
15
|
-
== USAGE:
|
16
|
-
|
17
|
-
You can parse strings containing a natural language date using the Chronic.parse method.
|
18
|
-
|
19
|
-
require 'rubygems'
|
20
|
-
require 'chronic'
|
21
|
-
|
22
|
-
Time.now #=> Sun Aug 27 23:18:25 PDT 2006
|
23
|
-
|
24
|
-
#---
|
25
|
-
|
26
|
-
Chronic.parse('tomorrow')
|
27
|
-
#=> Mon Aug 28 12:00:00 PDT 2006
|
28
|
-
|
29
|
-
Chronic.parse('monday', :context => :past)
|
30
|
-
#=> Mon Aug 21 12:00:00 PDT 2006
|
31
|
-
|
32
|
-
Chronic.parse('this tuesday 5:00')
|
33
|
-
#=> Tue Aug 29 17:00:00 PDT 2006
|
34
|
-
|
35
|
-
Chronic.parse('this tuesday 5:00', :ambiguous_time_range => :none)
|
36
|
-
#=> Tue Aug 29 05:00:00 PDT 2006
|
37
|
-
|
38
|
-
Chronic.parse('may 27th', :now => Time.local(2000, 1, 1))
|
39
|
-
#=> Sat May 27 12:00:00 PDT 2000
|
40
|
-
|
41
|
-
Chronic.parse('may 27th', :guess => false)
|
42
|
-
#=> Sun May 27 00:00:00 PDT 2007..Mon May 28 00:00:00 PDT 2007
|
43
|
-
|
44
|
-
See Chronic.parse for detailed usage instructions.
|
45
|
-
|
46
|
-
== EXAMPLES:
|
47
|
-
|
48
|
-
Chronic can parse a huge variety of date and time formats. Following is a small sample of strings that will be properly parsed. Parsing is case insensitive and will handle common abbreviations and misspellings.
|
49
|
-
|
50
|
-
Simple
|
51
|
-
|
52
|
-
thursday
|
53
|
-
november
|
54
|
-
summer
|
55
|
-
friday 13:00
|
56
|
-
mon 2:35
|
57
|
-
4pm
|
58
|
-
6 in the morning
|
59
|
-
friday 1pm
|
60
|
-
sat 7 in the evening
|
61
|
-
yesterday
|
62
|
-
today
|
63
|
-
tomorrow
|
64
|
-
this tuesday
|
65
|
-
next month
|
66
|
-
last winter
|
67
|
-
this morning
|
68
|
-
last night
|
69
|
-
this second
|
70
|
-
yesterday at 4:00
|
71
|
-
last friday at 20:00
|
72
|
-
last week tuesday
|
73
|
-
tomorrow at 6:45pm
|
74
|
-
afternoon yesterday
|
75
|
-
thursday last week
|
76
|
-
|
77
|
-
Complex
|
78
|
-
|
79
|
-
3 years ago
|
80
|
-
5 months before now
|
81
|
-
7 hours ago
|
82
|
-
7 days from now
|
83
|
-
1 week hence
|
84
|
-
in 3 hours
|
85
|
-
1 year ago tomorrow
|
86
|
-
3 months ago saturday at 5:00 pm
|
87
|
-
7 hours before tomorrow at noon
|
88
|
-
3rd wednesday in november
|
89
|
-
3rd month next year
|
90
|
-
3rd thursday this september
|
91
|
-
4th day last week
|
92
|
-
|
93
|
-
Specific Dates
|
94
|
-
|
95
|
-
January 5
|
96
|
-
dec 25
|
97
|
-
may 27th
|
98
|
-
October 2006
|
99
|
-
oct 06
|
100
|
-
jan 3 2010
|
101
|
-
february 14, 2004
|
102
|
-
3 jan 2000
|
103
|
-
17 april 85
|
104
|
-
5/27/1979
|
105
|
-
27/5/1979
|
106
|
-
05/06
|
107
|
-
1979-05-27
|
108
|
-
Friday
|
109
|
-
5
|
110
|
-
4:00
|
111
|
-
17:00
|
112
|
-
0800
|
113
|
-
|
114
|
-
Specific Times (many of the above with an added time)
|
115
|
-
|
116
|
-
January 5 at 7pm
|
117
|
-
1979-05-27 05:00:00
|
118
|
-
etc
|
119
|
-
|
120
|
-
== LIMITATIONS:
|
121
|
-
|
122
|
-
Chronic uses Ruby's built in Time class for all time storage and computation. Because of this, only times that the Time class can handle will be properly parsed. Parsing for times outside of this range will simply return nil. Support for a wider range of times is planned for a future release.
|
123
|
-
|
124
|
-
Time zones other than the local one are not currently supported. Support for other time zones is planned for a future release.
|
125
|
-
|
126
|
-
== LICENSE:
|
127
|
-
|
128
|
-
(The MIT License)
|
129
|
-
|
130
|
-
Copyright (c) 2006 Ryan Davis, Zen Spider Software
|
131
|
-
|
132
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
133
|
-
a copy of this software and associated documentation files (the
|
134
|
-
"Software"), to deal in the Software without restriction, including
|
135
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
136
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
137
|
-
permit persons to whom the Software is furnished to do so, subject to
|
138
|
-
the following conditions:
|
139
|
-
|
140
|
-
The above copyright notice and this permission notice shall be
|
141
|
-
included in all copies or substantial portions of the Software.
|
142
|
-
|
143
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
144
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
145
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
146
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
147
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
148
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
149
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|