ice_cube 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,11 +15,11 @@ module IceCube
15
15
  # Convert the schedule to a hash, reverse of Schedule.from_hash
16
16
  def to_hash
17
17
  hash = Hash.new
18
- hash[:start_date] = @start_date
18
+ hash[:start_date] = TimeUtil.serializable_time(@start_date)
19
19
  hash[:rrules] = @rrule_occurrence_heads.map { |rr| rr.rule.to_hash }
20
20
  hash[:exrules] = @exrule_occurrence_heads.map { |ex| ex.rule.to_hash }
21
- hash[:rdates] = @rdates
22
- hash[:exdates] = @exdates
21
+ hash[:rdates] = @rdates.map { |t| TimeUtil.serializable_time(t) }
22
+ hash[:exdates] = @exdates.map { |t| TimeUtil.serializable_time(t) }
23
23
  hash
24
24
  end
25
25
 
@@ -132,7 +132,7 @@ module IceCube
132
132
  @exdates << date unless date.nil?
133
133
  end
134
134
 
135
- attr_reader :rdates, :exdates
135
+ attr_reader :rdates, :exdates, :start_date
136
136
 
137
137
  def occurrences_between(begin_time, end_time)
138
138
  exclude_dates, include_dates = Set.new(@exdates), SortedSet.new(@rdates)
@@ -3,6 +3,19 @@ module TimeUtil
3
3
  LeapYearMonthDays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
4
4
  CommonYearMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
5
5
 
6
+ # this method exists because ActiveSupport will serialize
7
+ # TimeWithZone's in collections in UTC time instead of
8
+ # their local time. if +time+ is a TimeWithZone, we move
9
+ # it to a DateTime
10
+ # Note: When converting to datetime, you microseconds get set to 0
11
+ def self.serializable_time(time)
12
+ if time.respond_to?(:to_datetime)
13
+ time.to_datetime
14
+ else
15
+ time
16
+ end
17
+ end
18
+
6
19
  def self.is_leap?(date)
7
20
  (date.year % 4 == 0 && date.year % 100 != 0) || (date.year % 400 == 0)
8
21
  end
@@ -15,4 +28,4 @@ module TimeUtil
15
28
  is_leap?(date) ? LeapYearMonthDays[date.month - 1] : CommonYearMonthDays[date.month - 1]
16
29
  end
17
30
 
18
- end
31
+ end
@@ -1,5 +1,5 @@
1
1
  module IceCube
2
2
 
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
4
4
 
5
5
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Crepezzi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-27 00:00:00 -04:00
17
+ date: 2010-04-29 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency