chronic 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ = 0.1.6 2006-01-15
2
+
3
+ * added 'weekend' support (eventualbuddha)
4
+
1
5
  = 0.1.5 2006-12-20
2
6
 
3
7
  * fixed 'aug 20' returning next year if current month is august
data/Rakefile CHANGED
@@ -10,6 +10,8 @@ Hoe.new('chronic', Chronic::VERSION) do |p|
10
10
  p.description = p.paragraphs_of('README.txt', 2).join("\n\n")
11
11
  p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
12
12
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
13
+ p.need_tar = false
14
+ p.extra_deps = []
13
15
  end
14
16
 
15
17
  # vim: syntax=Ruby
@@ -34,7 +34,7 @@ require 'chronic/ordinal'
34
34
  require 'chronic/separator'
35
35
 
36
36
  module Chronic
37
- VERSION = "0.1.5"
37
+ VERSION = "0.1.6"
38
38
 
39
39
  def self.debug; false; end
40
40
  end
@@ -72,7 +72,7 @@ class Chronic::Repeater < Chronic::Tag #:nodoc:
72
72
  /^months?$/ => :month,
73
73
  /^fortnights?$/ => :fortnight,
74
74
  /^weeks?$/ => :week,
75
- /^weekends?$/ => :weekends,
75
+ /^weekends?$/ => :weekend,
76
76
  /^days?$/ => :day,
77
77
  /^hours?$/ => :hour,
78
78
  /^minutes?$/ => :minute,
@@ -104,7 +104,7 @@ class Chronic::Repeater < Chronic::Tag #:nodoc:
104
104
  end
105
105
 
106
106
  def this(pointer)
107
- !@now.nil? || raise("Start point must be set before calling #next")
107
+ !@now.nil? || raise("Start point must be set before calling #this")
108
108
  [:future, :past, :none].include?(pointer) || raise("First argument 'pointer' must be one of :past, :future, :none")
109
109
  end
110
110
 
@@ -1,6 +1,55 @@
1
1
  class Chronic::RepeaterWeekend < Chronic::Repeater #:nodoc:
2
2
  WEEKEND_SECONDS = 172_800 # (2 * 24 * 60 * 60)
3
3
 
4
+ def next(pointer)
5
+ super
6
+
7
+ if !@current_week_start
8
+ case pointer
9
+ when :future
10
+ saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
11
+ saturday_repeater.start = @now
12
+ next_saturday_span = saturday_repeater.next(:future)
13
+ @current_week_start = next_saturday_span.begin
14
+ when :past
15
+ saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
16
+ saturday_repeater.start = (@now + Chronic::RepeaterDay::DAY_SECONDS)
17
+ last_saturday_span = saturday_repeater.next(:past)
18
+ @current_week_start = last_saturday_span.begin
19
+ end
20
+ else
21
+ direction = pointer == :future ? 1 : -1
22
+ @current_week_start += direction * Chronic::RepeaterWeek::WEEK_SECONDS
23
+ end
24
+
25
+ Chronic::Span.new(@current_week_start, @current_week_start + WEEKEND_SECONDS)
26
+ end
27
+
28
+ def this(pointer = :future)
29
+ super
30
+
31
+ case pointer
32
+ when :future, :none
33
+ saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
34
+ saturday_repeater.start = @now
35
+ this_saturday_span = saturday_repeater.this(:future)
36
+ Chronic::Span.new(this_saturday_span.begin, this_saturday_span.begin + WEEKEND_SECONDS)
37
+ when :past
38
+ saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
39
+ saturday_repeater.start = @now
40
+ last_saturday_span = saturday_repeater.this(:past)
41
+ Chronic::Span.new(last_saturday_span.begin, last_saturday_span.begin + WEEKEND_SECONDS)
42
+ end
43
+ end
44
+
45
+ def offset(span, amount, pointer)
46
+ direction = pointer == :future ? 1 : -1
47
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
48
+ weekend.start = span.begin
49
+ start = weekend.next(pointer).begin + (amount - 1) * direction * Chronic::RepeaterWeek::WEEK_SECONDS
50
+ Chronic::Span.new(start, start + (span.end - span.begin))
51
+ end
52
+
4
53
  def width
5
54
  WEEKEND_SECONDS
6
55
  end
@@ -0,0 +1,75 @@
1
+ require 'chronic'
2
+ require 'test/unit'
3
+
4
+ class TestRepeaterWeekend < Test::Unit::TestCase
5
+
6
+ def setup
7
+ # Wed Aug 16 14:00:00 2006
8
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
9
+ end
10
+
11
+ def test_next_future
12
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
13
+ weekend.start = @now
14
+
15
+ next_weekend = weekend.next(:future)
16
+ assert_equal Time.local(2006, 8, 19), next_weekend.begin
17
+ assert_equal Time.local(2006, 8, 21), next_weekend.end
18
+ end
19
+
20
+ def test_next_past
21
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
22
+ weekend.start = @now
23
+
24
+ next_weekend = weekend.next(:past)
25
+ assert_equal Time.local(2006, 8, 12), next_weekend.begin
26
+ assert_equal Time.local(2006, 8, 14), next_weekend.end
27
+ end
28
+
29
+ def test_this_future
30
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
31
+ weekend.start = @now
32
+
33
+ next_weekend = weekend.this(:future)
34
+ assert_equal Time.local(2006, 8, 19), next_weekend.begin
35
+ assert_equal Time.local(2006, 8, 21), next_weekend.end
36
+ end
37
+
38
+ def test_this_past
39
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
40
+ weekend.start = @now
41
+
42
+ next_weekend = weekend.this(:past)
43
+ assert_equal Time.local(2006, 8, 12), next_weekend.begin
44
+ assert_equal Time.local(2006, 8, 14), next_weekend.end
45
+ end
46
+
47
+ def test_this_none
48
+ weekend = Chronic::RepeaterWeekend.new(:weekend)
49
+ weekend.start = @now
50
+
51
+ next_weekend = weekend.this(:future)
52
+ assert_equal Time.local(2006, 8, 19), next_weekend.begin
53
+ assert_equal Time.local(2006, 8, 21), next_weekend.end
54
+ end
55
+
56
+ def test_offset
57
+ span = Chronic::Span.new(@now, @now + 1)
58
+
59
+ offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 3, :future)
60
+
61
+ assert_equal Time.local(2006, 9, 2), offset_span.begin
62
+ assert_equal Time.local(2006, 9, 2, 0, 0, 1), offset_span.end
63
+
64
+ offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 1, :past)
65
+
66
+ assert_equal Time.local(2006, 8, 12), offset_span.begin
67
+ assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
68
+
69
+ offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 0, :future)
70
+
71
+ assert_equal Time.local(2006, 8, 12), offset_span.begin
72
+ assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
73
+ end
74
+
75
+ end
@@ -254,6 +254,17 @@ class TestParsing < Test::Unit::TestCase
254
254
  time = Chronic.parse("this week", :now => @time_2006_08_16_14_00_00, :context => :past)
255
255
  assert_equal Time.local(2006, 8, 14, 19), time
256
256
 
257
+ # weekend
258
+
259
+ time = Chronic.parse("this weekend", :now => @time_2006_08_16_14_00_00)
260
+ assert_equal Time.local(2006, 8, 20), time
261
+
262
+ time = Chronic.parse("this weekend", :now => @time_2006_08_16_14_00_00, :context => :past)
263
+ assert_equal Time.local(2006, 8, 13), time
264
+
265
+ time = Chronic.parse("last weekend", :now => @time_2006_08_16_14_00_00)
266
+ assert_equal Time.local(2006, 8, 13), time
267
+
257
268
  # day
258
269
 
259
270
  time = Chronic.parse("this day", :now => @time_2006_08_16_14_00_00)
@@ -386,6 +397,9 @@ class TestParsing < Test::Unit::TestCase
386
397
  time = Chronic.parse("3 weeks ago", :now => @time_2006_08_16_14_00_00)
387
398
  assert_equal Time.local(2006, 7, 26, 14, 30, 30), time
388
399
 
400
+ time = Chronic.parse("2 weekends ago", :now => @time_2006_08_16_14_00_00)
401
+ assert_equal Time.local(2006, 8, 5), time
402
+
389
403
  time = Chronic.parse("3 days ago", :now => @time_2006_08_16_14_00_00)
390
404
  assert_equal Time.local(2006, 8, 13, 14), time
391
405
 
@@ -418,6 +432,12 @@ class TestParsing < Test::Unit::TestCase
418
432
  time = Chronic.parse("1 week from now", :now => @time_2006_08_16_14_00_00)
419
433
  assert_equal Time.local(2006, 8, 23, 14, 0, 0), time
420
434
 
435
+ time = Chronic.parse("1 weekend from now", :now => @time_2006_08_16_14_00_00)
436
+ assert_equal Time.local(2006, 8, 19), time
437
+
438
+ time = Chronic.parse("2 weekends from now", :now => @time_2006_08_16_14_00_00)
439
+ assert_equal Time.local(2006, 8, 26), time
440
+
421
441
  time = Chronic.parse("1 day hence", :now => @time_2006_08_16_14_00_00)
422
442
  assert_equal Time.local(2006, 8, 17, 14), time
423
443
 
@@ -492,6 +512,10 @@ class TestParsing < Test::Unit::TestCase
492
512
  span = Chronic.parse("november", :now => @time_2006_08_16_14_00_00, :guess => false)
493
513
  assert_equal Time.local(2006, 11), span.begin
494
514
  assert_equal Time.local(2006, 12), span.end
515
+
516
+ span = Chronic.parse("weekend" , :now => @time_2006_08_16_14_00_00, :guess => false)
517
+ assert_equal Time.local(2006, 8, 19), span.begin
518
+ assert_equal Time.local(2006, 8, 21), span.end
495
519
  end
496
520
 
497
521
  def test_argument_validation
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: chronic
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.5
7
- date: 2006-12-21 00:00:00 -08:00
6
+ version: 0.1.6
7
+ date: 2007-01-15 00:00:00 -08:00
8
8
  summary: A natural language date parser
9
9
  require_paths:
10
10
  - lib
@@ -82,6 +82,7 @@ test_files:
82
82
  - test/test_RepeaterMonthName.rb
83
83
  - test/test_RepeaterTime.rb
84
84
  - test/test_RepeaterWeek.rb
85
+ - test/test_RepeaterWeekend.rb
85
86
  - test/test_RepeaterYear.rb
86
87
  - test/test_Span.rb
87
88
  - test/test_Token.rb
@@ -95,13 +96,5 @@ extensions: []
95
96
 
96
97
  requirements: []
97
98
 
98
- dependencies:
99
- - !ruby/object:Gem::Dependency
100
- name: hoe
101
- version_requirement:
102
- version_requirements: !ruby/object:Gem::Version::Requirement
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: 1.1.6
107
- version:
99
+ dependencies: []
100
+