chronic 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/chronic.rb CHANGED
@@ -7,8 +7,6 @@
7
7
  #
8
8
  #=============================================================================
9
9
 
10
- require 'date'
11
-
12
10
  require 'chronic/chronic'
13
11
  require 'chronic/handlers'
14
12
 
@@ -4,10 +4,14 @@ class Chronic::RepeaterDay < Chronic::Repeater #:nodoc:
4
4
  def next(pointer)
5
5
  super
6
6
 
7
- @current_day ||= Date.parse(@now.to_s)
8
- @current_day += pointer == :future ? 1 : -1
9
- span_begin = Time.parse(@current_day.to_s)
10
- Chronic::Span.new(span_begin, span_begin + width)
7
+ if !@current_day_start
8
+ @current_day_start = Time.local(@now.year, @now.month, @now.day)
9
+ end
10
+
11
+ direction = pointer == :future ? 1 : -1
12
+ @current_day_start += direction * DAY_SECONDS
13
+
14
+ Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
11
15
  end
12
16
 
13
17
  def this(pointer = :future)
@@ -4,18 +4,22 @@ class Chronic::RepeaterDayName < Chronic::Repeater #:nodoc:
4
4
  def next(pointer)
5
5
  super
6
6
 
7
- if !@current_day
8
- @current_day = Date.parse(@now.to_s)
9
- @current_day += pointer == :future ? 1 : -1
7
+ direction = pointer == :future ? 1 : -1
8
+
9
+ if !@current_day_start
10
+ @current_day_start = Time.local(@now.year, @now.month, @now.day)
11
+ @current_day_start += direction * DAY_SECONDS
12
+
10
13
  day_num = symbol_to_number(@type)
11
- while @current_day.wday != day_num
12
- @current_day += pointer == :future ? 1 : -1
14
+
15
+ while @current_day_start.wday != day_num
16
+ @current_day_start += direction * DAY_SECONDS
13
17
  end
14
18
  else
15
- @current_day += pointer == :future ? 7 : -7
19
+ @current_day_start += direction * 7 * DAY_SECONDS
16
20
  end
17
- span_begin = Time.parse(@current_day.to_s)
18
- Chronic::Span.new(span_begin, span_begin + width)
21
+
22
+ Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
19
23
  end
20
24
 
21
25
  def this(pointer = :future)
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.1
7
- date: 2006-09-09 00:00:00 -07:00
6
+ version: 0.1.2
7
+ date: 2006-09-16 00:00:00 -07:00
8
8
  summary: A natural language date parser
9
9
  require_paths:
10
10
  - lib