chronic 0.1.5 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +5 -0
  3. data/.yardopts +3 -0
  4. data/HISTORY.md +180 -0
  5. data/LICENSE +21 -0
  6. data/README.md +176 -0
  7. data/Rakefile +39 -32
  8. data/chronic.gemspec +17 -0
  9. data/lib/chronic/chronic.rb +294 -208
  10. data/lib/chronic/grabber.rb +22 -17
  11. data/lib/chronic/handler.rb +90 -0
  12. data/lib/chronic/handlers.rb +365 -278
  13. data/lib/chronic/mini_date.rb +38 -0
  14. data/lib/chronic/numerizer.rb +121 -0
  15. data/lib/chronic/ordinal.rb +23 -19
  16. data/lib/chronic/pointer.rb +20 -17
  17. data/lib/chronic/repeater.rb +126 -105
  18. data/lib/chronic/repeaters/repeater_day.rb +49 -43
  19. data/lib/chronic/repeaters/repeater_day_name.rb +48 -42
  20. data/lib/chronic/repeaters/repeater_day_portion.rb +81 -80
  21. data/lib/chronic/repeaters/repeater_fortnight.rb +59 -53
  22. data/lib/chronic/repeaters/repeater_hour.rb +49 -43
  23. data/lib/chronic/repeaters/repeater_minute.rb +55 -39
  24. data/lib/chronic/repeaters/repeater_month.rb +77 -55
  25. data/lib/chronic/repeaters/repeater_month_name.rb +83 -82
  26. data/lib/chronic/repeaters/repeater_season.rb +107 -21
  27. data/lib/chronic/repeaters/repeater_season_name.rb +41 -22
  28. data/lib/chronic/repeaters/repeater_second.rb +39 -33
  29. data/lib/chronic/repeaters/repeater_time.rb +117 -103
  30. data/lib/chronic/repeaters/repeater_week.rb +63 -57
  31. data/lib/chronic/repeaters/repeater_weekday.rb +85 -0
  32. data/lib/chronic/repeaters/repeater_weekend.rb +64 -9
  33. data/lib/chronic/repeaters/repeater_year.rb +70 -51
  34. data/lib/chronic/scalar.rb +64 -29
  35. data/lib/chronic/season.rb +37 -0
  36. data/lib/chronic/separator.rb +50 -38
  37. data/lib/chronic/span.rb +31 -0
  38. data/lib/chronic/tag.rb +42 -0
  39. data/lib/chronic/time_zone.rb +30 -0
  40. data/lib/chronic/token.rb +45 -0
  41. data/lib/chronic.rb +86 -22
  42. data/test/helper.rb +6 -0
  43. data/test/test_Chronic.rb +118 -20
  44. data/test/test_DaylightSavings.rb +118 -0
  45. data/test/test_Handler.rb +36 -42
  46. data/test/test_MiniDate.rb +32 -0
  47. data/test/test_Numerizer.rb +72 -0
  48. data/test/test_RepeaterDayName.rb +15 -16
  49. data/test/test_RepeaterFortnight.rb +16 -17
  50. data/test/test_RepeaterHour.rb +22 -19
  51. data/test/test_RepeaterMinute.rb +34 -0
  52. data/test/test_RepeaterMonth.rb +20 -17
  53. data/test/test_RepeaterMonthName.rb +17 -18
  54. data/test/test_RepeaterSeason.rb +40 -0
  55. data/test/test_RepeaterTime.rb +20 -22
  56. data/test/test_RepeaterWeek.rb +16 -17
  57. data/test/test_RepeaterWeekday.rb +55 -0
  58. data/test/test_RepeaterWeekend.rb +74 -0
  59. data/test/test_RepeaterYear.rb +24 -18
  60. data/test/test_Span.rb +5 -6
  61. data/test/test_Token.rb +5 -6
  62. data/test/test_parsing.rb +743 -338
  63. metadata +81 -54
  64. data/History.txt +0 -29
  65. data/Manifest.txt +0 -43
  66. data/README.txt +0 -149
  67. data/test/parse_numbers.rb +0 -50
  68. data/test/suite.rb +0 -9
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg
2
+ *.rbc
3
+ rdoc
4
+ .yardoc
5
+ doc
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ -m markdown
2
+ --readme README.md
3
+ --title "Chronic - Natural language date/time parsing"
data/HISTORY.md ADDED
@@ -0,0 +1,180 @@
1
+ # 0.6.5 / 2011-11-04
2
+
3
+ * Fix bug when parsing ordinal repeaters (#73)
4
+ * Added handler support for day_name month_name (@imme5150)
5
+ * Fix bug when parsing strings prefixed with PM
6
+
7
+ # 0.6.4 / 2011-08-08
8
+
9
+ * Fixed bug where 'noon' was parsed as 00:00 rather than 12:00
10
+ with :ambiguous_time_range => :none (Vladimir Chernis)
11
+ * Add support for handling '2009 May 22nd'
12
+ * Add the ability to handle scalar-day/repeater-month-name as well as ordinals
13
+
14
+ # 0.6.3 / 2011-08-01
15
+
16
+ * Ensure 'thu' is parsed as Thursday for 1.8.7 generic timestamp
17
+
18
+ # 0.6.2 / 2011-07-28
19
+
20
+ * Ensure specific endian handlers are prioritised over normal date handlers
21
+ * Recognize UTC as timezone and accept HH::MM timezone offset (Jason Dusek)
22
+
23
+ # 0.6.1 / 2011-07-21
24
+
25
+ * Ensure Handler definitions are executed in the correct order
26
+
27
+ # 0.6.0 / 2011-07-19
28
+
29
+ * Attempting to parse strings with days past the last day of a month will
30
+ now return nil. ex: `Chronic.parse("30th February") #=> nil`
31
+ * All deprecated methods are marked for removal in Chronic 0.7.0
32
+ * Deprecated `Chronic.numericize_numbers` instead use
33
+ `Chronic::Numerizer.numerize`
34
+ * Deprecated `Chronic::InvalidArgumentException` and instead use
35
+ `ArgumentError`
36
+ * Deprecated `Time.construct` and use `Chronic.construct` in place of this
37
+ * Deprecated `Time#to_minidate`, instead use `Chronic::MiniDate.from_time(time)`
38
+ * Add support for handling generic timestamp for Ruby 1.9+
39
+
40
+ # 0.5.0 / 2011-07-01
41
+
42
+ * Replace commas with spaces instead of removing the char (Thomas Walpole)
43
+ * Added tests for RepeaterSeason
44
+ * Re-factored tests. Now rather than having a test_parsing method for testing
45
+ all handlers, break them down independent of handler method. For example
46
+ with handler `handle_sm_sd_sy` the subsequent test would be
47
+ `test_handle_sm_sd_sy`
48
+ * Added support for parsing ordinal-dates/month-names/year, ie:
49
+ `2nd of May 1995`
50
+ * Added support for parsing ordinal-dates and month names, ie:
51
+ `22nd of February at 6:30pm`
52
+ * Fix `Time.construct` leap year checking. Instead use `Date.leap?(year)`
53
+
54
+ # 0.4.4 / 2011-06-12
55
+
56
+ * Fix RepeaterYear for fetching past year offsets when the current day is
57
+ later than the last day of the same month in a past year (leap years) ie
58
+ on 29th/feb (leap year) `last year` should (and now does) return 28th/feb
59
+ instead of 1st/march
60
+ * Opt in for gem testing http://test.rubygems.org/
61
+
62
+ # 0.4.3 / 2011-06-08
63
+
64
+ * Fix issue with parsing 1:xxPM -- Ensure 1 is treated as ambiguous, not
65
+ just >1
66
+
67
+ # 0.4.2 / 2011-06-07
68
+
69
+ * Fix MonthRepeater for fetching past month offsets when current day is
70
+ later than the last day of a past month (ie on 29th of March when parsing
71
+ `last month` Chronic would return March instead of February. Now Chronic
72
+ returns the last day of the past month)
73
+
74
+ # 0.4.1 / 2011-06-05
75
+
76
+ * Fix MiniDate ranges for parsing seasons (Thomas Walpole)
77
+
78
+ # 0.4.0 / 2011-06-04
79
+
80
+ * Ensure context is being passed through grabbers. Now "Sunday at 2:18pm"
81
+ with `:context => :past` will return the correct date
82
+ * Support parsing ordinal strings (eg first, twenty third => 1st, 23rd)
83
+ * Seasons now ignore DST and return 00 as an hour
84
+ * Support parsing 2 digit years and added `ambiguous_year_future_bias` option
85
+ * Support parsing 'thurs' for Thursday
86
+ * Fix pre_normalize() to remove periods before numerizing
87
+ * Fix RepeaterDays to not add an extra hour in future tense. This meant
88
+ when parsing 'yesterday' after 11PM, Chronic would return today
89
+ * Discard any prefixed 0 for time strings when using post noon portion
90
+ * Gemspec updates for RubyGems deprecations
91
+ * Ensure 0:10 is treated like 00:10
92
+ * Ensure we load classes after setting Chronic class instance variables
93
+ so we can debug initialization and do assignments at compile time
94
+ * Added a Tag.scan_for method for DRYing up some scanning code
95
+ * Move some classes into their own files for maintainability
96
+ * Numerizer.andition should be a private class method, make it so
97
+ * Namespaced Numerizer, Season and MiniDate (Sascha Teske)
98
+ * Support for Ruby 1.9 (Dave Lee, Aaron Hurley)
99
+ * Fix `:context => :past` where parsed date is in current month (Marc Hedlund)
100
+ * Fix undefined variable in RepeaterHour (Ryan Garver)
101
+ * Added support for parsing 'Fourty' as another mis-spelling (Lee Reilly)
102
+ * Added ordinal format support: ie 'February 14th, 2004' (Jeff Felchner)
103
+ * Fix dates when working with daylight saving times (Mike Mangino)
104
+
105
+ # 0.3.0 / 2010-10-22
106
+
107
+ * Fix numerizer number combination bug (27 Oct 2006 7:30pm works now)
108
+ * Allow numeric timezone offset (e.g -0500)
109
+ * Disregard commas (so as to not return nil)
110
+ * Fix parse of (am|pm|oclock) separation to handle "Ham sandwich" properly
111
+ * Handle 'on' e.g. 5pm on Monday
112
+ * Support seasons
113
+ * Support weekend/weekday
114
+ * Add endianness option
115
+ * Update version number in the module
116
+ * Fix/improve logic checks in Ordinal, and Scalar
117
+ * Parse 'a' or 'p' as 'am' and 'pm' google-calendar style
118
+ * Dates < 1 are not valid
119
+ * Fix bugs related to timezone offset
120
+ * Use RakeGem for build management
121
+ * Reformat README and HISTORY to use Markdown
122
+ * Global whitespace removal
123
+
124
+ # 0.2.3
125
+
126
+ * Fix 12am/12pm
127
+
128
+ # 0.2.2
129
+
130
+ * Add missing files (damn you manifest)
131
+
132
+ # 0.2.1
133
+
134
+ * Fix time overflow issue
135
+ * Implement "next" for minute repeater
136
+ * Generalize time dealiasing to dealias regardless of day portion and
137
+ time position
138
+ * Add additional token match for cases like "friday evening at 7" and
139
+ "tomorrow evening at 7"
140
+ * Add support for Time#to_s output format: "Mon Apr 02 17:00:00 PDT 2007"
141
+
142
+ # 0.2.0 2007-03-20
143
+
144
+ * Implement numerizer, allowing the use of number words (e.g. five weeks ago)
145
+
146
+ # 0.1.6 2006-01-15
147
+
148
+ * Add 'weekend' support
149
+
150
+ # 0.1.5 2006-12-20
151
+
152
+ * Fix 'aug 20' returning next year if current month is august
153
+ * Modify behavior of 'from now'
154
+ * Add support for seconds on times, and thus db timestamp format:
155
+ "2006-12-20 18:04:23"
156
+ * Make Hoe compliant
157
+
158
+ # 0.1.4
159
+
160
+ * Remove verbose error checking code. oops. :-/
161
+
162
+ # 0.1.3
163
+
164
+ * improved regexes for word variations
165
+ * Fix a bug that caused "today at 3am" to return nil if current time is
166
+ after 3am
167
+
168
+ # 0.1.2
169
+
170
+ * Remove Date dependency (now works on windows properly without fiddling)
171
+
172
+ # 0.1.1
173
+
174
+ * Run to_s on incoming object
175
+ * Fix loop loading of repeaters files (out of order on some machines)
176
+ * Fix find_within to use this instead of next (was breaking "today at 6pm")
177
+
178
+ # 0.1.0
179
+
180
+ * 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.
data/README.md ADDED
@@ -0,0 +1,176 @@
1
+ Chronic
2
+ =======
3
+
4
+ ## DESCRIPTION
5
+
6
+ Chronic is a natural language date/time parser written in pure Ruby. See below
7
+ for the wide variety of formats Chronic will parse.
8
+
9
+
10
+ ## INSTALLATION
11
+
12
+ ### RubyGems
13
+
14
+ $ [sudo] gem install chronic
15
+
16
+ ### GitHub
17
+
18
+ $ git clone git://github.com/mojombo/chronic.git
19
+ $ cd chronic && gem build chronic.gemspec
20
+ $ gem install chronic-<version>.gem
21
+
22
+
23
+ ## USAGE
24
+
25
+ You can parse strings containing a natural language date using the
26
+ `Chronic.parse` method.
27
+
28
+ require 'chronic'
29
+
30
+ Time.now #=> Sun Aug 27 23:18:25 PDT 2006
31
+
32
+ Chronic.parse('tomorrow')
33
+ #=> Mon Aug 28 12:00:00 PDT 2006
34
+
35
+ Chronic.parse('monday', :context => :past)
36
+ #=> Mon Aug 21 12:00:00 PDT 2006
37
+
38
+ Chronic.parse('this tuesday 5:00')
39
+ #=> Tue Aug 29 17:00:00 PDT 2006
40
+
41
+ Chronic.parse('this tuesday 5:00', :ambiguous_time_range => :none)
42
+ #=> Tue Aug 29 05:00:00 PDT 2006
43
+
44
+ Chronic.parse('may 27th', :now => Time.local(2000, 1, 1))
45
+ #=> Sat May 27 12:00:00 PDT 2000
46
+
47
+ Chronic.parse('may 27th', :guess => false)
48
+ #=> Sun May 27 00:00:00 PDT 2007..Mon May 28 00:00:00 PDT 2007
49
+
50
+ See `Chronic.parse` for detailed usage instructions.
51
+
52
+
53
+ ## EXAMPLES
54
+
55
+ Chronic can parse a huge variety of date and time formats. Following is a
56
+ small sample of strings that will be properly parsed. Parsing is case
57
+ insensitive and will handle common abbreviations and misspellings.
58
+
59
+ Simple
60
+
61
+ * thursday
62
+ * november
63
+ * summer
64
+ * friday 13:00
65
+ * mon 2:35
66
+ * 4pm
67
+ * 6 in the morning
68
+ * friday 1pm
69
+ * sat 7 in the evening
70
+ * yesterday
71
+ * today
72
+ * tomorrow
73
+ * this tuesday
74
+ * next month
75
+ * last winter
76
+ * this morning
77
+ * last night
78
+ * this second
79
+ * yesterday at 4:00
80
+ * last friday at 20:00
81
+ * last week tuesday
82
+ * tomorrow at 6:45pm
83
+ * afternoon yesterday
84
+ * thursday last week
85
+
86
+ Complex
87
+
88
+ * 3 years ago
89
+ * 5 months before now
90
+ * 7 hours ago
91
+ * 7 days from now
92
+ * 1 week hence
93
+ * in 3 hours
94
+ * 1 year ago tomorrow
95
+ * 3 months ago saturday at 5:00 pm
96
+ * 7 hours before tomorrow at noon
97
+ * 3rd wednesday in november
98
+ * 3rd month next year
99
+ * 3rd thursday this september
100
+ * 4th day last week
101
+ * fourteenth of june 2010 at eleven o'clock in the evening
102
+ * may seventh '97 at three in the morning
103
+
104
+ Specific Dates
105
+
106
+ * January 5
107
+ * 22nd of june
108
+ * 5th may 2017
109
+ * February twenty first
110
+ * dec 25
111
+ * may 27th
112
+ * October 2006
113
+ * oct 06
114
+ * jan 3 2010
115
+ * february 14, 2004
116
+ * february 14th, 2004
117
+ * 3 jan 2000
118
+ * 17 april 85
119
+ * 5/27/1979
120
+ * 27/5/1979
121
+ * 05/06
122
+ * 1979-05-27
123
+ * Friday
124
+ * 5
125
+ * 4:00
126
+ * 17:00
127
+ * 0800
128
+
129
+ Specific Times (many of the above with an added time)
130
+
131
+ * January 5 at 7pm
132
+ * 22nd of june at 8am
133
+ * 1979-05-27 05:00:00
134
+ * etc
135
+
136
+
137
+ ## TIME ZONES
138
+
139
+ Chronic allows you to set which Time class to use when constructing times. By
140
+ default, the built in Ruby time class creates times in your system's local
141
+ time zone. You can set this to something like ActiveSupport's
142
+ [TimeZone](http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html)
143
+ class to get full time zone support.
144
+
145
+ >> Time.zone = "UTC"
146
+ >> Chronic.time_class = Time.zone
147
+ >> Chronic.parse("June 15 2006 at 5:45 AM")
148
+ => Thu, 15 Jun 2006 05:45:00 UTC +00:00
149
+
150
+
151
+ ## LIMITATIONS
152
+
153
+ Chronic uses Ruby's built in Time class for all time storage and computation.
154
+ Because of this, only times that the Time class can handle will be properly
155
+ parsed. Parsing for times outside of this range will simply return nil.
156
+ Support for a wider range of times is planned for a future release.
157
+
158
+
159
+ ## CONTRIBUTE
160
+
161
+ If you'd like to hack on Chronic, start by forking the repo on GitHub:
162
+
163
+ https://github.com/mojombo/chronic
164
+
165
+ The best way to get your changes merged back into core is as follows:
166
+
167
+ 1. Clone down your fork
168
+ 1. Create a thoughtfully named topic branch to contain your change
169
+ 1. Hack away
170
+ 1. Add tests and make sure everything still passes by running `rake`
171
+ 1. Ensure your tests pass in multiple timezones. ie `TZ=utc rake` `TZ=BST rake`
172
+ 1. If you are adding new functionality, document it in the README
173
+ 1. Do not change the version number, we will do that on our end
174
+ 1. If necessary, rebase your commits into logical chunks, without errors
175
+ 1. Push the branch up to GitHub
176
+ 1. Send a pull request for your branch
data/Rakefile CHANGED
@@ -1,39 +1,46 @@
1
- # -*- ruby -*-
1
+ require 'date'
2
2
 
3
- require 'rubygems'
4
- require 'hoe'
5
- require './lib/chronic.rb'
6
-
7
- Hoe.new('chronic', Chronic::VERSION) do |p|
8
- p.rubyforge_name = 'chronic'
9
- p.summary = 'A natural language date parser'
10
- p.description = p.paragraphs_of('README.txt', 2).join("\n\n")
11
- p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
12
- p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
3
+ def version
4
+ contents = File.read File.expand_path('../lib/chronic.rb', __FILE__)
5
+ contents[/VERSION = "([^"]+)"/, 1]
13
6
  end
14
7
 
15
- # vim: syntax=Ruby
8
+ task :test do
9
+ $:.unshift './test'
10
+ Dir.glob('test/test_*.rb').each { |t| require File.basename(t) }
11
+ end
16
12
 
17
- __END__
13
+ desc "Generate RCov test coverage and open in your browser"
14
+ task :coverage do
15
+ require 'rcov'
16
+ sh "rm -fr coverage"
17
+ sh "rcov test/test_*.rb"
18
+ sh "open coverage/index.html"
19
+ end
18
20
 
19
- require 'rubygems'
21
+ desc "Open an irb session preloaded with this library"
22
+ task :console do
23
+ sh "irb -Ilib -rchronic"
24
+ end
20
25
 
21
- SPEC = Gem::Specification.new do |s|
22
- s.name = 'chronic'
23
- s.version = '0.1.5'
24
- s.author = 'Tom Preston-Werner'
25
- s.email = 'tom@rubyisawesome.com'
26
- s.homepage = 'http://chronic.rubyforge.org'
27
- s.platform = Gem::Platform::RUBY
28
- s.summary = "A natural language date parser"
29
- candidates = Dir["{lib,test}/**/*"]
30
- s.files = candidates.delete_if do |item|
31
- item.include?('.svn')
26
+ desc "Release Chronic version #{version}"
27
+ task :release => :build do
28
+ unless `git branch` =~ /^\* master$/
29
+ puts "You must be on the master branch to release!"
30
+ exit!
32
31
  end
33
- s.require_path = "lib"
34
- s.autorequire = "chronic"
35
- s.test_file = "test/suite.rb"
36
- s.has_rdoc = true
37
- s.extra_rdoc_files = ['README']
38
- s.rdoc_options << '--main' << 'README'
39
- end
32
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
33
+ sh "git tag v#{version}"
34
+ sh "git push origin master"
35
+ sh "git push origin v#{version}"
36
+ sh "gem push pkg/chronic-#{version}.gem"
37
+ end
38
+
39
+ desc "Build a gem from the gemspec"
40
+ task :build do
41
+ sh "mkdir -p pkg"
42
+ sh "gem build chronic.gemspec"
43
+ sh "mv chronic-#{version}.gem pkg"
44
+ end
45
+
46
+ task :default => :test
data/chronic.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+ require 'chronic'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'chronic'
6
+ s.version = Chronic::VERSION
7
+ s.rubyforge_project = 'chronic'
8
+ s.summary = 'Natural language date/time parsing.'
9
+ s.description = 'Chronic is a natural language date/time parser written in pure Ruby.'
10
+ s.authors = ['Tom Preston-Werner', 'Lee Jarvis']
11
+ s.email = ['tom@mojombo.com', 'lee@jarvis.co']
12
+ s.homepage = 'http://github.com/mojombo/chronic'
13
+ s.rdoc_options = ['--charset=UTF-8']
14
+ s.extra_rdoc_files = %w[README.md HISTORY.md LICENSE]
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- test`.split("\n")
17
+ end