rubyredrick-ri_cal 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/History.txt +19 -2
  2. data/Manifest.txt +6 -3
  3. data/README.txt +130 -44
  4. data/Rakefile +1 -1
  5. data/copyrights.txt +1 -2
  6. data/lib/ri_cal/component/alarm.rb +1 -2
  7. data/lib/ri_cal/component/calendar.rb +25 -9
  8. data/lib/ri_cal/component/event.rb +1 -2
  9. data/lib/ri_cal/component/freebusy.rb +1 -2
  10. data/lib/ri_cal/component/journal.rb +1 -2
  11. data/lib/ri_cal/component/t_z_info_timezone.rb +1 -2
  12. data/lib/ri_cal/component/timezone/daylight_period.rb +1 -2
  13. data/lib/ri_cal/component/timezone/standard_period.rb +1 -2
  14. data/lib/ri_cal/component/timezone/timezone_period.rb +1 -2
  15. data/lib/ri_cal/component/timezone.rb +5 -2
  16. data/lib/ri_cal/component.rb +22 -7
  17. data/lib/ri_cal/core_extensions/date/conversions.rb +8 -7
  18. data/lib/ri_cal/core_extensions/date_time.rb +4 -2
  19. data/lib/ri_cal/core_extensions/object/conversions.rb +1 -1
  20. data/lib/ri_cal/core_extensions/string/conversions.rb +37 -6
  21. data/lib/ri_cal/core_extensions/time/conversions.rb +11 -7
  22. data/lib/ri_cal/core_extensions/time/tzid_access.rb +37 -0
  23. data/lib/ri_cal/core_extensions/time.rb +3 -1
  24. data/lib/ri_cal/floating_timezone.rb +32 -0
  25. data/lib/ri_cal/invalid_property_value.rb +8 -0
  26. data/lib/ri_cal/invalid_timezone_identifer.rb +2 -2
  27. data/lib/ri_cal/occurrence_enumerator.rb +5 -3
  28. data/lib/ri_cal/parser.rb +8 -8
  29. data/lib/ri_cal/properties/alarm.rb +8 -8
  30. data/lib/ri_cal/properties/event.rb +60 -60
  31. data/lib/ri_cal/properties/freebusy.rb +16 -16
  32. data/lib/ri_cal/properties/journal.rb +58 -58
  33. data/lib/ri_cal/properties/timezone_period.rb +23 -23
  34. data/lib/ri_cal/properties/todo.rb +63 -64
  35. data/lib/ri_cal/property_value/array.rb +10 -2
  36. data/lib/ri_cal/property_value/cal_address.rb +1 -2
  37. data/lib/ri_cal/property_value/date.rb +15 -3
  38. data/lib/ri_cal/property_value/date_time/additive_methods.rb +34 -33
  39. data/lib/ri_cal/property_value/date_time/time_machine.rb +175 -174
  40. data/lib/ri_cal/property_value/date_time/timezone_support.rb +70 -52
  41. data/lib/ri_cal/property_value/date_time.rb +47 -77
  42. data/lib/ri_cal/property_value/duration.rb +6 -3
  43. data/lib/ri_cal/property_value/geo.rb +1 -2
  44. data/lib/ri_cal/property_value/integer.rb +1 -2
  45. data/lib/ri_cal/property_value/occurrence_list.rb +79 -26
  46. data/lib/ri_cal/property_value/period.rb +23 -3
  47. data/lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb +1 -2
  48. data/lib/ri_cal/property_value/recurrence_rule/enumerator.rb +1 -2
  49. data/lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb +1 -2
  50. data/lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb +1 -2
  51. data/lib/ri_cal/property_value/recurrence_rule/numbered_span.rb +1 -2
  52. data/lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb +1 -2
  53. data/lib/ri_cal/property_value/recurrence_rule/recurring_day.rb +1 -2
  54. data/lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb +1 -2
  55. data/lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb +1 -2
  56. data/lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb +1 -2
  57. data/lib/ri_cal/property_value/recurrence_rule/validations.rb +1 -2
  58. data/lib/ri_cal/property_value/recurrence_rule.rb +3 -4
  59. data/lib/ri_cal/property_value/text.rb +1 -2
  60. data/lib/ri_cal/property_value/uri.rb +1 -2
  61. data/lib/ri_cal/property_value/utc_offset.rb +1 -2
  62. data/lib/ri_cal/property_value.rb +42 -11
  63. data/lib/ri_cal/required_timezones.rb +1 -2
  64. data/lib/ri_cal.rb +1 -2
  65. data/ri_cal.gemspec +6 -4
  66. data/spec/ri_cal/component/alarm_spec.rb +1 -2
  67. data/spec/ri_cal/component/calendar_spec.rb +1 -2
  68. data/spec/ri_cal/component/event_spec.rb +168 -13
  69. data/spec/ri_cal/component/freebusy_spec.rb +1 -2
  70. data/spec/ri_cal/component/journal_spec.rb +1 -2
  71. data/spec/ri_cal/component/t_z_info_timezone_spec.rb +1 -2
  72. data/spec/ri_cal/component/timezone_spec.rb +1 -2
  73. data/spec/ri_cal/component/todo_spec.rb +4 -5
  74. data/spec/ri_cal/component_spec.rb +30 -18
  75. data/spec/ri_cal/core_extensions/string/conversions_spec.rb +78 -0
  76. data/spec/ri_cal/core_extensions/time/calculations_spec.rb +1 -2
  77. data/spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb +1 -2
  78. data/spec/ri_cal/occurrence_enumerator_spec.rb +23 -2
  79. data/spec/ri_cal/parser_spec.rb +6 -7
  80. data/spec/ri_cal/property_value/date_spec.rb +1 -2
  81. data/spec/ri_cal/property_value/date_time_spec.rb +54 -119
  82. data/spec/ri_cal/property_value/duration_spec.rb +12 -2
  83. data/spec/ri_cal/property_value/occurrence_list_spec.rb +67 -0
  84. data/spec/ri_cal/property_value/period_spec.rb +1 -2
  85. data/spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb +1 -2
  86. data/spec/ri_cal/property_value/recurrence_rule_spec.rb +1 -2
  87. data/spec/ri_cal/property_value/text_spec.rb +1 -2
  88. data/spec/ri_cal/property_value/utc_offset_spec.rb +1 -2
  89. data/spec/ri_cal/property_value_spec.rb +19 -8
  90. data/spec/ri_cal/required_timezones_spec.rb +1 -2
  91. data/spec/ri_cal_spec.rb +1 -2
  92. data/spec/spec_helper.rb +2 -7
  93. data/tasks/ri_cal.rake +20 -13
  94. data/tasks/spec.rake +1 -1
  95. metadata +8 -5
  96. data/lib/ri_cal/core_extensions/date_time/conversions.rb +0 -27
  97. data/lib/ri_cal/time_with_floating_timezone.rb +0 -59
@@ -1,179 +1,180 @@
1
1
  module RiCal
2
2
  class PropertyValue
3
- #- ©2009 Rick DeNatale
4
- #- All rights reserved. Refer to the file README.txt for the license
5
- #
6
- # Methods for DateTime which support getting values at different point in time.
7
- module TimeMachine
8
- def compute_change(d, options) # :nodoc:
9
- ::DateTime.civil(
10
- options[:year] || d.year,
11
- options[:month] || d.month,
12
- options[:day] || d.day,
13
- options[:hour] || d.hour,
14
- options[:min] || (options[:hour] ? 0 : d.min),
15
- options[:sec] || ((options[:hour] || options[:min]) ? 0 : d.sec),
16
- options[:offset] || d.offset,
17
- options[:start] || d.start
18
- )
19
- end
20
-
21
- def compute_advance(d, options) # :nodoc:
22
- d = d >> options[:years] * 12 if options[:years]
23
- d = d >> options[:months] if options[:months]
24
- d = d + options[:weeks] * 7 if options[:weeks]
25
- d = d + options[:days] if options[:days]
26
- datetime_advanced_by_date = compute_change(@date_time_value, :year => d.year, :month => d.month, :day => d.day)
27
- seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
28
- seconds_to_advance == 0 ? datetime_advanced_by_date : datetime_advanced_by_date + Rational(seconds_to_advance.round, 86400)
29
- end
30
-
31
- def advance(options) # :nodoc:
32
- PropertyValue::DateTime.new(timezone_finder,
33
- :value => compute_advance(@date_time_value, options),
34
- :tzid => tzid,
35
- :params =>(params ? params.dup : nil)
36
- )
37
- end
38
-
39
- def change(options) # :nodoc:
40
- PropertyValue::DateTime.new(timezone_finder,
41
- :value => compute_change(@date_time_value, options),
42
- :tzid => tzid,
43
- :params => (params ? params.dup : nil)
44
- )
45
- end
46
-
47
- def change_sec(new_sec) #:nodoc:
48
- PropertyValue::DateTime.civil(self.year, self.month, self.day, self.hour, self.min, sec, self.offset, self.start, params)
49
- end
50
-
51
- def change_min(new_min) #:nodoc:
52
- PropertyValue::DateTime.civil(self.year, self.month, self.day, self.hour, new_min, self.sec, self.offset, self.start, params)
53
- end
54
-
55
- def change_hour(new_hour) #:nodoc:
56
- PropertyValue::DateTime.civil(self.year, self.month, self.day, new_hour, self.min, self.sec, self.offset, self.start, params)
57
- end
58
-
59
- def change_day(new_day) #:nodoc:
60
- PropertyValue::DateTime.civil(self.year, self.month, new_day, self.hour, self.min, self.sec, self.offset, self.start, params)
61
- end
62
-
63
- def change_month(new_month) #:nodoc:
64
- PropertyValue::DateTime.civil(self.year, new_month, self.day, self.hour, self.min, self.sec, self.offset, self.start, params)
65
- end
66
-
67
- def change_year(new_year) #:nodoc:
68
- PropertyValue::DateTime.civil(new_year, self.month, self.day, self.hour, self.min, self.sec, self.offset, self.start, params)
69
- end
70
-
71
- # Return a DATE-TIME property representing the receiver on a different day (if necessary) so that
72
- # the result is within the 7 days starting with date
73
- def in_week_starting?(date)
74
- wkst_jd = date.jd
75
- @date_time_value.jd.between?(wkst_jd, wkst_jd + 6)
76
- end
77
-
78
- # Return a DATE-TIME property representing the receiver on a different day (if necessary) so that
79
- # the result is the first day of the ISO week starting on the wkst day containing the receiver.
80
- def at_start_of_week_with_wkst(wkst)
81
- date = @date_time_value.start_of_week_with_wkst(wkst)
82
- change(:year => date.year, :month => date.month, :day => date.day)
83
- end
84
- # Return a DATE_TIME value representing the first second of the minute containing the receiver
85
- def start_of_minute
86
- change(:sec => 0)
87
- end
88
-
89
- # Return a DATE_TIME value representing the last second of the minute containing the receiver
90
- def end_of_minute
91
- change(:sec => 59)
92
- end
93
-
94
- # Return a DATE_TIME value representing the first second of the hour containing the receiver
95
- def start_of_hour
96
- change(:min => 0, :sec => 0)
97
- end
98
-
99
- # Return a DATE_TIME value representing the last second of the hour containing the receiver
100
- def end_of_hour
101
- change(:min => 59, :sec => 59)
102
- end
103
-
104
- # Return a DATE_TIME value representing the first second of the day containing the receiver
105
- def start_of_day
106
- change(:hour => 0, :min => 0, :sec => 0)
107
- end
108
-
109
- # Return a DATE_TIME value representing the last second of the day containing the receiver
110
- def end_of_day
111
- change(:hour => 23, :min => 59, :sec => 59)
112
- end
113
-
114
- # Return a Ruby Date representing the first day of the ISO week starting with wkst containing the receiver
115
- def start_of_week_with_wkst(wkst)
116
- @date_time_value.start_of_week_with_wkst(wkst)
117
- end
118
-
119
- # Return a DATE_TIME value representing the last second of the ISO week starting with wkst containing the receiver
120
- def end_of_week_with_wkst(wkst)
121
- date = at_start_of_week_with_wkst(wkst).advance(:days => 6).end_of_day
122
- end
123
-
124
- # Return a DATE_TIME value representing the first second of the month containing the receiver
125
- def start_of_month
126
- change(:day => 1, :hour => 0, :min => 0, :sec => 0)
127
- end
128
-
129
- # Return a DATE_TIME value representing the last second of the month containing the receiver
130
- def end_of_month
131
- change(:day => days_in_month, :hour => 23, :min => 59, :sec => 59)
132
- end
133
-
134
- # Return a DATE_TIME value representing the first second of the month containing the receiver
135
- def start_of_year
136
- change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0)
137
- end
138
-
139
- # Return a DATE_TIME value representing the last second of the month containing the receiver
140
- def end_of_year
141
- change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59)
142
- end
143
-
144
- # Return a DATE_TIME value representing the same time on the first day of the ISO year with weeks
145
- # starting on wkst containing the receiver
146
- def at_start_of_iso_year(wkst)
147
- start_of_year = @date_time_value.iso_year_start(wkst)
148
- change(:year => start_of_year.year, :month => start_of_year.month, :day => start_of_year.day)
149
- end
150
-
151
- # Return a DATE_TIME value representing the same time on the last day of the ISO year with weeks
152
- # starting on wkst containing the receiver
153
- def at_end_of_iso_year(wkst)
154
- num_weeks = @date_time_value.iso_weeks_in_year(wkst)
155
- at_start_of_iso_year(wkst).advance(:weeks => (num_weeks - 1), :days => 6)
156
- end
157
-
158
- # Return a DATE_TIME value representing the same time on the first day of the ISO year with weeks
159
- # starting on wkst after the ISO year containing the receiver
160
- def at_start_of_next_iso_year(wkst)
161
- num_weeks = @date_time_value.iso_weeks_in_year(wkst)
162
- at_start_of_iso_year(wkst).advance(:weeks => num_weeks)
163
- end
164
-
165
- # Return a DATE_TIME value representing the last second of the last day of the ISO year with weeks
166
- # starting on wkst containing the receiver
167
- def end_of_iso_year(wkst)
168
- at_end_of_iso_year(wkst).end_of_day
169
- end
170
-
171
- # Return a DATE-TIME representing the same time, on the same day of the month in month.
172
- # If the month of the receiver has more days than the target month the last day of the target month
173
- # will be used.
174
- def in_month(month)
175
- first = change(:day => 1, :month => month)
176
- first.change(:day => [first.days_in_month, day].min)
3
+ class DateTime
4
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
5
+ #
6
+ # Methods for DateTime which support getting values at different point in time.
7
+ module TimeMachine
8
+ def compute_change(d, options) # :nodoc:
9
+ ::DateTime.civil(
10
+ options[:year] || d.year,
11
+ options[:month] || d.month,
12
+ options[:day] || d.day,
13
+ options[:hour] || d.hour,
14
+ options[:min] || (options[:hour] ? 0 : d.min),
15
+ options[:sec] || ((options[:hour] || options[:min]) ? 0 : d.sec),
16
+ options[:offset] || d.offset,
17
+ options[:start] || d.start
18
+ )
19
+ end
20
+
21
+ def compute_advance(d, options) # :nodoc:
22
+ d = d >> options[:years] * 12 if options[:years]
23
+ d = d >> options[:months] if options[:months]
24
+ d = d + options[:weeks] * 7 if options[:weeks]
25
+ d = d + options[:days] if options[:days]
26
+ datetime_advanced_by_date = compute_change(@date_time_value, :year => d.year, :month => d.month, :day => d.day)
27
+ seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
28
+ seconds_to_advance == 0 ? datetime_advanced_by_date : datetime_advanced_by_date + Rational(seconds_to_advance.round, 86400)
29
+ end
30
+
31
+ def advance(options) # :nodoc:
32
+ PropertyValue::DateTime.new(timezone_finder,
33
+ :value => compute_advance(@date_time_value, options),
34
+ :tzid => @tzid,
35
+ :params =>(params ? params.dup : nil)
36
+ )
37
+ end
38
+
39
+ def change(options) # :nodoc:
40
+ PropertyValue::DateTime.new(timezone_finder,
41
+ :value => compute_change(@date_time_value, options),
42
+ :tzid => @tzid,
43
+ :params => (params ? params.dup : nil)
44
+ )
45
+ end
46
+
47
+ def change_sec(new_sec) #:nodoc:
48
+ PropertyValue::DateTime.civil(self.year, self.month, self.day, self.hour, self.min, sec, self.offset, self.start, params)
49
+ end
50
+
51
+ def change_min(new_min) #:nodoc:
52
+ PropertyValue::DateTime.civil(self.year, self.month, self.day, self.hour, new_min, self.sec, self.offset, self.start, params)
53
+ end
54
+
55
+ def change_hour(new_hour) #:nodoc:
56
+ PropertyValue::DateTime.civil(self.year, self.month, self.day, new_hour, self.min, self.sec, self.offset, self.start, params)
57
+ end
58
+
59
+ def change_day(new_day) #:nodoc:
60
+ PropertyValue::DateTime.civil(self.year, self.month, new_day, self.hour, self.min, self.sec, self.offset, self.start, params)
61
+ end
62
+
63
+ def change_month(new_month) #:nodoc:
64
+ PropertyValue::DateTime.civil(self.year, new_month, self.day, self.hour, self.min, self.sec, self.offset, self.start, params)
65
+ end
66
+
67
+ def change_year(new_year) #:nodoc:
68
+ PropertyValue::DateTime.civil(new_year, self.month, self.day, self.hour, self.min, self.sec, self.offset, self.start, params)
69
+ end
70
+
71
+ # Return a DATE-TIME property representing the receiver on a different day (if necessary) so that
72
+ # the result is within the 7 days starting with date
73
+ def in_week_starting?(date)
74
+ wkst_jd = date.jd
75
+ @date_time_value.jd.between?(wkst_jd, wkst_jd + 6)
76
+ end
77
+
78
+ # Return a DATE-TIME property representing the receiver on a different day (if necessary) so that
79
+ # the result is the first day of the ISO week starting on the wkst day containing the receiver.
80
+ def at_start_of_week_with_wkst(wkst)
81
+ date = @date_time_value.start_of_week_with_wkst(wkst)
82
+ change(:year => date.year, :month => date.month, :day => date.day)
83
+ end
84
+ # Return a DATE_TIME value representing the first second of the minute containing the receiver
85
+ def start_of_minute
86
+ change(:sec => 0)
87
+ end
88
+
89
+ # Return a DATE_TIME value representing the last second of the minute containing the receiver
90
+ def end_of_minute
91
+ change(:sec => 59)
92
+ end
93
+
94
+ # Return a DATE_TIME value representing the first second of the hour containing the receiver
95
+ def start_of_hour
96
+ change(:min => 0, :sec => 0)
97
+ end
98
+
99
+ # Return a DATE_TIME value representing the last second of the hour containing the receiver
100
+ def end_of_hour
101
+ change(:min => 59, :sec => 59)
102
+ end
103
+
104
+ # Return a DATE_TIME value representing the first second of the day containing the receiver
105
+ def start_of_day
106
+ change(:hour => 0, :min => 0, :sec => 0)
107
+ end
108
+
109
+ # Return a DATE_TIME value representing the last second of the day containing the receiver
110
+ def end_of_day
111
+ change(:hour => 23, :min => 59, :sec => 59)
112
+ end
113
+
114
+ # Return a Ruby Date representing the first day of the ISO week starting with wkst containing the receiver
115
+ def start_of_week_with_wkst(wkst)
116
+ @date_time_value.start_of_week_with_wkst(wkst)
117
+ end
118
+
119
+ # Return a DATE_TIME value representing the last second of the ISO week starting with wkst containing the receiver
120
+ def end_of_week_with_wkst(wkst)
121
+ date = at_start_of_week_with_wkst(wkst).advance(:days => 6).end_of_day
122
+ end
123
+
124
+ # Return a DATE_TIME value representing the first second of the month containing the receiver
125
+ def start_of_month
126
+ change(:day => 1, :hour => 0, :min => 0, :sec => 0)
127
+ end
128
+
129
+ # Return a DATE_TIME value representing the last second of the month containing the receiver
130
+ def end_of_month
131
+ change(:day => days_in_month, :hour => 23, :min => 59, :sec => 59)
132
+ end
133
+
134
+ # Return a DATE_TIME value representing the first second of the month containing the receiver
135
+ def start_of_year
136
+ change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0)
137
+ end
138
+
139
+ # Return a DATE_TIME value representing the last second of the month containing the receiver
140
+ def end_of_year
141
+ change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59)
142
+ end
143
+
144
+ # Return a DATE_TIME value representing the same time on the first day of the ISO year with weeks
145
+ # starting on wkst containing the receiver
146
+ def at_start_of_iso_year(wkst)
147
+ start_of_year = @date_time_value.iso_year_start(wkst)
148
+ change(:year => start_of_year.year, :month => start_of_year.month, :day => start_of_year.day)
149
+ end
150
+
151
+ # Return a DATE_TIME value representing the same time on the last day of the ISO year with weeks
152
+ # starting on wkst containing the receiver
153
+ def at_end_of_iso_year(wkst)
154
+ num_weeks = @date_time_value.iso_weeks_in_year(wkst)
155
+ at_start_of_iso_year(wkst).advance(:weeks => (num_weeks - 1), :days => 6)
156
+ end
157
+
158
+ # Return a DATE_TIME value representing the same time on the first day of the ISO year with weeks
159
+ # starting on wkst after the ISO year containing the receiver
160
+ def at_start_of_next_iso_year(wkst)
161
+ num_weeks = @date_time_value.iso_weeks_in_year(wkst)
162
+ at_start_of_iso_year(wkst).advance(:weeks => num_weeks)
163
+ end
164
+
165
+ # Return a DATE_TIME value representing the last second of the last day of the ISO year with weeks
166
+ # starting on wkst containing the receiver
167
+ def end_of_iso_year(wkst)
168
+ at_end_of_iso_year(wkst).end_of_day
169
+ end
170
+
171
+ # Return a DATE-TIME representing the same time, on the same day of the month in month.
172
+ # If the month of the receiver has more days than the target month the last day of the target month
173
+ # will be used.
174
+ def in_month(month)
175
+ first = change(:day => 1, :month => month)
176
+ first.change(:day => [first.days_in_month, day].min)
177
+ end
177
178
  end
178
179
  end
179
180
  end
@@ -1,63 +1,81 @@
1
1
  module RiCal
2
2
  class PropertyValue
3
- #- ©2009 Rick DeNatale
4
- #- All rights reserved. Refer to the file README.txt for the license
5
- #
6
- # Time zone related ethods for DateTime
7
- module TimezoneSupport
8
- # Return the timezone id of the receiver, or nil if it is a floating time
9
- def tzid
10
- @tzid
11
- end
3
+ class DateTime
4
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
5
+ #
6
+ # Time zone related methods for DateTime
7
+ module TimezoneSupport
8
+ # Return the timezone id of the receiver, or nil if it is a floating time
9
+ def tzid
10
+ @tzid == :floating ? nil : @tzid
11
+ end
12
12
 
13
- def tzid=(string) #:nodoc:
14
- @tzid = string
15
- @timezone = nil
16
- end
13
+ def tzid=(timezone_id) #:nodoc:
14
+ timezone_id = default_tzid if timezone_id == :default
15
+ @tzid = timezone_id
16
+ @timezone = nil
17
+ end
17
18
 
18
- def timezone #:nodoc:
19
- @timezone ||= timezone_finder.find_timezone(@tzid)
20
- end
21
-
22
- # Determine if the receiver has a local time zone, i.e. it is not a floating time or a UTC time
23
- def has_local_timezone?
24
- tzid && tzid != "UTC"
25
- end
26
-
27
- # Return the receiver if it has a floating time zone already,
28
- # otherwise return a DATETIME property with the same time as the receiver but with a floating time zone
29
- def with_floating_timezone
30
- if @tzid == nil
31
- self
32
- else
33
- @date_time_value.with_floating_timezone.to_ri_cal_date_time_value
19
+ def find_timezone #:nodoc:
20
+ if @tzid == :floating
21
+ FloatingTimezone
22
+ else
23
+ timezone_finder.find_timezone(@tzid)
24
+ end
34
25
  end
35
- end
36
26
 
37
- # Returns a instance that represents the time in UTC.
38
- def utc
39
- if has_local_timezone?
40
- timezone.local_to_utc(self)
41
- else # Already local or a floating time
42
- self
27
+ def timezone #:nodoc:
28
+ @timezone ||= find_timezone
29
+ end
30
+
31
+ # Determine if the receiver has a local time zone, i.e. it is not a floating time or a UTC time
32
+ def has_local_timezone?
33
+ tzid && tzid.upcase != "UTC"
34
+ end
35
+
36
+ # Return the receiver if it has a floating time zone already,
37
+ # otherwise return a DATETIME property with the same time as the receiver but with a floating time zone
38
+ def with_floating_timezone
39
+ if @tzid == nil
40
+ self
41
+ else
42
+ @date_time_value.with_floating_timezone.to_ri_cal_date_time_value
43
+ end
44
+ end
45
+
46
+ # Returns a instance that represents the time in UTC.
47
+ def utc
48
+ if has_local_timezone?
49
+ timezone.local_to_utc(self)
50
+ else # Already local or a floating time
51
+ self
52
+ end
53
+ end
54
+
55
+ def rational_tz_offset #:nodoc:
56
+ if has_local_timezone?
57
+ timezone.rational_utc_offset(@date_time_value)
58
+ else
59
+ Rational(0,24)
60
+ end
61
+ end
62
+
63
+ # Predicate indicating whether or not the instance represents a ZULU time
64
+ def utc?
65
+ tzid == "UTC"
43
66
  end
44
- end
45
-
46
- # Predicate indicating whether or not the instance represents a ZULU time
47
- def utc?
48
- tzid == "UTC"
49
- end
50
67
 
51
- # Returns the simultaneous time in the specified zone.
52
- def in_time_zone(new_zone)
53
- new_zone = timezone_finder.find_timezone(new_zone)
54
- return self if tzid == new_zone.identifier
55
- if has_local_timezone?
56
- new_zone.utc_to_local(utc)
57
- elsif utc?
58
- new_zone.utc_to_local(self)
59
- else # Floating time
60
- DateTime.new(timezone_finder, :value => @date_time_value, :tzid => new_zone.identifier)
68
+ # Returns the simultaneous time in the specified zone.
69
+ def in_time_zone(new_zone)
70
+ new_zone = timezone_finder.find_timezone(new_zone)
71
+ return self if tzid == new_zone.identifier
72
+ if has_local_timezone?
73
+ new_zone.utc_to_local(utc)
74
+ elsif utc?
75
+ new_zone.utc_to_local(self)
76
+ else # Floating time
77
+ DateTime.new(timezone_finder, :value => @date_time_value, :tzid => new_zone.identifier)
78
+ end
61
79
  end
62
80
  end
63
81
  end