chronic 0.4.4 → 0.5.0
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.
- data/HISTORY.md +16 -1
- data/Manifest.txt +5 -0
- data/README.md +5 -0
- data/lib/chronic.rb +3 -3
- data/lib/chronic/chronic.rb +5 -3
- data/lib/chronic/handlers.rb +21 -0
- data/lib/chronic/repeater.rb +1 -1
- data/lib/chronic/repeaters/repeater_month_name.rb +13 -20
- data/lib/chronic/repeaters/repeater_season.rb +0 -36
- data/lib/chronic/repeaters/repeater_season_name.rb +0 -2
- data/lib/chronic/season.rb +37 -0
- data/test/test_RepeaterSeason.rb +40 -0
- data/test/test_Time.rb +1 -1
- data/test/test_parsing.rb +153 -113
- metadata +27 -28
data/HISTORY.md
CHANGED
@@ -1,9 +1,24 @@
|
|
1
|
-
#
|
1
|
+
# TBA
|
2
|
+
|
3
|
+
* Replace commas with spaces instead of removing the char (Thomas Walpole)
|
4
|
+
* Added tests for RepeaterSeason
|
5
|
+
* Re-factored tests. Now rather than having a test_parsing method for testing
|
6
|
+
all handlers, break them down independent of handler method. For example
|
7
|
+
with handler `handle_sm_sd_sy` the subsequent test would be
|
8
|
+
`test_handle_sm_sd_sy`
|
9
|
+
* Added support for parsing ordinal-dates/month-names/year, ie:
|
10
|
+
`2nd of May 1995`
|
11
|
+
* Added support for parsing ordinal-dates and month names, ie:
|
12
|
+
`22nd of February at 6:30pm`
|
13
|
+
* Fix `Time.construct` leap year checking. Instead use `Date.leap?(year)`
|
14
|
+
|
15
|
+
# 0.4.4 / 2011-06-12
|
2
16
|
|
3
17
|
* Fix RepeaterYear for fetching past year offsets when the current day is
|
4
18
|
later than the last day of the same month in a past year (leap years) ie
|
5
19
|
on 29th/feb (leap year) `last year` should (and now does) return 28th/feb
|
6
20
|
instead of 1st/march
|
21
|
+
* Opt in for gem testing http://test.rubygems.org/
|
7
22
|
|
8
23
|
# 0.4.3 / 2011-06-08
|
9
24
|
|
data/Manifest.txt
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
.gemtest
|
2
|
+
.gitignore
|
3
|
+
.yardopts
|
1
4
|
HISTORY.md
|
2
5
|
LICENSE
|
3
6
|
Manifest.txt
|
@@ -30,6 +33,7 @@ lib/chronic/repeaters/repeater_weekday.rb
|
|
30
33
|
lib/chronic/repeaters/repeater_weekend.rb
|
31
34
|
lib/chronic/repeaters/repeater_year.rb
|
32
35
|
lib/chronic/scalar.rb
|
36
|
+
lib/chronic/season.rb
|
33
37
|
lib/chronic/separator.rb
|
34
38
|
lib/chronic/span.rb
|
35
39
|
lib/chronic/tag.rb
|
@@ -47,6 +51,7 @@ test/test_RepeaterHour.rb
|
|
47
51
|
test/test_RepeaterMinute.rb
|
48
52
|
test/test_RepeaterMonth.rb
|
49
53
|
test/test_RepeaterMonthName.rb
|
54
|
+
test/test_RepeaterSeason.rb
|
50
55
|
test/test_RepeaterTime.rb
|
51
56
|
test/test_RepeaterWeek.rb
|
52
57
|
test/test_RepeaterWeekday.rb
|
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
|
|
data/lib/chronic.rb
CHANGED
@@ -28,7 +28,7 @@ require 'date'
|
|
28
28
|
#
|
29
29
|
# @author Tom Preston-Werner, Lee Jarvis
|
30
30
|
module Chronic
|
31
|
-
VERSION = "0.
|
31
|
+
VERSION = "0.5.0"
|
32
32
|
|
33
33
|
class << self
|
34
34
|
|
@@ -77,6 +77,7 @@ require 'chronic/ordinal'
|
|
77
77
|
require 'chronic/separator'
|
78
78
|
require 'chronic/time_zone'
|
79
79
|
require 'chronic/numerizer'
|
80
|
+
require 'chronic/season'
|
80
81
|
|
81
82
|
require 'chronic/repeater'
|
82
83
|
require 'chronic/repeaters/repeater_year'
|
@@ -118,10 +119,9 @@ class Time
|
|
118
119
|
day <= 56 || raise("day must be no more than 56 (makes month resolution easier)")
|
119
120
|
if day > 28
|
120
121
|
# no month ever has fewer than 28 days, so only do this if necessary
|
121
|
-
leap_year = (year % 4 == 0) && !(year % 100 == 0)
|
122
122
|
leap_year_month_days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
123
123
|
common_year_month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
124
|
-
days_this_month =
|
124
|
+
days_this_month = Date.leap?(year) ? leap_year_month_days[month - 1] : common_year_month_days[month - 1]
|
125
125
|
if day > days_this_month
|
126
126
|
month += day / days_this_month
|
127
127
|
day = day % days_this_month
|
data/lib/chronic/chronic.rb
CHANGED
@@ -111,7 +111,8 @@ module Chronic
|
|
111
111
|
# @return [String] A new string ready for Chronic to parse
|
112
112
|
def pre_normalize(text)
|
113
113
|
text = text.to_s.downcase
|
114
|
-
text.gsub!(/['"
|
114
|
+
text.gsub!(/['"\.]/, '')
|
115
|
+
text.gsub!(/,/,' ')
|
115
116
|
text.gsub!(/\bsecond (of|day|month|hour|minute|second)\b/, '2nd \1')
|
116
117
|
text = numericize_numbers(text)
|
117
118
|
text.gsub!(/ \-(\d{4})\b/, ' tzminus\1')
|
@@ -180,6 +181,8 @@ module Chronic
|
|
180
181
|
Handler.new([:repeater_month_name, :scalar_day, :separator_at?, 'time?'], :handle_rmn_sd),
|
181
182
|
Handler.new([:repeater_time, :repeater_day_portion?, :separator_on?, :repeater_month_name, :scalar_day], :handle_rmn_sd_on),
|
182
183
|
Handler.new([:repeater_month_name, :ordinal_day, :separator_at?, 'time?'], :handle_rmn_od),
|
184
|
+
Handler.new([:ordinal_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_od_rmn_sy),
|
185
|
+
Handler.new([:ordinal_day, :repeater_month_name, :separator_at?, 'time?'], :handle_od_rmn),
|
183
186
|
Handler.new([:repeater_time, :repeater_day_portion?, :separator_on?, :repeater_month_name, :ordinal_day], :handle_rmn_od_on),
|
184
187
|
Handler.new([:repeater_month_name, :scalar_year], :handle_rmn_sy),
|
185
188
|
Handler.new([:scalar_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_sd_rmn_sy),
|
@@ -258,8 +261,7 @@ module Chronic
|
|
258
261
|
definitions[:arrow].each do |handler|
|
259
262
|
if handler.match(tokens, definitions)
|
260
263
|
puts "-arrow" if Chronic.debug
|
261
|
-
|
262
|
-
good_tokens = tokens.reject { |o| tags.any? { |t| o.get_tag(t) } }
|
264
|
+
good_tokens = tokens.reject { |o| o.get_tag(SeparatorAt) || o.get_tag(SeparatorSlashOrDash) || o.get_tag(SeparatorComma) }
|
263
265
|
return Handlers.send(handler.handler_method, good_tokens, options)
|
264
266
|
end
|
265
267
|
end
|
data/lib/chronic/handlers.rb
CHANGED
@@ -31,6 +31,11 @@ module Chronic
|
|
31
31
|
handle_m_d(tokens[0].get_tag(RepeaterMonthName), tokens[1].get_tag(OrdinalDay).type, tokens[2..tokens.size], options)
|
32
32
|
end
|
33
33
|
|
34
|
+
# Handle ordinal-day/repeater-month-name
|
35
|
+
def handle_od_rmn(tokens, options) #:nodoc:
|
36
|
+
handle_m_d(tokens[1].get_tag(RepeaterMonthName), tokens[0].get_tag(OrdinalDay).type, tokens[2..tokens.size], options)
|
37
|
+
end
|
38
|
+
|
34
39
|
# Handle repeater-month-name/ordinal-day with separator-on
|
35
40
|
def handle_rmn_od_on(tokens, options) #:nodoc:
|
36
41
|
if tokens.size > 3
|
@@ -98,6 +103,22 @@ module Chronic
|
|
98
103
|
end
|
99
104
|
end
|
100
105
|
|
106
|
+
# Handle oridinal-day/repeater-month-name/scalar-year
|
107
|
+
def handle_od_rmn_sy(tokens, options) #:nodoc:
|
108
|
+
day = tokens[0].get_tag(OrdinalDay).type
|
109
|
+
month = tokens[1].get_tag(RepeaterMonthName).index
|
110
|
+
year = tokens[2].get_tag(ScalarYear).type
|
111
|
+
|
112
|
+
time_tokens = tokens.last(tokens.size - 3)
|
113
|
+
|
114
|
+
begin
|
115
|
+
day_start = Chronic.time_class.local(year, month, day)
|
116
|
+
day_or_time(day_start, time_tokens, options)
|
117
|
+
rescue ArgumentError
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
101
122
|
# Handle scalar-day/repeater-month-name/scalar-year
|
102
123
|
def handle_sd_rmn_sy(tokens, options) #:nodoc:
|
103
124
|
new_tokens = [tokens[1], tokens[0], tokens[2]]
|
data/lib/chronic/repeater.rb
CHANGED
@@ -119,7 +119,7 @@ module Chronic
|
|
119
119
|
|
120
120
|
# returns the width (in seconds or months) of this repeatable.
|
121
121
|
def width
|
122
|
-
raise("
|
122
|
+
raise("Repeater#width must be overridden in subclasses")
|
123
123
|
end
|
124
124
|
|
125
125
|
# returns the next occurance of this repeatable.
|
@@ -24,25 +24,24 @@ module Chronic
|
|
24
24
|
super
|
25
25
|
|
26
26
|
if !@current_month_begin
|
27
|
-
target_month = symbol_to_number(@type)
|
28
27
|
case pointer
|
29
28
|
when :future
|
30
|
-
if @now.month <
|
31
|
-
@current_month_begin = Time.construct(@now.year,
|
32
|
-
elsif @now.month >
|
33
|
-
@current_month_begin = Time.construct(@now.year + 1,
|
29
|
+
if @now.month < index
|
30
|
+
@current_month_begin = Time.construct(@now.year, index)
|
31
|
+
elsif @now.month > index
|
32
|
+
@current_month_begin = Time.construct(@now.year + 1, index)
|
34
33
|
end
|
35
34
|
when :none
|
36
|
-
if @now.month <=
|
37
|
-
@current_month_begin = Time.construct(@now.year,
|
38
|
-
elsif @now.month >
|
39
|
-
@current_month_begin = Time.construct(@now.year + 1,
|
35
|
+
if @now.month <= index
|
36
|
+
@current_month_begin = Time.construct(@now.year, index)
|
37
|
+
elsif @now.month > index
|
38
|
+
@current_month_begin = Time.construct(@now.year + 1, index)
|
40
39
|
end
|
41
40
|
when :past
|
42
|
-
if @now.month >=
|
43
|
-
@current_month_begin = Time.construct(@now.year,
|
44
|
-
elsif @now.month <
|
45
|
-
@current_month_begin = Time.construct(@now.year - 1,
|
41
|
+
if @now.month >= index
|
42
|
+
@current_month_begin = Time.construct(@now.year, index)
|
43
|
+
elsif @now.month < index
|
44
|
+
@current_month_begin = Time.construct(@now.year - 1, index)
|
46
45
|
end
|
47
46
|
end
|
48
47
|
@current_month_begin || raise("Current month should be set by now")
|
@@ -85,17 +84,11 @@ module Chronic
|
|
85
84
|
end
|
86
85
|
|
87
86
|
def index
|
88
|
-
|
87
|
+
@index ||= MONTHS[@type]
|
89
88
|
end
|
90
89
|
|
91
90
|
def to_s
|
92
91
|
super << '-monthname-' << @type.to_s
|
93
92
|
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
def symbol_to_number(sym)
|
98
|
-
MONTHS[sym] || raise("Invalid symbol specified")
|
99
|
-
end
|
100
93
|
end
|
101
94
|
end
|
@@ -1,40 +1,4 @@
|
|
1
1
|
module Chronic
|
2
|
-
class Season
|
3
|
-
# @return [MiniDate]
|
4
|
-
attr_reader :start
|
5
|
-
|
6
|
-
# @return [MiniDate]
|
7
|
-
attr_reader :end
|
8
|
-
|
9
|
-
# @param [MiniDate] start_date
|
10
|
-
# @param [MiniDate] end_date
|
11
|
-
def initialize(start_date, end_date)
|
12
|
-
@start = start_date
|
13
|
-
@end = end_date
|
14
|
-
end
|
15
|
-
|
16
|
-
# @param [Symbol] season The season name
|
17
|
-
# @param [Integer] pointer The direction (-1 for past, 1 for future)
|
18
|
-
# @return [Symbol] The new season name
|
19
|
-
def self.find_next_season(season, pointer)
|
20
|
-
lookup = {:spring => 0, :summer => 1, :autumn => 2, :winter => 3}
|
21
|
-
next_season_num = (lookup[season] + 1 * pointer) % 4
|
22
|
-
lookup.invert[next_season_num]
|
23
|
-
end
|
24
|
-
|
25
|
-
# @param [Symbol] season The season name
|
26
|
-
# @return [Symbol] The new season name
|
27
|
-
def self.season_after(season)
|
28
|
-
find_next_season(season, +1)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @param [Symbol] season The season name
|
32
|
-
# @return [Symbol] The new season name
|
33
|
-
def self.season_before(season)
|
34
|
-
find_next_season(season, -1)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
2
|
class RepeaterSeason < Repeater #:nodoc:
|
39
3
|
SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
|
40
4
|
SEASONS = {
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Chronic
|
2
|
+
class Season
|
3
|
+
# @return [MiniDate]
|
4
|
+
attr_reader :start
|
5
|
+
|
6
|
+
# @return [MiniDate]
|
7
|
+
attr_reader :end
|
8
|
+
|
9
|
+
# @param [MiniDate] start_date
|
10
|
+
# @param [MiniDate] end_date
|
11
|
+
def initialize(start_date, end_date)
|
12
|
+
@start = start_date
|
13
|
+
@end = end_date
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [Symbol] season The season name
|
17
|
+
# @param [Integer] pointer The direction (-1 for past, 1 for future)
|
18
|
+
# @return [Symbol] The new season name
|
19
|
+
def self.find_next_season(season, pointer)
|
20
|
+
lookup = {:spring => 0, :summer => 1, :autumn => 2, :winter => 3}
|
21
|
+
next_season_num = (lookup[season] + 1 * pointer) % 4
|
22
|
+
lookup.invert[next_season_num]
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [Symbol] season The season name
|
26
|
+
# @return [Symbol] The new season name
|
27
|
+
def self.season_after(season)
|
28
|
+
find_next_season(season, +1)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param [Symbol] season The season name
|
32
|
+
# @return [Symbol] The new season name
|
33
|
+
def self.season_before(season)
|
34
|
+
find_next_season(season, -1)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[helper])
|
2
|
+
|
3
|
+
class TestRepeaterSeason < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_next_future
|
10
|
+
seasons = Chronic::RepeaterSeason.new(:season)
|
11
|
+
seasons.start = @now
|
12
|
+
|
13
|
+
next_season = seasons.next(:future)
|
14
|
+
assert_equal Time.local(2006, 9, 23), next_season.begin
|
15
|
+
assert_equal Time.local(2006, 12, 21), next_season.end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_next_past
|
19
|
+
seasons = Chronic::RepeaterSeason.new(:season)
|
20
|
+
seasons.start = @now
|
21
|
+
|
22
|
+
last_season = seasons.next(:past)
|
23
|
+
assert_equal Time.local(2006, 3, 20), last_season.begin
|
24
|
+
assert_equal Time.local(2006, 6, 20), last_season.end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_this
|
28
|
+
seasons = Chronic::RepeaterSeason.new(:season)
|
29
|
+
seasons.start = @now
|
30
|
+
|
31
|
+
this_season = seasons.this(:future)
|
32
|
+
assert_equal Time.local(2006, 8, 17), this_season.begin
|
33
|
+
assert_equal Time.local(2006, 9, 22), this_season.end
|
34
|
+
|
35
|
+
this_season = seasons.this(:past)
|
36
|
+
assert_equal Time.local(2006, 6, 21), this_season.begin
|
37
|
+
assert_equal Time.local(2006, 8, 16), this_season.end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/test/test_Time.rb
CHANGED
@@ -31,7 +31,7 @@ class TestTime < Test::Unit::TestCase
|
|
31
31
|
assert_equal Time.local(2006, 2, 1), Time.construct(2006, 1, 32)
|
32
32
|
assert_equal Time.local(2006, 3, 5), Time.construct(2006, 2, 33)
|
33
33
|
assert_equal Time.local(2004, 3, 4), Time.construct(2004, 2, 33)
|
34
|
-
assert_equal Time.local(2000, 3,
|
34
|
+
assert_equal Time.local(2000, 3, 4), Time.construct(2000, 2, 33)
|
35
35
|
|
36
36
|
assert_nothing_raised do
|
37
37
|
Time.construct(2006, 1, 56)
|
data/test/test_parsing.rb
CHANGED
@@ -8,8 +8,21 @@ class TestParsing < Test::Unit::TestCase
|
|
8
8
|
@time_2006_08_16_14_00_00 = TIME_2006_08_16_14_00_00
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def test_parse_m_d
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_handle_rmn_sd
|
15
|
+
time = parse_now("aug 3")
|
16
|
+
assert_equal Time.local(2006, 8, 3, 12), time
|
17
|
+
|
18
|
+
time = parse_now("aug 3", :context => :past)
|
19
|
+
assert_equal Time.local(2006, 8, 3, 12), time
|
20
|
+
|
21
|
+
time = parse_now("aug 20")
|
22
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
23
|
+
|
24
|
+
time = parse_now("aug 20", :context => :future)
|
25
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
13
26
|
|
14
27
|
time = parse_now("may 27")
|
15
28
|
assert_equal Time.local(2007, 5, 27, 12), time
|
@@ -25,23 +38,9 @@ class TestParsing < Test::Unit::TestCase
|
|
25
38
|
|
26
39
|
time = parse_now("may 28 at 5:32.19pm", :context => :past)
|
27
40
|
assert_equal Time.local(2006, 5, 28, 17, 32, 19), time
|
41
|
+
end
|
28
42
|
|
29
|
-
|
30
|
-
|
31
|
-
time = parse_now("aug 3")
|
32
|
-
assert_equal Time.local(2006, 8, 3, 12), time
|
33
|
-
|
34
|
-
time = parse_now("aug 3", :context => :past)
|
35
|
-
assert_equal Time.local(2006, 8, 3, 12), time
|
36
|
-
|
37
|
-
time = parse_now("aug 20")
|
38
|
-
assert_equal Time.local(2006, 8, 20, 12), time
|
39
|
-
|
40
|
-
time = parse_now("aug 20", :context => :future)
|
41
|
-
assert_equal Time.local(2006, 8, 20, 12), time
|
42
|
-
|
43
|
-
# rm_sd_on
|
44
|
-
|
43
|
+
def test_handle_rmn_sd_on
|
45
44
|
time = parse_now("5pm on may 28")
|
46
45
|
assert_equal Time.local(2007, 5, 28, 17), time
|
47
46
|
|
@@ -50,9 +49,9 @@ class TestParsing < Test::Unit::TestCase
|
|
50
49
|
|
51
50
|
time = parse_now("5 on may 28", :ambiguous_time_range => :none)
|
52
51
|
assert_equal Time.local(2007, 5, 28, 05), time
|
52
|
+
end
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
def test_handle_rmn_od
|
56
55
|
time = parse_now("may 27th")
|
57
56
|
assert_equal Time.local(2007, 5, 27, 12), time
|
58
57
|
|
@@ -67,9 +66,20 @@ class TestParsing < Test::Unit::TestCase
|
|
67
66
|
|
68
67
|
time = parse_now("may 27th at 5", :ambiguous_time_range => :none)
|
69
68
|
assert_equal Time.local(2007, 5, 27, 5), time
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_handle_od_rmn
|
72
|
+
time = parse_now("22nd February")
|
73
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
70
74
|
|
71
|
-
|
75
|
+
time = parse_now("31st of may at 6:30pm")
|
76
|
+
assert_equal Time.local(2007, 5, 31, 18, 30), time
|
72
77
|
|
78
|
+
time = parse_now("11th december 8am")
|
79
|
+
assert_equal Time.local(2006, 12, 11, 8), time
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_handle_rmn_od_on
|
73
83
|
time = parse_now("5:00 pm may 27th", :context => :past)
|
74
84
|
assert_equal Time.local(2006, 5, 27, 17), time
|
75
85
|
|
@@ -81,16 +91,65 @@ class TestParsing < Test::Unit::TestCase
|
|
81
91
|
|
82
92
|
time = parse_now("5 on may 27th", :ambiguous_time_range => :none)
|
83
93
|
assert_equal Time.local(2007, 5, 27, 5), time
|
94
|
+
end
|
84
95
|
|
85
|
-
|
96
|
+
def test_handle_rmn_sy
|
97
|
+
time = parse_now("may 97")
|
98
|
+
assert_equal Time.local(1997, 5, 16, 12), time
|
86
99
|
|
87
|
-
time = parse_now("
|
88
|
-
assert_equal Time.local(
|
100
|
+
time = parse_now("may 33", :ambiguous_year_future_bias => 10)
|
101
|
+
assert_equal Time.local(2033, 5, 16, 12), time
|
89
102
|
|
90
|
-
time = parse_now("
|
91
|
-
assert_equal Time.local(
|
103
|
+
time = parse_now("may 32")
|
104
|
+
assert_equal Time.local(2032, 5, 16, 12, 0, 0), time
|
105
|
+
end
|
92
106
|
|
93
|
-
|
107
|
+
def test_handle_rdn_rmn_sd_t_tz_sy
|
108
|
+
time = parse_now("Mon Apr 02 17:00:00 PDT 2007")
|
109
|
+
assert_equal 1175558400, time.to_i
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_handle_rmn_sd_sy
|
113
|
+
time = parse_now("November 18, 2010")
|
114
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
115
|
+
|
116
|
+
time = parse_now("Jan 1,2010")
|
117
|
+
assert_equal Time.local(2010, 1, 1, 12), time
|
118
|
+
|
119
|
+
time = parse_now("February 14, 2004")
|
120
|
+
assert_equal Time.local(2004, 2, 14, 12), time
|
121
|
+
|
122
|
+
time = parse_now("jan 3 2010")
|
123
|
+
assert_equal Time.local(2010, 1, 3, 12), time
|
124
|
+
|
125
|
+
time = parse_now("jan 3 2010 midnight")
|
126
|
+
assert_equal Time.local(2010, 1, 4, 0), time
|
127
|
+
|
128
|
+
time = parse_now("jan 3 2010 at midnight")
|
129
|
+
assert_equal Time.local(2010, 1, 4, 0), time
|
130
|
+
|
131
|
+
time = parse_now("jan 3 2010 at 4", :ambiguous_time_range => :none)
|
132
|
+
assert_equal Time.local(2010, 1, 3, 4), time
|
133
|
+
|
134
|
+
time = parse_now("may 27, 1979")
|
135
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
136
|
+
|
137
|
+
time = parse_now("may 27 79")
|
138
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
139
|
+
|
140
|
+
time = parse_now("may 27 79 4:30")
|
141
|
+
assert_equal Time.local(1979, 5, 27, 16, 30), time
|
142
|
+
|
143
|
+
time = parse_now("may 27 79 at 4:30", :ambiguous_time_range => :none)
|
144
|
+
assert_equal Time.local(1979, 5, 27, 4, 30), time
|
145
|
+
|
146
|
+
time = parse_now("may 27 32")
|
147
|
+
assert_equal Time.local(2032, 5, 27, 12, 0, 0), time
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_handle_rmn_od_sy
|
151
|
+
time = parse_now("may 1st 01")
|
152
|
+
assert_equal Time.local(2001, 5, 1, 12), time
|
94
153
|
|
95
154
|
time = parse_now("November 18th 2010")
|
96
155
|
assert_equal Time.local(2010, 11, 18, 12), time
|
@@ -121,44 +180,17 @@ class TestParsing < Test::Unit::TestCase
|
|
121
180
|
|
122
181
|
time = parse_now("March 30th 79 at 4:30", :ambiguous_time_range => :none)
|
123
182
|
assert_equal Time.local(1979, 3, 30, 4, 30), time
|
183
|
+
end
|
124
184
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
assert_equal Time.local(2010, 11, 18, 12), time
|
129
|
-
|
130
|
-
time = parse_now("February 14, 2004")
|
131
|
-
assert_equal Time.local(2004, 2, 14, 12), time
|
132
|
-
|
133
|
-
time = parse_now("jan 3 2010")
|
134
|
-
assert_equal Time.local(2010, 1, 3, 12), time
|
135
|
-
|
136
|
-
time = parse_now("jan 3 2010 midnight")
|
137
|
-
assert_equal Time.local(2010, 1, 4, 0), time
|
138
|
-
|
139
|
-
time = parse_now("jan 3 2010 at midnight")
|
140
|
-
assert_equal Time.local(2010, 1, 4, 0), time
|
141
|
-
|
142
|
-
time = parse_now("jan 3 2010 at 4", :ambiguous_time_range => :none)
|
143
|
-
assert_equal Time.local(2010, 1, 3, 4), time
|
144
|
-
|
145
|
-
#time = parse_now("January 12, '00")
|
146
|
-
#assert_equal Time.local(2000, 1, 12, 12), time
|
147
|
-
|
148
|
-
time = parse_now("may 27, 1979")
|
149
|
-
assert_equal Time.local(1979, 5, 27, 12), time
|
150
|
-
|
151
|
-
time = parse_now("may 27 79")
|
152
|
-
assert_equal Time.local(1979, 5, 27, 12), time
|
153
|
-
|
154
|
-
time = parse_now("may 27 79 4:30")
|
155
|
-
assert_equal Time.local(1979, 5, 27, 16, 30), time
|
156
|
-
|
157
|
-
time = parse_now("may 27 79 at 4:30", :ambiguous_time_range => :none)
|
158
|
-
assert_equal Time.local(1979, 5, 27, 4, 30), time
|
185
|
+
def test_handle_od_rmn_sy
|
186
|
+
time = parse_now("22nd February 2012")
|
187
|
+
assert_equal Time.local(2012, 2, 22, 12), time
|
159
188
|
|
160
|
-
|
189
|
+
time = parse_now("11th december 79")
|
190
|
+
assert_equal Time.local(1979, 12, 11, 12), time
|
191
|
+
end
|
161
192
|
|
193
|
+
def test_handle_sd_rmn_sy
|
162
194
|
time = parse_now("3 jan 2010")
|
163
195
|
assert_equal Time.local(2010, 1, 3, 12), time
|
164
196
|
|
@@ -167,36 +199,25 @@ class TestParsing < Test::Unit::TestCase
|
|
167
199
|
|
168
200
|
time = parse_now("27 Oct 2006 7:30pm")
|
169
201
|
assert_equal Time.local(2006, 10, 27, 19, 30), time
|
202
|
+
end
|
170
203
|
|
171
|
-
|
172
|
-
|
204
|
+
def test_handle_sm_sd_sy
|
173
205
|
time = parse_now("5/27/1979")
|
174
206
|
assert_equal Time.local(1979, 5, 27, 12), time
|
175
207
|
|
176
208
|
time = parse_now("5/27/1979 4am")
|
177
209
|
assert_equal Time.local(1979, 5, 27, 4), time
|
210
|
+
end
|
178
211
|
|
179
|
-
|
180
|
-
|
212
|
+
def test_handle_sd_sm_sy
|
181
213
|
time = parse_now("27/5/1979")
|
182
214
|
assert_equal Time.local(1979, 5, 27, 12), time
|
183
215
|
|
184
216
|
time = parse_now("27/5/1979 @ 0700")
|
185
217
|
assert_equal Time.local(1979, 5, 27, 7), time
|
218
|
+
end
|
186
219
|
|
187
|
-
|
188
|
-
|
189
|
-
time = parse_now("05/06")
|
190
|
-
assert_equal Time.local(2006, 5, 16, 12), time
|
191
|
-
|
192
|
-
time = parse_now("12/06")
|
193
|
-
assert_equal Time.local(2006, 12, 16, 12), time
|
194
|
-
|
195
|
-
time = parse_now("13/06")
|
196
|
-
assert_equal nil, time
|
197
|
-
|
198
|
-
# sy_sm_sd
|
199
|
-
|
220
|
+
def test_handle_sy_sm_sd
|
200
221
|
time = parse_now("2000-1-1")
|
201
222
|
assert_equal Time.local(2000, 1, 1, 12), time
|
202
223
|
|
@@ -218,43 +239,73 @@ class TestParsing < Test::Unit::TestCase
|
|
218
239
|
time = parse_now("2006-08-20 15:30.30")
|
219
240
|
assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
|
220
241
|
|
221
|
-
|
242
|
+
time = parse_now("1902-08-20")
|
243
|
+
assert_equal Time.local(1902, 8, 20, 12, 0, 0), time
|
244
|
+
end
|
222
245
|
|
223
|
-
|
224
|
-
|
246
|
+
def test_handle_sm_sy
|
247
|
+
time = parse_now("05/06")
|
248
|
+
assert_equal Time.local(2006, 5, 16, 12), time
|
225
249
|
|
226
|
-
|
227
|
-
|
228
|
-
# assert_equal now.to_s, time.to_s
|
250
|
+
time = parse_now("12/06")
|
251
|
+
assert_equal Time.local(2006, 12, 16, 12), time
|
229
252
|
|
230
|
-
|
253
|
+
time = parse_now("13/06")
|
254
|
+
assert_equal nil, time
|
255
|
+
end
|
231
256
|
|
232
|
-
|
233
|
-
|
257
|
+
def test_handle_r
|
258
|
+
end
|
234
259
|
|
235
|
-
|
260
|
+
def test_handle_r_g_r
|
261
|
+
end
|
236
262
|
|
237
|
-
|
238
|
-
|
263
|
+
def test_handle_srp
|
264
|
+
end
|
239
265
|
|
240
|
-
|
241
|
-
|
266
|
+
def test_handle_s_r_p
|
267
|
+
end
|
242
268
|
|
243
|
-
|
244
|
-
assert_equal Time.local(1800, 8, 20, 12, 0, 0), time
|
269
|
+
def test_handle_p_s_r
|
245
270
|
end
|
246
271
|
|
247
|
-
def
|
248
|
-
|
249
|
-
assert_equal Time.local(1997, 5, 16, 12), time
|
272
|
+
def test_handle_s_r_p_a
|
273
|
+
end
|
250
274
|
|
251
|
-
|
252
|
-
|
275
|
+
def test_handle_orr
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_handle_o_r_s_r
|
279
|
+
time = parse_now("3rd wednesday in november")
|
280
|
+
assert_equal Time.local(2006, 11, 15, 12), time
|
253
281
|
|
254
|
-
time = parse_now("
|
255
|
-
assert_equal
|
282
|
+
time = parse_now("10th wednesday in november")
|
283
|
+
assert_equal nil, time
|
284
|
+
|
285
|
+
# time = parse_now("3rd wednesday in 2007")
|
286
|
+
# assert_equal Time.local(2007, 1, 20, 12), time
|
256
287
|
end
|
257
288
|
|
289
|
+
def test_handle_o_r_g_r
|
290
|
+
time = parse_now("3rd month next year", :guess => false)
|
291
|
+
assert_equal Time.local(2007, 3), time.begin
|
292
|
+
|
293
|
+
time = parse_now("3rd month next year", :guess => false)
|
294
|
+
assert_equal Time.local(2007, 3, 1), time.begin
|
295
|
+
|
296
|
+
time = parse_now("3rd thursday this september")
|
297
|
+
assert_equal Time.local(2006, 9, 21, 12), time
|
298
|
+
|
299
|
+
now = Time.parse("1/10/2010")
|
300
|
+
time = parse_now("3rd thursday this november", :now => now)
|
301
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
302
|
+
|
303
|
+
time = parse_now("4th day last week")
|
304
|
+
assert_equal Time.local(2006, 8, 9, 12), time
|
305
|
+
end
|
306
|
+
|
307
|
+
# end of testing handlers
|
308
|
+
|
258
309
|
def test_parse_guess_r
|
259
310
|
time = parse_now("friday")
|
260
311
|
assert_equal Time.local(2006, 8, 18, 12), time
|
@@ -649,17 +700,6 @@ class TestParsing < Test::Unit::TestCase
|
|
649
700
|
# future
|
650
701
|
end
|
651
702
|
|
652
|
-
def test_parse_guess_o_r_s_r
|
653
|
-
time = parse_now("3rd wednesday in november")
|
654
|
-
assert_equal Time.local(2006, 11, 15, 12), time
|
655
|
-
|
656
|
-
time = parse_now("10th wednesday in november")
|
657
|
-
assert_equal nil, time
|
658
|
-
|
659
|
-
# time = parse_now("3rd wednesday in 2007")
|
660
|
-
# assert_equal Time.local(2007, 1, 20, 12), time
|
661
|
-
end
|
662
|
-
|
663
703
|
def test_parse_guess_o_r_g_r
|
664
704
|
time = parse_now("3rd month next year", :guess => false)
|
665
705
|
assert_equal Time.local(2007, 3), time.begin
|
metadata
CHANGED
@@ -1,32 +1,29 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronic
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.4.4
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Tom Preston-Werner
|
9
9
|
- Lee Jarvis
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
|
14
|
-
|
13
|
+
date: 2011-07-01 00:00:00.000000000 +01:00
|
14
|
+
default_executable:
|
15
15
|
dependencies: []
|
16
|
-
|
17
16
|
description: Chronic is a natural language date/time parser written in pure Ruby.
|
18
|
-
email:
|
17
|
+
email:
|
19
18
|
- tom@mojombo.com
|
20
19
|
- lee@jarvis.co
|
21
20
|
executables: []
|
22
|
-
|
23
21
|
extensions: []
|
24
|
-
|
25
|
-
extra_rdoc_files:
|
22
|
+
extra_rdoc_files:
|
26
23
|
- README.md
|
27
24
|
- HISTORY.md
|
28
25
|
- LICENSE
|
29
|
-
files:
|
26
|
+
files:
|
30
27
|
- .gemtest
|
31
28
|
- .gitignore
|
32
29
|
- .yardopts
|
@@ -62,6 +59,7 @@ files:
|
|
62
59
|
- lib/chronic/repeaters/repeater_weekend.rb
|
63
60
|
- lib/chronic/repeaters/repeater_year.rb
|
64
61
|
- lib/chronic/scalar.rb
|
62
|
+
- lib/chronic/season.rb
|
65
63
|
- lib/chronic/separator.rb
|
66
64
|
- lib/chronic/span.rb
|
67
65
|
- lib/chronic/tag.rb
|
@@ -79,6 +77,7 @@ files:
|
|
79
77
|
- test/test_RepeaterMinute.rb
|
80
78
|
- test/test_RepeaterMonth.rb
|
81
79
|
- test/test_RepeaterMonthName.rb
|
80
|
+
- test/test_RepeaterSeason.rb
|
82
81
|
- test/test_RepeaterTime.rb
|
83
82
|
- test/test_RepeaterWeek.rb
|
84
83
|
- test/test_RepeaterWeekday.rb
|
@@ -88,34 +87,33 @@ files:
|
|
88
87
|
- test/test_Time.rb
|
89
88
|
- test/test_Token.rb
|
90
89
|
- test/test_parsing.rb
|
90
|
+
has_rdoc: true
|
91
91
|
homepage: http://github.com/mojombo/chronic
|
92
92
|
licenses: []
|
93
|
-
|
94
93
|
post_install_message:
|
95
|
-
rdoc_options:
|
94
|
+
rdoc_options:
|
96
95
|
- --charset=UTF-8
|
97
|
-
require_paths:
|
96
|
+
require_paths:
|
98
97
|
- lib
|
99
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
99
|
none: false
|
101
|
-
requirements:
|
102
|
-
- -
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version:
|
105
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
105
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version:
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
111
110
|
requirements: []
|
112
|
-
|
113
111
|
rubyforge_project: chronic
|
114
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.6.2
|
115
113
|
signing_key:
|
116
114
|
specification_version: 3
|
117
115
|
summary: Natural language date/time parsing.
|
118
|
-
test_files:
|
116
|
+
test_files:
|
119
117
|
- test/helper.rb
|
120
118
|
- test/test_Chronic.rb
|
121
119
|
- test/test_DaylightSavings.rb
|
@@ -128,6 +126,7 @@ test_files:
|
|
128
126
|
- test/test_RepeaterMinute.rb
|
129
127
|
- test/test_RepeaterMonth.rb
|
130
128
|
- test/test_RepeaterMonthName.rb
|
129
|
+
- test/test_RepeaterSeason.rb
|
131
130
|
- test/test_RepeaterTime.rb
|
132
131
|
- test/test_RepeaterWeek.rb
|
133
132
|
- test/test_RepeaterWeekday.rb
|