chronic-mmlac 0.6.4.2

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/.gemtest +0 -0
  3. data/.gitignore +5 -0
  4. data/.yardopts +3 -0
  5. data/HISTORY.md +174 -0
  6. data/LICENSE +21 -0
  7. data/README.md +177 -0
  8. data/Rakefile +46 -0
  9. data/chronic.gemspec +17 -0
  10. data/lib/chronic/chronic.rb +325 -0
  11. data/lib/chronic/grabber.rb +31 -0
  12. data/lib/chronic/handler.rb +90 -0
  13. data/lib/chronic/handlers.rb +465 -0
  14. data/lib/chronic/mini_date.rb +38 -0
  15. data/lib/chronic/numerizer.rb +121 -0
  16. data/lib/chronic/ordinal.rb +44 -0
  17. data/lib/chronic/pointer.rb +30 -0
  18. data/lib/chronic/repeater.rb +135 -0
  19. data/lib/chronic/repeaters/repeater_day.rb +53 -0
  20. data/lib/chronic/repeaters/repeater_day_name.rb +52 -0
  21. data/lib/chronic/repeaters/repeater_day_portion.rb +94 -0
  22. data/lib/chronic/repeaters/repeater_fortnight.rb +71 -0
  23. data/lib/chronic/repeaters/repeater_hour.rb +58 -0
  24. data/lib/chronic/repeaters/repeater_minute.rb +58 -0
  25. data/lib/chronic/repeaters/repeater_month.rb +79 -0
  26. data/lib/chronic/repeaters/repeater_month_name.rb +94 -0
  27. data/lib/chronic/repeaters/repeater_season.rb +109 -0
  28. data/lib/chronic/repeaters/repeater_season_name.rb +43 -0
  29. data/lib/chronic/repeaters/repeater_second.rb +42 -0
  30. data/lib/chronic/repeaters/repeater_time.rb +128 -0
  31. data/lib/chronic/repeaters/repeater_week.rb +74 -0
  32. data/lib/chronic/repeaters/repeater_weekday.rb +85 -0
  33. data/lib/chronic/repeaters/repeater_weekend.rb +66 -0
  34. data/lib/chronic/repeaters/repeater_year.rb +77 -0
  35. data/lib/chronic/scalar.rb +109 -0
  36. data/lib/chronic/season.rb +37 -0
  37. data/lib/chronic/separator.rb +88 -0
  38. data/lib/chronic/span.rb +31 -0
  39. data/lib/chronic/tag.rb +42 -0
  40. data/lib/chronic/time_zone.rb +30 -0
  41. data/lib/chronic/token.rb +45 -0
  42. data/lib/chronic.rb +118 -0
  43. data/test/helper.rb +6 -0
  44. data/test/test_Chronic.rb +148 -0
  45. data/test/test_DaylightSavings.rb +118 -0
  46. data/test/test_Handler.rb +104 -0
  47. data/test/test_MiniDate.rb +32 -0
  48. data/test/test_Numerizer.rb +72 -0
  49. data/test/test_RepeaterDayName.rb +51 -0
  50. data/test/test_RepeaterFortnight.rb +62 -0
  51. data/test/test_RepeaterHour.rb +68 -0
  52. data/test/test_RepeaterMinute.rb +34 -0
  53. data/test/test_RepeaterMonth.rb +50 -0
  54. data/test/test_RepeaterMonthName.rb +56 -0
  55. data/test/test_RepeaterSeason.rb +40 -0
  56. data/test/test_RepeaterTime.rb +70 -0
  57. data/test/test_RepeaterWeek.rb +62 -0
  58. data/test/test_RepeaterWeekday.rb +55 -0
  59. data/test/test_RepeaterWeekend.rb +74 -0
  60. data/test/test_RepeaterYear.rb +69 -0
  61. data/test/test_Span.rb +23 -0
  62. data/test/test_Token.rb +25 -0
  63. data/test/test_parsing.rb +886 -0
  64. metadata +132 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e20903b5e5e074b8d546e3bf1b61c8f8d0c0544
4
+ data.tar.gz: ed722dfbd01535a516d80b8e97e9afb353f12b11
5
+ SHA512:
6
+ metadata.gz: 6c88b96d1239245f3162ad1dfe5b618e206b331300a69cb0457200be0ef84669cc8d0c199c189bee6e4b74c1f6fd5ae2a11618149de4a0d7d210f02be1570308
7
+ data.tar.gz: 81105ef5ab26321e3e4350fb9f8342eea33c172462c4610d1d3d49959761cb12aabba471b12b903a1d3538bb4f97957636c61073f73382d0928640368c9a215a
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,174 @@
1
+ # 0.6.4 / 2011-08-08
2
+
3
+ * Fixed bug where 'noon' was parsed as 00:00 rather than 12:00
4
+ with :ambiguous_time_range => :none (Vladimir Chernis)
5
+ * Add support for handling '2009 May 22nd'
6
+ * Add the ability to handle scalar-day/repeater-month-name as well as ordinals
7
+
8
+ # 0.6.3 / 2011-08-01
9
+
10
+ * Ensure 'thu' is parsed as Thursday for 1.8.7 generic timestamp
11
+
12
+ # 0.6.2 / 2011-07-28
13
+
14
+ * Ensure specific endian handlers are prioritised over normal date handlers
15
+ * Recognize UTC as timezone and accept HH::MM timezone offset (Jason Dusek)
16
+
17
+ # 0.6.1 / 2011-07-21
18
+
19
+ * Ensure Handler definitions are executed in the correct order
20
+
21
+ # 0.6.0 / 2011-07-19
22
+
23
+ * Attempting to parse strings with days past the last day of a month will
24
+ now return nil. ex: `Chronic.parse("30th February") #=> nil`
25
+ * All deprecated methods are marked for removal in Chronic 0.7.0
26
+ * Deprecated `Chronic.numericize_numbers` instead use
27
+ `Chronic::Numerizer.numerize`
28
+ * Deprecated `Chronic::InvalidArgumentException` and instead use
29
+ `ArgumentError`
30
+ * Deprecated `Time.construct` and use `Chronic.construct` in place of this
31
+ * Deprecated `Time#to_minidate`, instead use `Chronic::MiniDate.from_time(time)`
32
+ * Add support for handling generic timestamp for Ruby 1.9+
33
+
34
+ # 0.5.0 / 2011-07-01
35
+
36
+ * Replace commas with spaces instead of removing the char (Thomas Walpole)
37
+ * Added tests for RepeaterSeason
38
+ * Re-factored tests. Now rather than having a test_parsing method for testing
39
+ all handlers, break them down independent of handler method. For example
40
+ with handler `handle_sm_sd_sy` the subsequent test would be
41
+ `test_handle_sm_sd_sy`
42
+ * Added support for parsing ordinal-dates/month-names/year, ie:
43
+ `2nd of May 1995`
44
+ * Added support for parsing ordinal-dates and month names, ie:
45
+ `22nd of February at 6:30pm`
46
+ * Fix `Time.construct` leap year checking. Instead use `Date.leap?(year)`
47
+
48
+ # 0.4.4 / 2011-06-12
49
+
50
+ * Fix RepeaterYear for fetching past year offsets when the current day is
51
+ later than the last day of the same month in a past year (leap years) ie
52
+ on 29th/feb (leap year) `last year` should (and now does) return 28th/feb
53
+ instead of 1st/march
54
+ * Opt in for gem testing http://test.rubygems.org/
55
+
56
+ # 0.4.3 / 2011-06-08
57
+
58
+ * Fix issue with parsing 1:xxPM -- Ensure 1 is treated as ambiguous, not
59
+ just >1
60
+
61
+ # 0.4.2 / 2011-06-07
62
+
63
+ * Fix MonthRepeater for fetching past month offsets when current day is
64
+ later than the last day of a past month (ie on 29th of March when parsing
65
+ `last month` Chronic would return March instead of February. Now Chronic
66
+ returns the last day of the past month)
67
+
68
+ # 0.4.1 / 2011-06-05
69
+
70
+ * Fix MiniDate ranges for parsing seasons (Thomas Walpole)
71
+
72
+ # 0.4.0 / 2011-06-04
73
+
74
+ * Ensure context is being passed through grabbers. Now "Sunday at 2:18pm"
75
+ with `:context => :past` will return the correct date
76
+ * Support parsing ordinal strings (eg first, twenty third => 1st, 23rd)
77
+ * Seasons now ignore DST and return 00 as an hour
78
+ * Support parsing 2 digit years and added `ambiguous_year_future_bias` option
79
+ * Support parsing 'thurs' for Thursday
80
+ * Fix pre_normalize() to remove periods before numerizing
81
+ * Fix RepeaterDays to not add an extra hour in future tense. This meant
82
+ when parsing 'yesterday' after 11PM, Chronic would return today
83
+ * Discard any prefixed 0 for time strings when using post noon portion
84
+ * Gemspec updates for RubyGems deprecations
85
+ * Ensure 0:10 is treated like 00:10
86
+ * Ensure we load classes after setting Chronic class instance variables
87
+ so we can debug initialization and do assignments at compile time
88
+ * Added a Tag.scan_for method for DRYing up some scanning code
89
+ * Move some classes into their own files for maintainability
90
+ * Numerizer.andition should be a private class method, make it so
91
+ * Namespaced Numerizer, Season and MiniDate (Sascha Teske)
92
+ * Support for Ruby 1.9 (Dave Lee, Aaron Hurley)
93
+ * Fix `:context => :past` where parsed date is in current month (Marc Hedlund)
94
+ * Fix undefined variable in RepeaterHour (Ryan Garver)
95
+ * Added support for parsing 'Fourty' as another mis-spelling (Lee Reilly)
96
+ * Added ordinal format support: ie 'February 14th, 2004' (Jeff Felchner)
97
+ * Fix dates when working with daylight saving times (Mike Mangino)
98
+
99
+ # 0.3.0 / 2010-10-22
100
+
101
+ * Fix numerizer number combination bug (27 Oct 2006 7:30pm works now)
102
+ * Allow numeric timezone offset (e.g -0500)
103
+ * Disregard commas (so as to not return nil)
104
+ * Fix parse of (am|pm|oclock) separation to handle "Ham sandwich" properly
105
+ * Handle 'on' e.g. 5pm on Monday
106
+ * Support seasons
107
+ * Support weekend/weekday
108
+ * Add endianness option
109
+ * Update version number in the module
110
+ * Fix/improve logic checks in Ordinal, and Scalar
111
+ * Parse 'a' or 'p' as 'am' and 'pm' google-calendar style
112
+ * Dates < 1 are not valid
113
+ * Fix bugs related to timezone offset
114
+ * Use RakeGem for build management
115
+ * Reformat README and HISTORY to use Markdown
116
+ * Global whitespace removal
117
+
118
+ # 0.2.3
119
+
120
+ * Fix 12am/12pm
121
+
122
+ # 0.2.2
123
+
124
+ * Add missing files (damn you manifest)
125
+
126
+ # 0.2.1
127
+
128
+ * Fix time overflow issue
129
+ * Implement "next" for minute repeater
130
+ * Generalize time dealiasing to dealias regardless of day portion and
131
+ time position
132
+ * Add additional token match for cases like "friday evening at 7" and
133
+ "tomorrow evening at 7"
134
+ * Add support for Time#to_s output format: "Mon Apr 02 17:00:00 PDT 2007"
135
+
136
+ # 0.2.0 2007-03-20
137
+
138
+ * Implement numerizer, allowing the use of number words (e.g. five weeks ago)
139
+
140
+ # 0.1.6 2006-01-15
141
+
142
+ * Add 'weekend' support
143
+
144
+ # 0.1.5 2006-12-20
145
+
146
+ * Fix 'aug 20' returning next year if current month is august
147
+ * Modify behavior of 'from now'
148
+ * Add support for seconds on times, and thus db timestamp format:
149
+ "2006-12-20 18:04:23"
150
+ * Make Hoe compliant
151
+
152
+ # 0.1.4
153
+
154
+ * Remove verbose error checking code. oops. :-/
155
+
156
+ # 0.1.3
157
+
158
+ * improved regexes for word variations
159
+ * Fix a bug that caused "today at 3am" to return nil if current time is
160
+ after 3am
161
+
162
+ # 0.1.2
163
+
164
+ * Remove Date dependency (now works on windows properly without fiddling)
165
+
166
+ # 0.1.1
167
+
168
+ * Run to_s on incoming object
169
+ * Fix loop loading of repeaters files (out of order on some machines)
170
+ * Fix find_within to use this instead of next (was breaking "today at 6pm")
171
+
172
+ # 0.1.0
173
+
174
+ * 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,177 @@
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
+ To get all of the dependencies, install the gem first. The best way to get
166
+ your changes merged back into core is as follows:
167
+
168
+ 1. Clone down your fork
169
+ 1. Create a thoughtfully named topic branch to contain your change
170
+ 1. Hack away
171
+ 1. Add tests and make sure everything still passes by running `rake`
172
+ 1. Ensure your tests pass in multiple timezones
173
+ 1. If you are adding new functionality, document it in the README
174
+ 1. Do not change the version number, we will do that on our end
175
+ 1. If necessary, rebase your commits into logical chunks, without errors
176
+ 1. Push the branch up to GitHub
177
+ 1. Send a pull request for your branch
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'date'
2
+
3
+ def version
4
+ contents = File.read File.expand_path('../lib/chronic.rb', __FILE__)
5
+ contents[/VERSION = "([^"]+)"/, 1]
6
+ end
7
+
8
+ task :test do
9
+ $:.unshift './test'
10
+ Dir.glob('test/test_*.rb').each { |t| require File.basename(t) }
11
+ end
12
+
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
20
+
21
+ desc "Open an irb session preloaded with this library"
22
+ task :console do
23
+ sh "irb -Ilib -rchronic"
24
+ end
25
+
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!
31
+ 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-mmlac'
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