chronic-davispuh 0.10.2.v0.1da32066b3f46f2506b3471e39557497e34afa27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +3 -0
  5. data/HISTORY.md +243 -0
  6. data/LICENSE +21 -0
  7. data/README.md +185 -0
  8. data/Rakefile +68 -0
  9. data/chronic.gemspec +27 -0
  10. data/lib/chronic.rb +122 -0
  11. data/lib/chronic/arrow.rb +270 -0
  12. data/lib/chronic/date.rb +272 -0
  13. data/lib/chronic/definition.rb +208 -0
  14. data/lib/chronic/dictionary.rb +36 -0
  15. data/lib/chronic/handler.rb +44 -0
  16. data/lib/chronic/handlers/anchor.rb +65 -0
  17. data/lib/chronic/handlers/arrow.rb +84 -0
  18. data/lib/chronic/handlers/date.rb +270 -0
  19. data/lib/chronic/handlers/date_time.rb +72 -0
  20. data/lib/chronic/handlers/general.rb +130 -0
  21. data/lib/chronic/handlers/narrow.rb +54 -0
  22. data/lib/chronic/handlers/time.rb +167 -0
  23. data/lib/chronic/handlers/time_zone.rb +50 -0
  24. data/lib/chronic/objects/anchor_object.rb +263 -0
  25. data/lib/chronic/objects/arrow_object.rb +27 -0
  26. data/lib/chronic/objects/date_object.rb +164 -0
  27. data/lib/chronic/objects/date_time_object.rb +64 -0
  28. data/lib/chronic/objects/handler_object.rb +81 -0
  29. data/lib/chronic/objects/narrow_object.rb +85 -0
  30. data/lib/chronic/objects/time_object.rb +96 -0
  31. data/lib/chronic/objects/time_zone_object.rb +27 -0
  32. data/lib/chronic/parser.rb +154 -0
  33. data/lib/chronic/span.rb +32 -0
  34. data/lib/chronic/tag.rb +84 -0
  35. data/lib/chronic/tags/day_name.rb +34 -0
  36. data/lib/chronic/tags/day_portion.rb +33 -0
  37. data/lib/chronic/tags/day_special.rb +30 -0
  38. data/lib/chronic/tags/grabber.rb +29 -0
  39. data/lib/chronic/tags/keyword.rb +63 -0
  40. data/lib/chronic/tags/month_name.rb +39 -0
  41. data/lib/chronic/tags/ordinal.rb +52 -0
  42. data/lib/chronic/tags/pointer.rb +28 -0
  43. data/lib/chronic/tags/rational.rb +35 -0
  44. data/lib/chronic/tags/scalar.rb +101 -0
  45. data/lib/chronic/tags/season_name.rb +31 -0
  46. data/lib/chronic/tags/separator.rb +130 -0
  47. data/lib/chronic/tags/sign.rb +35 -0
  48. data/lib/chronic/tags/time_special.rb +34 -0
  49. data/lib/chronic/tags/time_zone.rb +56 -0
  50. data/lib/chronic/tags/unit.rb +174 -0
  51. data/lib/chronic/time.rb +141 -0
  52. data/lib/chronic/time_zone.rb +80 -0
  53. data/lib/chronic/token.rb +61 -0
  54. data/lib/chronic/token_group.rb +271 -0
  55. data/lib/chronic/tokenizer.rb +42 -0
  56. data/lib/chronic/version.rb +3 -0
  57. data/test/helper.rb +12 -0
  58. data/test/test_chronic.rb +190 -0
  59. data/test/test_daylight_savings.rb +98 -0
  60. data/test/test_handler.rb +113 -0
  61. data/test/test_parsing.rb +1520 -0
  62. data/test/test_span.rb +23 -0
  63. data/test/test_token.rb +31 -0
  64. metadata +218 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5591ebaa2332071a9ed493bd972aa1643c929161
4
+ data.tar.gz: f890080c51d79b2b45067891a1f3a20b983b87ba
5
+ SHA512:
6
+ metadata.gz: 37ac1d2cf46a31d7cbe44865e721af88f35168678cd1b02ba0997a73b389842ca8019f310ce240b34d00a39fda80954b6c80620a0511a82af7a5d88912359052
7
+ data.tar.gz: c3a6389042842236905f759a6de257f0436cf58edb60da90e898395b3b7475cb4872a75c1f2a6f7c446987de8271dcbaf03661d4c5291b5e15b91e46dde2d9fa
@@ -0,0 +1,8 @@
1
+ *.rbc
2
+ .yardoc
3
+ /.bundle/
4
+ /pkg/
5
+ /coverage/
6
+ /doc/
7
+ /tags/
8
+ Gemfile.lock
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.1
4
+ - 2.3
5
+ - 2.2
6
+ - 2.1
7
+ - 2.0.0
8
+ - 1.9.3
9
+ - jruby-19mode
10
+ - rbx-2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,243 @@
1
+ # 0.10.2 / 2013-09-09
2
+
3
+ * Fix 1.8.7 support (due to be dropped in 0.11.0)
4
+ * Bugfix for times with negative zones
5
+
6
+ # 0.10.1 / 2013-08-27
7
+
8
+ * Support `ActiveSupport::TimeZone` (#209, #208)
9
+
10
+ # 0.10.0 / 2013-08-25
11
+
12
+ * Chronic will parse subseconds correctly
13
+ for all supported date/time formats (#195, #198 and #200)
14
+ * Support for date format: dd.mm.yyyy (#197)
15
+ * Option `:hours24` to parse as 24 hour clock (#201 and #202)
16
+ * `:guess` option allows to specify which part of Span to return.
17
+ (accepted values `false`,`true`,`:begin`, `:middle`, `:end`)
18
+ * Replace `rcov` with `SimpleCov` for coverage generation
19
+ * Add more tests
20
+ * Various changes in codebase (#202 and #206)
21
+
22
+ # 0.9.1 / 2013-02-25
23
+
24
+ * Ensure Chronic strips periods from day portions (#173)
25
+ * Properly numerize "twelfth", "twentieth" etc. (#172, James McKinney)
26
+ * Ensure Chronic is compatible with Ruby 2.0.0 (#165, Ravil Bayramgalin)
27
+
28
+ # 0.9.0 / 2012-12-21
29
+
30
+ * Implement Chronic::Parser class and create an instance of this class
31
+ instead of leaving all data in the class level of Chronic
32
+ * Various bug fixes
33
+ * Add support for excel date formats (#149, @jmondo)
34
+ * Added support for time expressions such as '10 till' or 'half
35
+ past two' (#146, @chicagogrooves)
36
+ * Add support for RepeaterDayName, RepeaterMonthName,
37
+ Ordinal/ScalarDay and Time (#153, @kareemk)
38
+
39
+ # 0.8.0 / 2012-09-16
40
+
41
+ * Support parsing "<ordinal> of this month" (#109)
42
+ * Support parsing ISO 8601 format (#115)
43
+ * Support parsing "on <day>" without a timestamp (#117)
44
+ * Fix time parsing regexp (#125)
45
+ * Support time when parsing dd-mm-yyy <time> (#126)
46
+ * Allow anchor handler to accept any separators (at, on) (#128)
47
+ * Support parsing EXIF date format (#112)
48
+ * Start using minitest for testing
49
+ * Ensure periods are interpreted as colons (#81).
50
+ * Support month/day and day/month parsing (#59).
51
+ * Support day(scalar)-month(name)-year(scalar) (#99).
52
+ * Handle text starting with 'a' or 'an' (#101, @steveburkett).
53
+ * Ensure post medium timestamps are correctly formatted (#89)
54
+
55
+ # 0.6.7 / 2012-01-31
56
+
57
+ * Handle day, month names with scalar day and year (Joe Fiorini)
58
+ * Ensure 31st parses correctly with day names (Joe Fiorini)
59
+
60
+ # 0.6.6 / 2011-11-23
61
+
62
+ * `Chronic.parse('thur')` no longer returns `nil` (@harold)
63
+
64
+ # 0.6.5 / 2011-11-04
65
+
66
+ * Fix bug when parsing ordinal repeaters (#73)
67
+ * Added handler support for day_name month_name (@imme5150)
68
+ * Fix bug when parsing strings prefixed with PM
69
+
70
+ # 0.6.4 / 2011-08-08
71
+
72
+ * Fixed bug where 'noon' was parsed as 00:00 rather than 12:00
73
+ with :ambiguous_time_range => :none (Vladimir Chernis)
74
+ * Add support for handling '2009 May 22nd'
75
+ * Add the ability to handle scalar-day/repeater-month-name as well as ordinals
76
+
77
+ # 0.6.3 / 2011-08-01
78
+
79
+ * Ensure 'thu' is parsed as Thursday for 1.8.7 generic timestamp
80
+
81
+ # 0.6.2 / 2011-07-28
82
+
83
+ * Ensure specific endian handlers are prioritised over normal date handlers
84
+ * Recognize UTC as timezone and accept HH::MM timezone offset (Jason Dusek)
85
+
86
+ # 0.6.1 / 2011-07-21
87
+
88
+ * Ensure Handler definitions are executed in the correct order
89
+
90
+ # 0.6.0 / 2011-07-19
91
+
92
+ * Attempting to parse strings with days past the last day of a month will
93
+ now return nil. ex: `Chronic.parse("30th February") #=> nil`
94
+ * All deprecated methods are marked for removal in Chronic 0.7.0
95
+ * Deprecated `Chronic.numericize_numbers` instead use
96
+ `Chronic::Numerizer.numerize`
97
+ * Deprecated `Chronic::InvalidArgumentException` and instead use
98
+ `ArgumentError`
99
+ * Deprecated `Time.construct` and use `Chronic.construct` in place of this
100
+ * Deprecated `Time#to_minidate`, instead use `Chronic::MiniDate.from_time(time)`
101
+ * Add support for handling generic timestamp for Ruby 1.9+
102
+
103
+ # 0.5.0 / 2011-07-01
104
+
105
+ * Replace commas with spaces instead of removing the char (Thomas Walpole)
106
+ * Added tests for RepeaterSeason
107
+ * Re-factored tests. Now rather than having a test_parsing method for testing
108
+ all handlers, break them down independent of handler method. For example
109
+ with handler `handle_sm_sd_sy` the subsequent test would be
110
+ `test_handle_sm_sd_sy`
111
+ * Added support for parsing ordinal-dates/month-names/year, ie:
112
+ `2nd of May 1995`
113
+ * Added support for parsing ordinal-dates and month names, ie:
114
+ `22nd of February at 6:30pm`
115
+ * Fix `Time.construct` leap year checking. Instead use `Date.leap?(year)`
116
+
117
+ # 0.4.4 / 2011-06-12
118
+
119
+ * Fix RepeaterYear for fetching past year offsets when the current day is
120
+ later than the last day of the same month in a past year (leap years) ie
121
+ on 29th/feb (leap year) `last year` should (and now does) return 28th/feb
122
+ instead of 1st/march
123
+ * Opt in for gem testing http://test.rubygems.org/
124
+
125
+ # 0.4.3 / 2011-06-08
126
+
127
+ * Fix issue with parsing 1:xxPM -- Ensure 1 is treated as ambiguous, not
128
+ just >1
129
+
130
+ # 0.4.2 / 2011-06-07
131
+
132
+ * Fix MonthRepeater for fetching past month offsets when current day is
133
+ later than the last day of a past month (ie on 29th of March when parsing
134
+ `last month` Chronic would return March instead of February. Now Chronic
135
+ returns the last day of the past month)
136
+
137
+ # 0.4.1 / 2011-06-05
138
+
139
+ * Fix MiniDate ranges for parsing seasons (Thomas Walpole)
140
+
141
+ # 0.4.0 / 2011-06-04
142
+
143
+ * Ensure context is being passed through grabbers. Now "Sunday at 2:18pm"
144
+ with `:context => :past` will return the correct date
145
+ * Support parsing ordinal strings (eg first, twenty third => 1st, 23rd)
146
+ * Seasons now ignore DST and return 00 as an hour
147
+ * Support parsing 2 digit years and added `ambiguous_year_future_bias` option
148
+ * Support parsing 'thurs' for Thursday
149
+ * Fix pre_normalize() to remove periods before numerizing
150
+ * Fix RepeaterDays to not add an extra hour in future tense. This meant
151
+ when parsing 'yesterday' after 11PM, Chronic would return today
152
+ * Discard any prefixed 0 for time strings when using post noon portion
153
+ * Gemspec updates for RubyGems deprecations
154
+ * Ensure 0:10 is treated like 00:10
155
+ * Ensure we load classes after setting Chronic class instance variables
156
+ so we can debug initialization and do assignments at compile time
157
+ * Added a Tag.scan_for method for DRYing up some scanning code
158
+ * Move some classes into their own files for maintainability
159
+ * Numerizer.andition should be a private class method, make it so
160
+ * Namespaced Numerizer, Season and MiniDate (Sascha Teske)
161
+ * Support for Ruby 1.9 (Dave Lee, Aaron Hurley)
162
+ * Fix `:context => :past` where parsed date is in current month (Marc Hedlund)
163
+ * Fix undefined variable in RepeaterHour (Ryan Garver)
164
+ * Added support for parsing 'Fourty' as another mis-spelling (Lee Reilly)
165
+ * Added ordinal format support: ie 'February 14th, 2004' (Jeff Felchner)
166
+ * Fix dates when working with daylight saving times (Mike Mangino)
167
+
168
+ # 0.3.0 / 2010-10-22
169
+
170
+ * Fix numerizer number combination bug (27 Oct 2006 7:30pm works now)
171
+ * Allow numeric timezone offset (e.g -0500)
172
+ * Disregard commas (so as to not return nil)
173
+ * Fix parse of (am|pm|oclock) separation to handle "Ham sandwich" properly
174
+ * Handle 'on' e.g. 5pm on Monday
175
+ * Support seasons
176
+ * Support weekend/weekday
177
+ * Add endianness option
178
+ * Update version number in the module
179
+ * Fix/improve logic checks in Ordinal, and Scalar
180
+ * Parse 'a' or 'p' as 'am' and 'pm' google-calendar style
181
+ * Dates < 1 are not valid
182
+ * Fix bugs related to timezone offset
183
+ * Use RakeGem for build management
184
+ * Reformat README and HISTORY to use Markdown
185
+ * Global whitespace removal
186
+
187
+ # 0.2.3
188
+
189
+ * Fix 12am/12pm
190
+
191
+ # 0.2.2
192
+
193
+ * Add missing files (damn you manifest)
194
+
195
+ # 0.2.1
196
+
197
+ * Fix time overflow issue
198
+ * Implement "next" for minute repeater
199
+ * Generalize time dealiasing to dealias regardless of day portion and
200
+ time position
201
+ * Add additional token match for cases like "friday evening at 7" and
202
+ "tomorrow evening at 7"
203
+ * Add support for Time#to_s output format: "Mon Apr 02 17:00:00 PDT 2007"
204
+
205
+ # 0.2.0 2007-03-20
206
+
207
+ * Implement numerizer, allowing the use of number words (e.g. five weeks ago)
208
+
209
+ # 0.1.6 2006-01-15
210
+
211
+ * Add 'weekend' support
212
+
213
+ # 0.1.5 2006-12-20
214
+
215
+ * Fix 'aug 20' returning next year if current month is august
216
+ * Modify behavior of 'from now'
217
+ * Add support for seconds on times, and thus db timestamp format:
218
+ "2006-12-20 18:04:23"
219
+ * Make Hoe compliant
220
+
221
+ # 0.1.4
222
+
223
+ * Remove verbose error checking code. oops. :-/
224
+
225
+ # 0.1.3
226
+
227
+ * improved regexes for word variations
228
+ * Fix a bug that caused "today at 3am" to return nil if current time is
229
+ after 3am
230
+
231
+ # 0.1.2
232
+
233
+ * Remove Date dependency (now works on windows properly without fiddling)
234
+
235
+ # 0.1.1
236
+
237
+ * Run to_s on incoming object
238
+ * Fix loop loading of repeaters files (out of order on some machines)
239
+ * Fix find_within to use this instead of next (was breaking "today at 6pm")
240
+
241
+ # 0.1.0
242
+
243
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Tom Preston-Werner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,185 @@
1
+ Chronic
2
+ =======
3
+
4
+ Chronic is a natural language date/time parser written in pure Ruby. See below
5
+ for the wide variety of formats Chronic will parse.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ $ gem install chronic
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ require 'chronic'
17
+
18
+ Time.now #=> Sun Aug 27 23:18:25 PDT 2006
19
+
20
+ Chronic.parse('tomorrow')
21
+ #=> Mon Aug 28 12:00:00 PDT 2006
22
+
23
+ Chronic.parse('monday', :context => :past)
24
+ #=> Mon Aug 21 12:00:00 PDT 2006
25
+
26
+ Chronic.parse('this tuesday 5:00')
27
+ #=> Tue Aug 29 17:00:00 PDT 2006
28
+
29
+ Chronic.parse('this tuesday 5:00', :ambiguous_time_range => :none)
30
+ #=> Tue Aug 29 05:00:00 PDT 2006
31
+
32
+ Chronic.parse('may 27th', :now => Time.local(2000, 1, 1))
33
+ #=> Sat May 27 12:00:00 PDT 2000
34
+
35
+ Chronic.parse('may 27th', :guess => false)
36
+ #=> Sun May 27 00:00:00 PDT 2007..Mon May 28 00:00:00 PDT 2007
37
+
38
+ Chronic.parse('6/4/2012', :endian_precedence => :little)
39
+ #=> Fri Apr 06 00:00:00 PDT 2012
40
+
41
+ Chronic.parse('INVALID DATE')
42
+ #=> nil
43
+ ```
44
+
45
+ If the parser can find a date or time, either a Time or Chronic::Span
46
+ will be returned (depending on the value of `:guess`). If no
47
+ date or time can be found, `nil` will be returned.
48
+
49
+ See `Chronic.parse` for detailed usage instructions.
50
+
51
+ ## Examples
52
+
53
+ Chronic can parse a huge variety of date and time formats. Following is a
54
+ small sample of strings that will be properly parsed. Parsing is case
55
+ insensitive and will handle common abbreviations and misspellings.
56
+
57
+ Simple
58
+
59
+ * thursday
60
+ * november
61
+ * summer
62
+ * friday 13:00
63
+ * mon 2:35
64
+ * 4pm
65
+ * 10 to 8
66
+ * 10 past 2
67
+ * half past 2
68
+ * 6 in the morning
69
+ * friday 1pm
70
+ * sat 7 in the evening
71
+ * yesterday
72
+ * today
73
+ * tomorrow
74
+ * last week
75
+ * next week
76
+ * this tuesday
77
+ * next month
78
+ * last winter
79
+ * this morning
80
+ * last night
81
+ * this second
82
+ * yesterday at 4:00
83
+ * last friday at 20:00
84
+ * last week tuesday
85
+ * tomorrow at 6:45pm
86
+ * afternoon yesterday
87
+ * thursday last week
88
+
89
+ Complex
90
+
91
+ * 3 years ago
92
+ * a year ago
93
+ * 5 months before now
94
+ * 7 hours ago
95
+ * 7 days from now
96
+ * 1 week hence
97
+ * in 3 hours
98
+ * 1 year ago tomorrow
99
+ * 3 months ago saturday at 5:00 pm
100
+ * 7 hours before tomorrow at noon
101
+ * 3rd wednesday in november
102
+ * 3rd month next year
103
+ * 3rd thursday this september
104
+ * 4th day last week
105
+ * fourteenth of june 2010 at eleven o'clock in the evening
106
+ * may seventh '97 at three in the morning
107
+
108
+ Specific Dates
109
+
110
+ * January 5
111
+ * 22nd of june
112
+ * 5th may 2017
113
+ * February twenty first
114
+ * dec 25
115
+ * may 27th
116
+ * October 2006
117
+ * oct 06
118
+ * jan 3 2010
119
+ * february 14, 2004
120
+ * february 14th, 2004
121
+ * 3 jan 2000
122
+ * 17 april 85
123
+ * 5/27/1979
124
+ * 27/5/1979
125
+ * 05/06
126
+ * 1979-05-27
127
+ * Friday
128
+ * 5
129
+ * 4:00
130
+ * 17:00
131
+ * 0800
132
+
133
+ Specific Times (many of the above with an added time)
134
+
135
+ * January 5 at 7pm
136
+ * 22nd of june at 8am
137
+ * 1979-05-27 05:00:00
138
+ * 03/01/2012 07:25:09.234567
139
+ * 2013-08-01T19:30:00.345-07:00
140
+ * 2013-08-01T19:30:00.34-07:00
141
+ * etc
142
+
143
+
144
+ ## Time Zones
145
+
146
+ Chronic allows you to set which Time class to use when constructing times. By
147
+ default, the built in Ruby time class creates times in your system's local
148
+ time zone. You can set this to something like ActiveSupport's
149
+ [TimeZone](http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html)
150
+ class to get full time zone support.
151
+
152
+ ```
153
+ >> Time.zone = "UTC"
154
+ >> Chronic.time_class = Time.zone
155
+ >> Chronic.parse("June 15 2006 at 5:45 AM")
156
+ => Thu, 15 Jun 2006 05:45:00 UTC +00:00
157
+ ```
158
+
159
+ ## Limitations
160
+
161
+ Chronic uses Ruby's built in Time class for all time storage and computation.
162
+ Because of this, only times that the Time class can handle will be properly
163
+ parsed. Parsing for times outside of this range will simply return nil.
164
+ Support for a wider range of times is planned for a future release.
165
+
166
+
167
+ ## Contribute
168
+
169
+ If you'd like to hack on Chronic, start by forking the repo on GitHub:
170
+
171
+ https://github.com/mojombo/chronic
172
+
173
+ The best way to get your changes merged back into core is as follows:
174
+
175
+ 1. Clone down your fork
176
+ 1. Create a thoughtfully named topic branch to contain your change
177
+ 1. Install the development dependencies by running `bundle install`
178
+ 1. Hack away
179
+ 1. Add tests and make sure everything still passes by running `bundle exec rake`
180
+ 1. Ensure your tests pass in multiple timezones. ie `TZ=utc bundle exec rake` `TZ=BST bundle exec rake`
181
+ 1. If you are adding new functionality, document it in the README
182
+ 1. Do not change the version number, we will do that on our end
183
+ 1. If necessary, rebase your commits into logical chunks, without errors
184
+ 1. Push the branch up to GitHub
185
+ 1. Send a pull request for your branch