ice_cube 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ice_cube/schedule.rb +20 -20
- data/lib/ice_cube/time_util.rb +18 -0
- data/lib/ice_cube/version.rb +1 -1
- metadata +11 -4
data/lib/ice_cube/schedule.rb
CHANGED
@@ -60,34 +60,34 @@ module IceCube
|
|
60
60
|
|
61
61
|
TIME_FORMAT = '%B %e, %Y'
|
62
62
|
SEPARATOR = ' / '
|
63
|
+
NEWLINE = "\n"
|
63
64
|
|
64
65
|
# use with caution
|
65
66
|
# incomplete and not entirely tested - no time representation in dates
|
66
67
|
# there's a lot that can happen here
|
67
68
|
def to_s
|
68
|
-
|
69
|
+
representation_pieces = []
|
69
70
|
inc_dates = (@rdates - @exdates).uniq
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
if @exrule_occurrence_heads && !@exrule_occurrence_heads.empty?
|
78
|
-
representation << SEPARATOR unless representation.empty?
|
79
|
-
representation << @exrule_occurrence_heads.map { |r| 'not ' << r.to_s }.join(SEPARATOR)
|
80
|
-
end
|
81
|
-
if @exdates && !@exdates.empty?
|
82
|
-
representation << SEPARATOR unless representation.empty?
|
83
|
-
representation << @exdates.uniq.sort.map { |d| 'not on ' << d.strftime(TIME_FORMAT) }.join(SEPARATOR)
|
84
|
-
end
|
85
|
-
if @end_time
|
86
|
-
representation << "until #{end_time.strftime(TIME_FORMAT)}"
|
87
|
-
end
|
88
|
-
representation
|
71
|
+
representation_pieces.concat inc_dates.sort.map { |d| d.strftime(TIME_FORMAT) } unless inc_dates.empty?
|
72
|
+
representation_pieces.concat @rrule_occurrence_heads.map{ |r| r.rule.to_s } if @rrule_occurrence_heads
|
73
|
+
representation_pieces.concat @exrule_occurrence_heads.map { |r| 'not ' << r.rule.to_s } if @exrule_occurrence_heads
|
74
|
+
representation_pieces.concat @exdates.uniq.sort.map { |d| 'not on ' << d.strftime(TIME_FORMAT) } if @exdates
|
75
|
+
representation_pieces << "until #{end_time.strftime(TIME_FORMAT)}" if @end_time
|
76
|
+
representation_pieces.join(SEPARATOR)
|
89
77
|
end
|
90
78
|
|
79
|
+
def to_ical
|
80
|
+
representation_pieces = ["DTSTART#{TimeUtil.ical_format(@start_date)}"]
|
81
|
+
representation_pieces << "DURATION:#{TimeUtil.ical_duration(@duration)}" if @duration
|
82
|
+
inc_dates = (@rdates - @exdates).uniq
|
83
|
+
representation_pieces.concat inc_dates.sort.map { |d| "RDATE#{TimeUtil.ical_format(d)}" } if inc_dates.any?
|
84
|
+
representation_pieces.concat @exdates.uniq.sort.map { |d| "EXDATE#{TimeUtil.ical_format(d)}" } if @exdates
|
85
|
+
representation_pieces.concat @rrule_occurrence_heads.map { |r| "RRULE:#{r.rule.to_ical}" } if @rrule_occurrence_heads
|
86
|
+
representation_pieces.concat @exrule_occurrence_heads.map { |r| "EXRULE:#{r.rule.to_ical}" } if @exrule_occurrence_heads
|
87
|
+
representation_pieces << "DTEND#{TimeUtil.ical_format(@end_time)}" if @end_time
|
88
|
+
representation_pieces.join(NEWLINE)
|
89
|
+
end
|
90
|
+
|
91
91
|
def occurring_at?(time)
|
92
92
|
return false if @exdates.include?(time)
|
93
93
|
return true if @rdates.include?(time)
|
data/lib/ice_cube/time_util.rb
CHANGED
@@ -27,5 +27,23 @@ module TimeUtil
|
|
27
27
|
def self.days_in_month(date)
|
28
28
|
is_leap?(date) ? LeapYearMonthDays[date.month - 1] : CommonYearMonthDays[date.month - 1]
|
29
29
|
end
|
30
|
+
|
31
|
+
def self.ical_format(time)
|
32
|
+
if time.utc?
|
33
|
+
":#{time.strftime('%Y%m%dT%H%M%SZ')}" # utc time
|
34
|
+
else
|
35
|
+
";TZID=#{time.strftime('%Z:%Y%m%dT%H%M%S')}" # local time specified
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.ical_duration(duration)
|
40
|
+
hours = duration / 3600; duration %= 3600
|
41
|
+
minutes = duration / 60; duration %= 60
|
42
|
+
repr = ''
|
43
|
+
repr << "#{hours}H" if hours > 0
|
44
|
+
repr << "#{minutes}M" if minutes > 0
|
45
|
+
repr << "#{duration}S" if duration > 0
|
46
|
+
"PT#{repr}"
|
47
|
+
end
|
30
48
|
|
31
49
|
end
|
data/lib/ice_cube/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ice_cube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
9
|
+
- 3
|
10
|
+
version: 0.4.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- John Crepezzi
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-27 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rspec
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
version: "0"
|
@@ -71,23 +74,27 @@ rdoc_options: []
|
|
71
74
|
require_paths:
|
72
75
|
- lib
|
73
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
74
78
|
requirements:
|
75
79
|
- - ">="
|
76
80
|
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
77
82
|
segments:
|
78
83
|
- 0
|
79
84
|
version: "0"
|
80
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
81
87
|
requirements:
|
82
88
|
- - ">="
|
83
89
|
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
84
91
|
segments:
|
85
92
|
- 0
|
86
93
|
version: "0"
|
87
94
|
requirements: []
|
88
95
|
|
89
96
|
rubyforge_project: ice-cube
|
90
|
-
rubygems_version: 1.3.
|
97
|
+
rubygems_version: 1.3.7
|
91
98
|
signing_key:
|
92
99
|
specification_version: 3
|
93
100
|
summary: Ruby Date Recurrence Library
|