chronic 0.4.1 → 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 (64) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +5 -0
  3. data/.yardopts +3 -0
  4. data/HISTORY.md +75 -2
  5. data/README.md +10 -5
  6. data/Rakefile +12 -106
  7. data/chronic.gemspec +12 -78
  8. data/lib/chronic/chronic.rb +271 -101
  9. data/lib/chronic/grabber.rb +12 -3
  10. data/lib/chronic/handler.rb +90 -0
  11. data/lib/chronic/handlers.rb +247 -295
  12. data/lib/chronic/mini_date.rb +15 -5
  13. data/lib/chronic/numerizer.rb +3 -2
  14. data/lib/chronic/ordinal.rb +15 -4
  15. data/lib/chronic/pointer.rb +13 -5
  16. data/lib/chronic/repeater.rb +31 -15
  17. data/lib/chronic/repeaters/repeater_day.rb +6 -7
  18. data/lib/chronic/repeaters/repeater_day_name.rb +1 -2
  19. data/lib/chronic/repeaters/repeater_day_portion.rb +12 -13
  20. data/lib/chronic/repeaters/repeater_fortnight.rb +2 -3
  21. data/lib/chronic/repeaters/repeater_hour.rb +7 -8
  22. data/lib/chronic/repeaters/repeater_minute.rb +6 -7
  23. data/lib/chronic/repeaters/repeater_month.rb +22 -11
  24. data/lib/chronic/repeaters/repeater_month_name.rb +16 -24
  25. data/lib/chronic/repeaters/repeater_season.rb +10 -29
  26. data/lib/chronic/repeaters/repeater_season_name.rb +2 -4
  27. data/lib/chronic/repeaters/repeater_second.rb +0 -1
  28. data/lib/chronic/repeaters/repeater_time.rb +19 -20
  29. data/lib/chronic/repeaters/repeater_week.rb +0 -1
  30. data/lib/chronic/repeaters/repeater_weekday.rb +1 -2
  31. data/lib/chronic/repeaters/repeater_weekend.rb +0 -1
  32. data/lib/chronic/repeaters/repeater_year.rb +29 -18
  33. data/lib/chronic/scalar.rb +29 -1
  34. data/lib/chronic/season.rb +37 -0
  35. data/lib/chronic/separator.rb +24 -7
  36. data/lib/chronic/tag.rb +12 -1
  37. data/lib/chronic/time_zone.rb +14 -5
  38. data/lib/chronic/token.rb +14 -4
  39. data/lib/chronic.rb +66 -89
  40. data/test/helper.rb +1 -1
  41. data/test/test_Chronic.rb +97 -3
  42. data/test/test_DaylightSavings.rb +1 -1
  43. data/test/test_Handler.rb +1 -6
  44. data/test/test_MiniDate.rb +3 -3
  45. data/test/test_Numerizer.rb +1 -1
  46. data/test/test_RepeaterDayName.rb +1 -1
  47. data/test/test_RepeaterFortnight.rb +1 -1
  48. data/test/test_RepeaterHour.rb +1 -1
  49. data/test/test_RepeaterMinute.rb +1 -1
  50. data/test/test_RepeaterMonth.rb +5 -1
  51. data/test/test_RepeaterMonthName.rb +1 -1
  52. data/test/test_RepeaterSeason.rb +40 -0
  53. data/test/test_RepeaterTime.rb +1 -1
  54. data/test/test_RepeaterWeek.rb +1 -1
  55. data/test/test_RepeaterWeekday.rb +1 -1
  56. data/test/test_RepeaterWeekend.rb +1 -1
  57. data/test/test_RepeaterYear.rb +8 -1
  58. data/test/test_Span.rb +1 -1
  59. data/test/test_Token.rb +1 -1
  60. data/test/test_parsing.rb +228 -117
  61. metadata +30 -32
  62. data/Manifest.txt +0 -59
  63. data/benchmark/benchmark.rb +0 -13
  64. data/test/test_Time.rb +0 -49
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 CHANGED
@@ -1,4 +1,77 @@
1
- # 0.4.1
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
2
75
 
3
76
  * Fix MiniDate ranges for parsing seasons (Thomas Walpole)
4
77
 
@@ -27,7 +100,7 @@
27
100
  * Fix undefined variable in RepeaterHour (Ryan Garver)
28
101
  * Added support for parsing 'Fourty' as another mis-spelling (Lee Reilly)
29
102
  * Added ordinal format support: ie 'February 14th, 2004' (Jeff Felchner)
30
- * Fix dates when working with daylight saving times Mike Mangino
103
+ * Fix dates when working with daylight saving times (Mike Mangino)
31
104
 
32
105
  # 0.3.0 / 2010-10-22
33
106
 
data/README.md CHANGED
@@ -98,10 +98,14 @@ Complex
98
98
  * 3rd month next year
99
99
  * 3rd thursday this september
100
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
101
103
 
102
104
  Specific Dates
103
105
 
104
106
  * January 5
107
+ * 22nd of june
108
+ * 5th may 2017
105
109
  * February twenty first
106
110
  * dec 25
107
111
  * may 27th
@@ -125,6 +129,7 @@ Specific Dates
125
129
  Specific Times (many of the above with an added time)
126
130
 
127
131
  * January 5 at 7pm
132
+ * 22nd of june at 8am
128
133
  * 1979-05-27 05:00:00
129
134
  * etc
130
135
 
@@ -133,8 +138,9 @@ Specific Times (many of the above with an added time)
133
138
 
134
139
  Chronic allows you to set which Time class to use when constructing times. By
135
140
  default, the built in Ruby time class creates times in your system's local
136
- time zone. You can set this to something like ActiveSupport's TimeZone class
137
- to get full time zone support.
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.
138
144
 
139
145
  >> Time.zone = "UTC"
140
146
  >> Chronic.time_class = Time.zone
@@ -156,14 +162,13 @@ If you'd like to hack on Chronic, start by forking the repo on GitHub:
156
162
 
157
163
  https://github.com/mojombo/chronic
158
164
 
159
- To get all of the dependencies, install the gem first. The best way to get
160
- your changes merged back into core is as follows:
165
+ The best way to get your changes merged back into core is as follows:
161
166
 
162
167
  1. Clone down your fork
163
168
  1. Create a thoughtfully named topic branch to contain your change
164
169
  1. Hack away
165
170
  1. Add tests and make sure everything still passes by running `rake`
166
- 1. Ensure your tests pass in multiple timezones
171
+ 1. Ensure your tests pass in multiple timezones. ie `TZ=utc rake` `TZ=BST rake`
167
172
  1. If you are adding new functionality, document it in the README
168
173
  1. Do not change the version number, we will do that on our end
169
174
  1. If necessary, rebase your commits into logical chunks, without errors
data/Rakefile CHANGED
@@ -1,49 +1,13 @@
1
1
  require 'date'
2
2
 
3
- #############################################################################
4
- #
5
- # Helper functions
6
- #
7
- #############################################################################
8
-
9
- def name
10
- @name ||= Dir['*.gemspec'].first.split('.').first
11
- end
12
-
13
3
  def version
14
- line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
15
- line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
16
- end
17
-
18
- def rubyforge_project
19
- name
20
- end
21
-
22
- def gemspec_file
23
- "#{name}.gemspec"
4
+ contents = File.read File.expand_path('../lib/chronic.rb', __FILE__)
5
+ contents[/VERSION = "([^"]+)"/, 1]
24
6
  end
25
7
 
26
- def gem_file
27
- "#{name}-#{version}.gem"
28
- end
29
-
30
- def replace_header(head, header_name)
31
- head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
32
- end
33
-
34
- #############################################################################
35
- #
36
- # Standard tasks
37
- #
38
- #############################################################################
39
-
40
- task :default => :test
41
-
42
- require 'rake/testtask'
43
- Rake::TestTask.new(:test) do |test|
44
- test.libs << 'lib' << 'test'
45
- test.pattern = 'test/**/test_*.rb'
46
- test.verbose = true
8
+ task :test do
9
+ $:.unshift './test'
10
+ Dir.glob('test/test_*.rb').each { |t| require File.basename(t) }
47
11
  end
48
12
 
49
13
  desc "Generate RCov test coverage and open in your browser"
@@ -54,33 +18,12 @@ task :coverage do
54
18
  sh "open coverage/index.html"
55
19
  end
56
20
 
57
- require 'rake/rdoctask'
58
- Rake::RDocTask.new do |rdoc|
59
- rdoc.rdoc_dir = 'rdoc'
60
- rdoc.title = "#{name} #{version}"
61
- rdoc.rdoc_files.include('README*')
62
- rdoc.rdoc_files.include('lib/**/*.rb')
63
- end
64
-
65
21
  desc "Open an irb session preloaded with this library"
66
22
  task :console do
67
23
  sh "irb -Ilib -rchronic"
68
24
  end
69
25
 
70
- #############################################################################
71
- #
72
- # Custom tasks (add your own tasks here)
73
- #
74
- #############################################################################
75
-
76
-
77
-
78
- #############################################################################
79
- #
80
- # Packaging tasks
81
- #
82
- #############################################################################
83
-
26
+ desc "Release Chronic version #{version}"
84
27
  task :release => :build do
85
28
  unless `git branch` =~ /^\* master$/
86
29
  puts "You must be on the master branch to release!"
@@ -90,51 +33,14 @@ task :release => :build do
90
33
  sh "git tag v#{version}"
91
34
  sh "git push origin master"
92
35
  sh "git push origin v#{version}"
93
- sh "gem push pkg/#{name}-#{version}.gem"
36
+ sh "gem push pkg/chronic-#{version}.gem"
94
37
  end
95
38
 
96
- task :build => :gemspec do
39
+ desc "Build a gem from the gemspec"
40
+ task :build do
97
41
  sh "mkdir -p pkg"
98
- sh "gem build #{gemspec_file}"
99
- sh "mv #{gem_file} pkg"
100
- end
101
-
102
- task :gemspec => :validate do
103
- # read spec file and split out manifest section
104
- spec = File.read(gemspec_file)
105
- head, manifest, tail = spec.split(" # = MANIFEST =\n")
106
-
107
- # replace name version and date
108
- replace_header(head, :name)
109
- replace_header(head, :version)
110
-
111
- #comment this out if your rubyforge_project has a different name
112
- replace_header(head, :rubyforge_project)
113
-
114
- # determine file list from git ls-files
115
- files = `git ls-files`.
116
- split("\n").
117
- sort.
118
- reject { |file| file =~ /^\./ }.
119
- reject { |file| file =~ /^(rdoc|pkg)/ }.
120
- map { |file| " #{file}" }.
121
- join("\n")
122
-
123
- # piece file back together and write
124
- manifest = " s.files = %w[\n#{files}\n ]\n"
125
- spec = [head, manifest, tail].join(" # = MANIFEST =\n")
126
- File.open(gemspec_file, 'w') { |io| io.write(spec) }
127
- puts "Updated #{gemspec_file}"
42
+ sh "gem build chronic.gemspec"
43
+ sh "mv chronic-#{version}.gem pkg"
128
44
  end
129
45
 
130
- task :validate do
131
- libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
132
- unless libfiles.empty?
133
- puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
134
- exit!
135
- end
136
- unless Dir['VERSION*'].empty?
137
- puts "A `VERSION` file at root level violates Gem best practices."
138
- exit!
139
- end
140
- end
46
+ task :default => :test
data/chronic.gemspec CHANGED
@@ -1,83 +1,17 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+ require 'chronic'
3
+
1
4
  Gem::Specification.new do |s|
2
- s.name = 'chronic'
3
- s.version = '0.4.1'
5
+ s.name = 'chronic'
6
+ s.version = Chronic::VERSION
4
7
  s.rubyforge_project = 'chronic'
5
-
6
- s.summary = "Natural language date/time parsing."
7
- s.description = "Chronic is a natural language date/time parser written in pure Ruby."
8
-
9
- s.authors = ["Tom Preston-Werner", "Lee Jarvis"]
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']
10
11
  s.email = ['tom@mojombo.com', 'lee@jarvis.co']
11
12
  s.homepage = 'http://github.com/mojombo/chronic'
12
-
13
- s.rdoc_options = ["--charset=UTF-8"]
13
+ s.rdoc_options = ['--charset=UTF-8']
14
14
  s.extra_rdoc_files = %w[README.md HISTORY.md LICENSE]
15
-
16
- # = MANIFEST =
17
- s.files = %w[
18
- HISTORY.md
19
- LICENSE
20
- Manifest.txt
21
- README.md
22
- Rakefile
23
- benchmark/benchmark.rb
24
- chronic.gemspec
25
- lib/chronic.rb
26
- lib/chronic/chronic.rb
27
- lib/chronic/grabber.rb
28
- lib/chronic/handlers.rb
29
- lib/chronic/mini_date.rb
30
- lib/chronic/numerizer.rb
31
- lib/chronic/ordinal.rb
32
- lib/chronic/pointer.rb
33
- lib/chronic/repeater.rb
34
- lib/chronic/repeaters/repeater_day.rb
35
- lib/chronic/repeaters/repeater_day_name.rb
36
- lib/chronic/repeaters/repeater_day_portion.rb
37
- lib/chronic/repeaters/repeater_fortnight.rb
38
- lib/chronic/repeaters/repeater_hour.rb
39
- lib/chronic/repeaters/repeater_minute.rb
40
- lib/chronic/repeaters/repeater_month.rb
41
- lib/chronic/repeaters/repeater_month_name.rb
42
- lib/chronic/repeaters/repeater_season.rb
43
- lib/chronic/repeaters/repeater_season_name.rb
44
- lib/chronic/repeaters/repeater_second.rb
45
- lib/chronic/repeaters/repeater_time.rb
46
- lib/chronic/repeaters/repeater_week.rb
47
- lib/chronic/repeaters/repeater_weekday.rb
48
- lib/chronic/repeaters/repeater_weekend.rb
49
- lib/chronic/repeaters/repeater_year.rb
50
- lib/chronic/scalar.rb
51
- lib/chronic/separator.rb
52
- lib/chronic/span.rb
53
- lib/chronic/tag.rb
54
- lib/chronic/time_zone.rb
55
- lib/chronic/token.rb
56
- test/helper.rb
57
- test/test_Chronic.rb
58
- test/test_DaylightSavings.rb
59
- test/test_Handler.rb
60
- test/test_MiniDate.rb
61
- test/test_Numerizer.rb
62
- test/test_RepeaterDayName.rb
63
- test/test_RepeaterFortnight.rb
64
- test/test_RepeaterHour.rb
65
- test/test_RepeaterMinute.rb
66
- test/test_RepeaterMonth.rb
67
- test/test_RepeaterMonthName.rb
68
- test/test_RepeaterTime.rb
69
- test/test_RepeaterWeek.rb
70
- test/test_RepeaterWeekday.rb
71
- test/test_RepeaterWeekend.rb
72
- test/test_RepeaterYear.rb
73
- test/test_Span.rb
74
- test/test_Time.rb
75
- test/test_Token.rb
76
- test/test_parsing.rb
77
- ]
78
- # = MANIFEST =
79
-
80
- ## Test files will be grabbed from the file list. Make sure the path glob
81
- ## matches what you actually use.
82
- s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
83
- end
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- test`.split("\n")
17
+ end