chronic 0.6.2 → 0.7.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/.gitignore +1 -0
- data/HISTORY.md +36 -0
- data/README.md +7 -3
- data/Rakefile +3 -5
- data/chronic.gemspec +3 -0
- data/lib/chronic/chronic.rb +78 -63
- data/lib/chronic/grabber.rb +9 -7
- data/lib/chronic/handler.rb +10 -12
- data/lib/chronic/handlers.rb +130 -3
- data/lib/chronic/ordinal.rb +12 -9
- data/lib/chronic/pointer.rb +9 -7
- data/lib/chronic/repeater.rb +29 -19
- data/lib/chronic/repeaters/repeater_day_portion.rb +29 -15
- data/lib/chronic/repeaters/repeater_time.rb +19 -19
- data/lib/chronic/repeaters/repeater_year.rb +1 -1
- data/lib/chronic/scalar.rb +30 -23
- data/lib/chronic/season.rb +1 -12
- data/lib/chronic/separator.rb +21 -15
- data/lib/chronic/tag.rb +5 -11
- data/lib/chronic/time_zone.rb +9 -7
- data/lib/chronic/token.rb +12 -10
- data/lib/chronic.rb +50 -44
- data/test/helper.rb +8 -2
- data/test/{test_Chronic.rb → test_chronic.rb} +6 -6
- data/test/{test_DaylightSavings.rb → test_daylight_savings.rb} +1 -1
- data/test/{test_Handler.rb → test_handler.rb} +1 -1
- data/test/{test_MiniDate.rb → test_mini_date.rb} +9 -9
- data/test/{test_Numerizer.rb → test_numerizer.rb} +1 -1
- data/test/test_parsing.rb +173 -14
- data/test/{test_RepeaterDayName.rb → test_repeater_day_name.rb} +1 -1
- data/test/test_repeater_day_portion.rb +254 -0
- data/test/{test_RepeaterFortnight.rb → test_repeater_fortnight.rb} +1 -1
- data/test/{test_RepeaterHour.rb → test_repeater_hour.rb} +1 -1
- data/test/{test_RepeaterMinute.rb → test_repeater_minute.rb} +1 -1
- data/test/{test_RepeaterMonth.rb → test_repeater_month.rb} +1 -1
- data/test/{test_RepeaterMonthName.rb → test_repeater_month_name.rb} +1 -1
- data/test/{test_RepeaterSeason.rb → test_repeater_season.rb} +1 -1
- data/test/{test_RepeaterTime.rb → test_repeater_time.rb} +1 -1
- data/test/{test_RepeaterWeek.rb → test_repeater_week.rb} +1 -1
- data/test/{test_RepeaterWeekday.rb → test_repeater_weekday.rb} +1 -1
- data/test/{test_RepeaterWeekend.rb → test_repeater_weekend.rb} +1 -1
- data/test/{test_RepeaterYear.rb → test_repeater_year.rb} +1 -1
- data/test/{test_Span.rb → test_span.rb} +1 -1
- data/test/{test_Token.rb → test_token.rb} +1 -1
- metadata +96 -83
- data/.gemtest +0 -0
- data/.yardopts +0 -3
data/lib/chronic.rb
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
require 'time'
|
|
2
2
|
require 'date'
|
|
3
3
|
|
|
4
|
-
# Parse natural language dates and times into Time or
|
|
4
|
+
# Parse natural language dates and times into Time or Chronic::Span objects.
|
|
5
|
+
#
|
|
6
|
+
# Examples:
|
|
5
7
|
#
|
|
6
|
-
# @example
|
|
7
8
|
# require 'chronic'
|
|
8
9
|
#
|
|
9
10
|
# Time.now #=> Sun Aug 27 23:18:25 PDT 2006
|
|
@@ -25,17 +26,16 @@ require 'date'
|
|
|
25
26
|
#
|
|
26
27
|
# Chronic.parse('may 27th', :guess => false)
|
|
27
28
|
# #=> Sun May 27 00:00:00 PDT 2007..Mon May 28 00:00:00 PDT 2007
|
|
28
|
-
#
|
|
29
|
-
# @author Tom Preston-Werner, Lee Jarvis
|
|
30
29
|
module Chronic
|
|
31
|
-
VERSION = "0.
|
|
30
|
+
VERSION = "0.7.0"
|
|
32
31
|
|
|
33
32
|
class << self
|
|
34
33
|
|
|
35
|
-
#
|
|
34
|
+
# Returns true when debug mode is enabled.
|
|
36
35
|
attr_accessor :debug
|
|
37
36
|
|
|
38
|
-
#
|
|
37
|
+
# Examples:
|
|
38
|
+
#
|
|
39
39
|
# require 'chronic'
|
|
40
40
|
# require 'active_support/time'
|
|
41
41
|
#
|
|
@@ -44,63 +44,68 @@ module Chronic
|
|
|
44
44
|
# Chronic.parse('June 15 2006 at 5:54 AM')
|
|
45
45
|
# # => Thu, 15 Jun 2006 05:45:00 UTC +00:00
|
|
46
46
|
#
|
|
47
|
-
#
|
|
47
|
+
# Returns The Time class Chronic uses internally.
|
|
48
48
|
attr_accessor :time_class
|
|
49
49
|
|
|
50
|
-
# The current Time Chronic is using to base from
|
|
50
|
+
# The current Time Chronic is using to base from.
|
|
51
|
+
#
|
|
52
|
+
# Examples:
|
|
51
53
|
#
|
|
52
|
-
# @example
|
|
53
54
|
# Time.now #=> 2011-06-06 14:13:43 +0100
|
|
54
55
|
# Chronic.parse('yesterday') #=> 2011-06-05 12:00:00 +0100
|
|
55
56
|
#
|
|
56
57
|
# now = Time.local(2025, 12, 24)
|
|
57
58
|
# Chronic.parse('tomorrow', :now => now) #=> 2025-12-25 12:00:00 +0000
|
|
58
59
|
#
|
|
59
|
-
#
|
|
60
|
+
# Returns a Time object.
|
|
60
61
|
attr_accessor :now
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
self.debug = false
|
|
64
65
|
self.time_class = Time
|
|
66
|
+
|
|
67
|
+
autoload :Handler, 'chronic/handler'
|
|
68
|
+
autoload :Handlers, 'chronic/handlers'
|
|
69
|
+
autoload :MiniDate, 'chronic/mini_date'
|
|
70
|
+
autoload :Tag, 'chronic/tag'
|
|
71
|
+
autoload :Span, 'chronic/span'
|
|
72
|
+
autoload :Token, 'chronic/token'
|
|
73
|
+
autoload :Grabber, 'chronic/grabber'
|
|
74
|
+
autoload :Pointer, 'chronic/pointer'
|
|
75
|
+
autoload :Scalar, 'chronic/scalar'
|
|
76
|
+
autoload :Ordinal, 'chronic/ordinal'
|
|
77
|
+
autoload :OrdinalDay, 'chronic/ordinal'
|
|
78
|
+
autoload :Separator, 'chronic/separator'
|
|
79
|
+
autoload :TimeZone, 'chronic/time_zone'
|
|
80
|
+
autoload :Numerizer, 'chronic/numerizer'
|
|
81
|
+
autoload :Season, 'chronic/season'
|
|
82
|
+
|
|
83
|
+
autoload :Repeater, 'chronic/repeater'
|
|
84
|
+
autoload :RepeaterYear, 'chronic/repeaters/repeater_year'
|
|
85
|
+
autoload :RepeaterSeason, 'chronic/repeaters/repeater_season'
|
|
86
|
+
autoload :RepeaterSeasonName, 'chronic/repeaters/repeater_season_name'
|
|
87
|
+
autoload :RepeaterMonth, 'chronic/repeaters/repeater_month'
|
|
88
|
+
autoload :RepeaterMonthName, 'chronic/repeaters/repeater_month_name'
|
|
89
|
+
autoload :RepeaterFortnight, 'chronic/repeaters/repeater_fortnight'
|
|
90
|
+
autoload :RepeaterWeek, 'chronic/repeaters/repeater_week'
|
|
91
|
+
autoload :RepeaterWeekend, 'chronic/repeaters/repeater_weekend'
|
|
92
|
+
autoload :RepeaterWeekday, 'chronic/repeaters/repeater_weekday'
|
|
93
|
+
autoload :RepeaterDay, 'chronic/repeaters/repeater_day'
|
|
94
|
+
autoload :RepeaterDayName, 'chronic/repeaters/repeater_day_name'
|
|
95
|
+
autoload :RepeaterDayPortion, 'chronic/repeaters/repeater_day_portion'
|
|
96
|
+
autoload :RepeaterHour, 'chronic/repeaters/repeater_hour'
|
|
97
|
+
autoload :RepeaterMinute, 'chronic/repeaters/repeater_minute'
|
|
98
|
+
autoload :RepeaterSecond, 'chronic/repeaters/repeater_second'
|
|
99
|
+
autoload :RepeaterTime, 'chronic/repeaters/repeater_time'
|
|
100
|
+
|
|
65
101
|
end
|
|
66
102
|
|
|
67
103
|
require 'chronic/chronic'
|
|
68
|
-
require 'chronic/handler'
|
|
69
|
-
require 'chronic/handlers'
|
|
70
|
-
require 'chronic/mini_date'
|
|
71
|
-
require 'chronic/tag'
|
|
72
|
-
require 'chronic/span'
|
|
73
|
-
require 'chronic/token'
|
|
74
|
-
require 'chronic/grabber'
|
|
75
|
-
require 'chronic/pointer'
|
|
76
|
-
require 'chronic/scalar'
|
|
77
|
-
require 'chronic/ordinal'
|
|
78
|
-
require 'chronic/separator'
|
|
79
|
-
require 'chronic/time_zone'
|
|
80
|
-
require 'chronic/numerizer'
|
|
81
|
-
require 'chronic/season'
|
|
82
|
-
|
|
83
|
-
require 'chronic/repeater'
|
|
84
|
-
require 'chronic/repeaters/repeater_year'
|
|
85
|
-
require 'chronic/repeaters/repeater_season'
|
|
86
|
-
require 'chronic/repeaters/repeater_season_name'
|
|
87
|
-
require 'chronic/repeaters/repeater_month'
|
|
88
|
-
require 'chronic/repeaters/repeater_month_name'
|
|
89
|
-
require 'chronic/repeaters/repeater_fortnight'
|
|
90
|
-
require 'chronic/repeaters/repeater_week'
|
|
91
|
-
require 'chronic/repeaters/repeater_weekend'
|
|
92
|
-
require 'chronic/repeaters/repeater_weekday'
|
|
93
|
-
require 'chronic/repeaters/repeater_day'
|
|
94
|
-
require 'chronic/repeaters/repeater_day_name'
|
|
95
|
-
require 'chronic/repeaters/repeater_day_portion'
|
|
96
|
-
require 'chronic/repeaters/repeater_hour'
|
|
97
|
-
require 'chronic/repeaters/repeater_minute'
|
|
98
|
-
require 'chronic/repeaters/repeater_second'
|
|
99
|
-
require 'chronic/repeaters/repeater_time'
|
|
100
104
|
|
|
101
105
|
class Time
|
|
106
|
+
|
|
102
107
|
def self.construct(year, month = 1, day = 1, hour = 0, minute = 0, second = 0)
|
|
103
|
-
warn "
|
|
108
|
+
warn "Time.construct will be deprecated in version 0.7.0. Please use Chronic.construct instead"
|
|
104
109
|
Chronic.construct(year, month, day, hour, minute, second)
|
|
105
110
|
end
|
|
106
111
|
|
|
@@ -108,4 +113,5 @@ class Time
|
|
|
108
113
|
warn "Time.to_minidate will be deprecated in version 0.7.0. Please use Chronic::MiniDate.from_time(time) instead"
|
|
109
114
|
Chronic::MiniDate.from_time(self)
|
|
110
115
|
end
|
|
116
|
+
|
|
111
117
|
end
|
data/test/helper.rb
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
unless defined? Chronic
|
|
2
|
-
$:.unshift File.expand_path('../../lib')
|
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
|
3
3
|
require 'chronic'
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
require '
|
|
6
|
+
require 'minitest/autorun'
|
|
7
|
+
|
|
8
|
+
class TestCase < MiniTest::Unit::TestCase
|
|
9
|
+
def self.test(name, &block)
|
|
10
|
+
define_method("test_#{name.gsub(/\W/, '_')}", &block) if block
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
require 'helper'
|
|
2
2
|
|
|
3
|
-
class TestChronic <
|
|
3
|
+
class TestChronic < TestCase
|
|
4
4
|
|
|
5
5
|
def setup
|
|
6
6
|
# Wed Aug 16 14:00:00 UTC 2006
|
|
7
7
|
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def test_pre_normalize
|
|
11
|
+
assert_equal Chronic.pre_normalize('12:55 pm'), Chronic.pre_normalize('12.55 pm')
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
def test_pre_normalize_numerized_string
|
|
11
15
|
string = 'two and a half years'
|
|
12
16
|
assert_equal Chronic::Numerizer.numerize(string), Chronic.pre_normalize(string)
|
|
@@ -131,11 +135,7 @@ class TestChronic < Test::Unit::TestCase
|
|
|
131
135
|
assert_equal Time.local(2004, 3, 4), Chronic.construct(2004, 2, 33)
|
|
132
136
|
assert_equal Time.local(2000, 3, 4), Chronic.construct(2000, 2, 33)
|
|
133
137
|
|
|
134
|
-
|
|
135
|
-
Chronic.construct(2006, 1, 56)
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
assert_raise(RuntimeError) do
|
|
138
|
+
assert_raises(RuntimeError) do
|
|
139
139
|
Chronic.construct(2006, 1, 57)
|
|
140
140
|
end
|
|
141
141
|
end
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
require 'helper'
|
|
2
2
|
|
|
3
|
-
class TestMiniDate <
|
|
3
|
+
class TestMiniDate < TestCase
|
|
4
4
|
def test_valid_month
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
assert_raises(ArgumentError){ Chronic::MiniDate.new(0,12) }
|
|
6
|
+
assert_raises(ArgumentError){ Chronic::MiniDate.new(13,1) }
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
def test_is_between
|
|
10
10
|
m=Chronic::MiniDate.new(3,2)
|
|
11
11
|
assert m.is_between?(Chronic::MiniDate.new(2,4), Chronic::MiniDate.new(4,7))
|
|
12
|
-
assert !m.is_between?(Chronic::MiniDate.new(1,5), Chronic::MiniDate.new(2,7))
|
|
13
|
-
|
|
12
|
+
assert !m.is_between?(Chronic::MiniDate.new(1,5), Chronic::MiniDate.new(2,7))
|
|
13
|
+
|
|
14
14
|
#There was a hang if date tested is in december and outside the testing range
|
|
15
15
|
m=Chronic::MiniDate.new(12,24)
|
|
16
16
|
assert !m.is_between?(Chronic::MiniDate.new(10,1), Chronic::MiniDate.new(12,21))
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
def test_is_between_short_range
|
|
20
20
|
m=Chronic::MiniDate.new(5,10)
|
|
21
21
|
assert m.is_between?(Chronic::MiniDate.new(5,3), Chronic::MiniDate.new(5,12))
|
|
22
22
|
assert !m.is_between?(Chronic::MiniDate.new(5,11), Chronic::MiniDate.new(5,15))
|
|
23
23
|
end
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
def test_is_between_wrapping_range
|
|
26
26
|
m=Chronic::MiniDate.new(1,1)
|
|
27
27
|
assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(2,2))
|
|
28
28
|
m=Chronic::MiniDate.new(12,12)
|
|
29
29
|
assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(1,5))
|
|
30
30
|
end
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
end
|
data/test/test_parsing.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'helper'
|
|
2
2
|
|
|
3
|
-
class TestParsing <
|
|
3
|
+
class TestParsing < TestCase
|
|
4
4
|
# Wed Aug 16 14:00:00 UTC 2006
|
|
5
5
|
TIME_2006_08_16_14_00_00 = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
|
6
6
|
|
|
@@ -76,6 +76,22 @@ class TestParsing < Test::Unit::TestCase
|
|
|
76
76
|
assert_equal Time.local(2006, 12, 11, 8), time
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
+
def test_handle_sy_rmn_od
|
|
80
|
+
time = parse_now("2009 May 22nd")
|
|
81
|
+
assert_equal Time.local(2009, 05, 22, 12), time
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_handle_sd_rmn
|
|
85
|
+
time = parse_now("22 February")
|
|
86
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
|
87
|
+
|
|
88
|
+
time = parse_now("31 of may at 6:30pm")
|
|
89
|
+
assert_equal Time.local(2007, 5, 31, 18, 30), time
|
|
90
|
+
|
|
91
|
+
time = parse_now("11 december 8am")
|
|
92
|
+
assert_equal Time.local(2006, 12, 11, 8), time
|
|
93
|
+
end
|
|
94
|
+
|
|
79
95
|
def test_handle_rmn_od_on
|
|
80
96
|
time = parse_now("5:00 pm may 27th", :context => :past)
|
|
81
97
|
assert_equal Time.local(2006, 5, 27, 17), time
|
|
@@ -222,6 +238,9 @@ class TestParsing < Test::Unit::TestCase
|
|
|
222
238
|
time = parse_now("7/12/11", :endian_precedence => :little)
|
|
223
239
|
assert_equal Time.local(2011, 12, 7, 12), time
|
|
224
240
|
|
|
241
|
+
time = parse_now("9/19/2011 6:05:57 PM")
|
|
242
|
+
assert_equal Time.local(2011, 9, 19, 18, 05, 57), time
|
|
243
|
+
|
|
225
244
|
# month day overflows
|
|
226
245
|
time = parse_now("30/2/2000")
|
|
227
246
|
assert_nil time
|
|
@@ -233,6 +252,9 @@ class TestParsing < Test::Unit::TestCase
|
|
|
233
252
|
|
|
234
253
|
time = parse_now("27/5/1979 @ 0700")
|
|
235
254
|
assert_equal Time.local(1979, 5, 27, 7), time
|
|
255
|
+
|
|
256
|
+
time = parse_now("03/18/2012 09:26 pm")
|
|
257
|
+
assert_equal Time.local(2012, 3, 18, 21, 26), time
|
|
236
258
|
end
|
|
237
259
|
|
|
238
260
|
def test_handle_sy_sm_sd
|
|
@@ -259,19 +281,34 @@ class TestParsing < Test::Unit::TestCase
|
|
|
259
281
|
|
|
260
282
|
time = parse_now("1902-08-20")
|
|
261
283
|
assert_equal Time.local(1902, 8, 20, 12, 0, 0), time
|
|
284
|
+
|
|
285
|
+
# exif date time original
|
|
286
|
+
time = parse_now("2012:05:25 22:06:50")
|
|
287
|
+
assert_equal Time.local(2012, 5, 25, 22, 6, 50), time
|
|
262
288
|
end
|
|
263
289
|
|
|
264
|
-
def
|
|
290
|
+
def test_handle_sm_sd
|
|
265
291
|
time = parse_now("05/06")
|
|
266
|
-
assert_equal Time.local(2006, 5,
|
|
292
|
+
assert_equal Time.local(2006, 5, 6, 12), time
|
|
267
293
|
|
|
268
|
-
time = parse_now("
|
|
269
|
-
assert_equal Time.local(2006,
|
|
294
|
+
time = parse_now("05/06", :endian_precedence => [:little, :medium])
|
|
295
|
+
assert_equal Time.local(2006, 6, 5, 12), time
|
|
270
296
|
|
|
271
|
-
time = parse_now("13/
|
|
272
|
-
|
|
297
|
+
time = parse_now("13/01")
|
|
298
|
+
assert_nil time
|
|
273
299
|
end
|
|
274
300
|
|
|
301
|
+
# def test_handle_sm_sy
|
|
302
|
+
# time = parse_now("05/06")
|
|
303
|
+
# assert_equal Time.local(2006, 5, 16, 12), time
|
|
304
|
+
#
|
|
305
|
+
# time = parse_now("12/06")
|
|
306
|
+
# assert_equal Time.local(2006, 12, 16, 12), time
|
|
307
|
+
#
|
|
308
|
+
# time = parse_now("13/06")
|
|
309
|
+
# assert_equal nil, time
|
|
310
|
+
# end
|
|
311
|
+
|
|
275
312
|
def test_handle_r
|
|
276
313
|
end
|
|
277
314
|
|
|
@@ -291,6 +328,19 @@ class TestParsing < Test::Unit::TestCase
|
|
|
291
328
|
end
|
|
292
329
|
|
|
293
330
|
def test_handle_orr
|
|
331
|
+
time = parse_now("5th tuesday in january")
|
|
332
|
+
assert_equal Time.local(2007, 01, 30, 12), time
|
|
333
|
+
|
|
334
|
+
time = parse_now("5th tuesday in february")
|
|
335
|
+
assert_equal nil, time
|
|
336
|
+
|
|
337
|
+
%W(jan feb march april may june july aug sep oct nov dec).each_with_index do |month, index|
|
|
338
|
+
time = parse_now("5th tuesday in #{month}")
|
|
339
|
+
|
|
340
|
+
if time then
|
|
341
|
+
assert_equal time.month, index+1
|
|
342
|
+
end
|
|
343
|
+
end
|
|
294
344
|
end
|
|
295
345
|
|
|
296
346
|
def test_handle_o_r_s_r
|
|
@@ -322,6 +372,11 @@ class TestParsing < Test::Unit::TestCase
|
|
|
322
372
|
assert_equal Time.local(2006, 8, 9, 12), time
|
|
323
373
|
end
|
|
324
374
|
|
|
375
|
+
def test_handle_sm_rmn_sy
|
|
376
|
+
time = parse_now('30-Mar-11')
|
|
377
|
+
assert_equal Time.local(2011, 3, 30, 12), time
|
|
378
|
+
end
|
|
379
|
+
|
|
325
380
|
# end of testing handlers
|
|
326
381
|
|
|
327
382
|
def test_parse_guess_r
|
|
@@ -417,11 +472,11 @@ class TestParsing < Test::Unit::TestCase
|
|
|
417
472
|
def test_parse_guess_gr
|
|
418
473
|
# year
|
|
419
474
|
|
|
420
|
-
time = parse_now("this year")
|
|
421
|
-
assert_equal Time.local(2006,
|
|
475
|
+
time = parse_now("this year", :guess => false)
|
|
476
|
+
assert_equal Time.local(2006, 8, 17), time.begin
|
|
422
477
|
|
|
423
|
-
time = parse_now("this year", :context => :past)
|
|
424
|
-
assert_equal Time.local(2006,
|
|
478
|
+
time = parse_now("this year", :context => :past, :guess => false)
|
|
479
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
|
425
480
|
|
|
426
481
|
# month
|
|
427
482
|
|
|
@@ -507,6 +562,34 @@ class TestParsing < Test::Unit::TestCase
|
|
|
507
562
|
time = parse_now("last wed")
|
|
508
563
|
assert_equal Time.local(2006, 8, 9, 12), time
|
|
509
564
|
|
|
565
|
+
monday = Time.local(2006, 8, 21, 12)
|
|
566
|
+
assert_equal monday, parse_now("mon")
|
|
567
|
+
assert_equal monday, parse_now("mun")
|
|
568
|
+
|
|
569
|
+
tuesday = Time.local(2006, 8, 22, 12)
|
|
570
|
+
assert_equal tuesday, parse_now("tue")
|
|
571
|
+
assert_equal tuesday, parse_now("tus")
|
|
572
|
+
|
|
573
|
+
wednesday = Time.local(2006, 8, 23, 12)
|
|
574
|
+
assert_equal wednesday, parse_now("wed")
|
|
575
|
+
assert_equal wednesday, parse_now("wenns")
|
|
576
|
+
|
|
577
|
+
thursday = Time.local(2006, 8, 17, 12)
|
|
578
|
+
assert_equal thursday, parse_now("thu")
|
|
579
|
+
assert_equal thursday, parse_now("thur")
|
|
580
|
+
|
|
581
|
+
friday = Time.local(2006, 8, 18, 12)
|
|
582
|
+
assert_equal friday, parse_now("fri")
|
|
583
|
+
assert_equal friday, parse_now("fry")
|
|
584
|
+
|
|
585
|
+
saturday = Time.local(2006, 8, 19, 12)
|
|
586
|
+
assert_equal saturday, parse_now("sat")
|
|
587
|
+
assert_equal saturday, parse_now("satterday")
|
|
588
|
+
|
|
589
|
+
sunday = Time.local(2006, 8, 20, 12)
|
|
590
|
+
assert_equal sunday, parse_now("sun")
|
|
591
|
+
assert_equal sunday, parse_now("sum")
|
|
592
|
+
|
|
510
593
|
# day portion
|
|
511
594
|
|
|
512
595
|
time = parse_now("this morning")
|
|
@@ -515,13 +598,33 @@ class TestParsing < Test::Unit::TestCase
|
|
|
515
598
|
time = parse_now("tonight")
|
|
516
599
|
assert_equal Time.local(2006, 8, 16, 22), time
|
|
517
600
|
|
|
601
|
+
# hour
|
|
602
|
+
|
|
603
|
+
time = parse_now("next hr")
|
|
604
|
+
assert_equal Time.local(2006, 8, 16, 15, 30, 0), time
|
|
605
|
+
|
|
606
|
+
time = parse_now("next hrs")
|
|
607
|
+
assert_equal Time.local(2006, 8, 16, 15, 30, 0), time
|
|
608
|
+
|
|
518
609
|
# minute
|
|
519
610
|
|
|
611
|
+
time = parse_now("next min")
|
|
612
|
+
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
|
613
|
+
|
|
614
|
+
time = parse_now("next mins")
|
|
615
|
+
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
|
616
|
+
|
|
520
617
|
time = parse_now("next minute")
|
|
521
618
|
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
|
522
619
|
|
|
523
620
|
# second
|
|
524
621
|
|
|
622
|
+
time = parse_now("next sec")
|
|
623
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
|
|
624
|
+
|
|
625
|
+
time = parse_now("next secs")
|
|
626
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
|
|
627
|
+
|
|
525
628
|
time = parse_now("this second")
|
|
526
629
|
assert_equal Time.local(2006, 8, 16, 14), time
|
|
527
630
|
|
|
@@ -614,6 +717,20 @@ class TestParsing < Test::Unit::TestCase
|
|
|
614
717
|
assert_equal Time.local(2006, 8, 8, 12), time
|
|
615
718
|
end
|
|
616
719
|
|
|
720
|
+
def test_parse_guess_a_ago
|
|
721
|
+
time = parse_now("AN hour ago")
|
|
722
|
+
assert_equal Time.local(2006, 8, 16, 13), time
|
|
723
|
+
|
|
724
|
+
time = parse_now("A day ago")
|
|
725
|
+
assert_equal Time.local(2006, 8, 15, 14), time
|
|
726
|
+
|
|
727
|
+
time = parse_now("a month ago")
|
|
728
|
+
assert_equal Time.local(2006, 7, 16, 14), time
|
|
729
|
+
|
|
730
|
+
time = parse_now("a year ago")
|
|
731
|
+
assert_equal Time.local(2005, 8, 16, 14), time
|
|
732
|
+
end
|
|
733
|
+
|
|
617
734
|
def test_parse_guess_s_r_p
|
|
618
735
|
# past
|
|
619
736
|
|
|
@@ -776,6 +893,7 @@ class TestParsing < Test::Unit::TestCase
|
|
|
776
893
|
assert_equal parse_now("33 days from now"), parse_now("thirty-three days from now")
|
|
777
894
|
assert_equal parse_now("2867532 seconds from now"), parse_now("two million eight hundred and sixty seven thousand five hundred and thirty two seconds from now")
|
|
778
895
|
assert_equal parse_now("may 10th"), parse_now("may tenth")
|
|
896
|
+
assert_equal parse_now("second monday in january"), parse_now("2nd monday in january")
|
|
779
897
|
end
|
|
780
898
|
|
|
781
899
|
def test_parse_only_complete_pointers
|
|
@@ -795,11 +913,11 @@ class TestParsing < Test::Unit::TestCase
|
|
|
795
913
|
end
|
|
796
914
|
|
|
797
915
|
def test_argument_validation
|
|
798
|
-
|
|
916
|
+
assert_raises(ArgumentError) do
|
|
799
917
|
time = Chronic.parse("may 27", :foo => :bar)
|
|
800
918
|
end
|
|
801
919
|
|
|
802
|
-
|
|
920
|
+
assert_raises(ArgumentError) do
|
|
803
921
|
time = Chronic.parse("may 27", :context => :bar)
|
|
804
922
|
end
|
|
805
923
|
end
|
|
@@ -855,7 +973,48 @@ class TestParsing < Test::Unit::TestCase
|
|
|
855
973
|
t1 = Chronic.parse("now")
|
|
856
974
|
sleep 0.1
|
|
857
975
|
t2 = Chronic.parse("now")
|
|
858
|
-
|
|
976
|
+
refute_equal t1, t2
|
|
977
|
+
end
|
|
978
|
+
|
|
979
|
+
def test_noon
|
|
980
|
+
t1 = Chronic.parse('2011-01-01 at noon', :ambiguous_time_range => :none)
|
|
981
|
+
assert_equal Time.local(2011, 1, 1, 12, 0), t1
|
|
982
|
+
end
|
|
983
|
+
|
|
984
|
+
def test_handle_rdn_rmn_sd
|
|
985
|
+
time = parse_now("Thu Aug 10")
|
|
986
|
+
assert_equal Time.local(2006, 8, 10, 12), time
|
|
987
|
+
|
|
988
|
+
time = parse_now("Thursday July 31")
|
|
989
|
+
assert_equal Time.local(2006, 7, 31, 12), time
|
|
990
|
+
|
|
991
|
+
time = parse_now("Thursday December 31")
|
|
992
|
+
assert_equal Time.local(2006, 12, 31, 12), time
|
|
993
|
+
end
|
|
994
|
+
|
|
995
|
+
def test_handle_rdn_rmn_sd_sy
|
|
996
|
+
time = parse_now("Thu Aug 10 2006")
|
|
997
|
+
assert_equal Time.local(2006, 8, 10, 12), time
|
|
998
|
+
|
|
999
|
+
time = parse_now("Thursday July 31 2006")
|
|
1000
|
+
assert_equal Time.local(2006, 7, 31, 12), time
|
|
1001
|
+
|
|
1002
|
+
time = parse_now("Thursday December 31 2006")
|
|
1003
|
+
assert_equal Time.local(2006, 12, 31, 12), time
|
|
1004
|
+
|
|
1005
|
+
time = parse_now("Thursday December 30 2006")
|
|
1006
|
+
assert_equal Time.local(2006, 12, 30, 12), time
|
|
1007
|
+
end
|
|
1008
|
+
|
|
1009
|
+
def test_handle_rdn_rmn_od
|
|
1010
|
+
time = parse_now("Thu Aug 10th")
|
|
1011
|
+
assert_equal Time.local(2006, 8, 10, 12), time
|
|
1012
|
+
|
|
1013
|
+
time = parse_now("Thursday July 31st")
|
|
1014
|
+
assert_equal Time.local(2006, 7, 31, 12), time
|
|
1015
|
+
|
|
1016
|
+
time = parse_now("Thursday December 31st")
|
|
1017
|
+
assert_equal Time.local(2006, 12, 31, 12), time
|
|
859
1018
|
end
|
|
860
1019
|
|
|
861
1020
|
private
|