tilia-vobject 4.0.0.pre.alpha5 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.sabre.md +59 -2
- data/Gemfile +1 -8
- data/Gemfile.lock +18 -12
- data/LICENSE +1 -1
- data/LICENSE.sabre +1 -1
- data/lib/tilia/v_object.rb +1 -0
- data/lib/tilia/v_object/birthday_calendar_generator.rb +11 -11
- data/lib/tilia/v_object/cli.rb +39 -38
- data/lib/tilia/v_object/component.rb +47 -50
- data/lib/tilia/v_object/component/available.rb +4 -37
- data/lib/tilia/v_object/component/v_alarm.rb +6 -18
- data/lib/tilia/v_object/component/v_availability.rb +6 -39
- data/lib/tilia/v_object/component/v_calendar.rb +66 -98
- data/lib/tilia/v_object/component/v_card.rb +42 -69
- data/lib/tilia/v_object/component/v_event.rb +5 -17
- data/lib/tilia/v_object/component/v_free_busy.rb +4 -16
- data/lib/tilia/v_object/component/v_journal.rb +16 -16
- data/lib/tilia/v_object/component/v_time_zone.rb +2 -14
- data/lib/tilia/v_object/component/v_todo.rb +17 -36
- data/lib/tilia/v_object/date_time_parser.rb +24 -24
- data/lib/tilia/v_object/document.rb +25 -25
- data/lib/tilia/v_object/free_busy_data.rb +7 -7
- data/lib/tilia/v_object/free_busy_generator.rb +73 -75
- data/lib/tilia/v_object/i_tip.rb +1 -0
- data/lib/tilia/v_object/i_tip/broker.rb +134 -116
- data/lib/tilia/v_object/i_tip/i_tip_exception.rb +1 -1
- data/lib/tilia/v_object/i_tip/message.rb +13 -13
- data/lib/tilia/v_object/invalid_data_exception.rb +8 -0
- data/lib/tilia/v_object/node.rb +22 -27
- data/lib/tilia/v_object/parameter.rb +22 -22
- data/lib/tilia/v_object/parse_exception.rb +1 -1
- data/lib/tilia/v_object/parser.rb +1 -0
- data/lib/tilia/v_object/parser/json.rb +9 -19
- data/lib/tilia/v_object/parser/mime_dir.rb +73 -39
- data/lib/tilia/v_object/parser/parser.rb +9 -14
- data/lib/tilia/v_object/parser/xml.rb +33 -50
- data/lib/tilia/v_object/parser/xml/element.rb +1 -0
- data/lib/tilia/v_object/parser/xml/element/key_value.rb +2 -2
- data/lib/tilia/v_object/property.rb +52 -52
- data/lib/tilia/v_object/property/binary.rb +10 -10
- data/lib/tilia/v_object/property/boolean.rb +6 -6
- data/lib/tilia/v_object/property/flat_text.rb +3 -3
- data/lib/tilia/v_object/property/float_value.rb +10 -10
- data/lib/tilia/v_object/property/i_calendar.rb +1 -0
- data/lib/tilia/v_object/property/i_calendar/cal_address.rb +3 -3
- data/lib/tilia/v_object/property/i_calendar/date_time.rb +29 -57
- data/lib/tilia/v_object/property/i_calendar/duration.rb +6 -6
- data/lib/tilia/v_object/property/i_calendar/period.rb +10 -10
- data/lib/tilia/v_object/property/i_calendar/recur.rb +16 -24
- data/lib/tilia/v_object/property/integer_value.rb +8 -8
- data/lib/tilia/v_object/property/text.rb +21 -36
- data/lib/tilia/v_object/property/time.rb +29 -6
- data/lib/tilia/v_object/property/unknown.rb +2 -2
- data/lib/tilia/v_object/property/uri.rb +24 -5
- data/lib/tilia/v_object/property/utc_offset.rb +5 -5
- data/lib/tilia/v_object/property/v_card.rb +1 -0
- data/lib/tilia/v_object/property/v_card/date.rb +3 -3
- data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +30 -42
- data/lib/tilia/v_object/property/v_card/date_time.rb +1 -1
- data/lib/tilia/v_object/property/v_card/language_tag.rb +4 -4
- data/lib/tilia/v_object/property/v_card/time_stamp.rb +5 -5
- data/lib/tilia/v_object/reader.rb +12 -11
- data/lib/tilia/v_object/recur.rb +2 -0
- data/lib/tilia/v_object/recur/event_iterator.rb +30 -27
- data/lib/tilia/v_object/recur/max_instances_exceeded_exception.rb +10 -0
- data/lib/tilia/v_object/recur/no_instances_exception.rb +1 -1
- data/lib/tilia/v_object/recur/r_date_iterator.rb +15 -41
- data/lib/tilia/v_object/recur/r_rule_iterator.rb +23 -156
- data/lib/tilia/v_object/settings.rb +16 -0
- data/lib/tilia/v_object/splitter.rb +1 -0
- data/lib/tilia/v_object/splitter/i_calendar.rb +5 -5
- data/lib/tilia/v_object/splitter/splitter_interface.rb +2 -2
- data/lib/tilia/v_object/splitter/v_card.rb +5 -5
- data/lib/tilia/v_object/string_util.rb +25 -9
- data/lib/tilia/v_object/time_zone_data.rb +1 -0
- data/lib/tilia/v_object/time_zone_util.rb +6 -6
- data/lib/tilia/v_object/uuid_util.rb +3 -3
- data/lib/tilia/v_object/v_card_converter.rb +24 -21
- data/lib/tilia/v_object/version.rb +1 -1
- data/lib/tilia/v_object/writer.rb +7 -7
- data/test/test_helper.rb +3 -3
- data/test/v_object/birthday_calendar_generator_test.rb +22 -0
- data/test/v_object/component/v_alarm_test.rb +3 -1
- data/test/v_object/component/v_calendar_test.rb +40 -4
- data/test/v_object/component/v_card_test.rb +1 -1
- data/test/v_object/component_test.rb +5 -3
- data/test/v_object/date_time_parser_test.rb +15 -5
- data/test/v_object/free_busy_generator_test.rb +5 -5
- data/test/v_object/i_tip/broker_attendee_reply_test.rb +19 -0
- data/test/v_object/i_tip/broker_delete_event_test.rb +146 -2
- data/test/v_object/i_tip/broker_new_event_test.rb +21 -0
- data/test/v_object/i_tip/broker_process_reply_test.rb +10 -0
- data/test/v_object/i_tip/broker_tester.rb +1 -1
- data/test/v_object/i_tip/broker_update_event_test.rb +36 -0
- data/test/v_object/issue259_test.rb +24 -0
- data/test/v_object/issue40_test.rb +3 -1
- data/test/v_object/j_cal_test.rb +15 -12
- data/test/v_object/parser/json_test.rb +5 -5
- data/test/v_object/parser/mime_dir_test.rb +109 -0
- data/test/v_object/property/binary_test.rb +4 -2
- data/test/v_object/property/i_calendar/date_time_test.rb +3 -1
- data/test/v_object/property/uri_test.rb +23 -0
- data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +1 -1
- data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +1 -1
- data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +9 -9
- data/test/v_object/recur/event_iterator/handle_r_date_expand_test.rb +51 -0
- data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +3 -5
- data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +3 -1
- data/test/v_object/{issue26_test.rb → recur/event_iterator/issue26_test.rb} +3 -1
- data/test/v_object/recur/event_iterator/main_test.rb +9 -3
- data/test/v_object/recur/event_iterator/max_instances_test.rb +38 -0
- data/test/v_object/recur/event_iterator/missing_overridden_test.rb +3 -5
- data/test/v_object/recur/event_iterator/no_instances_test.rb +5 -3
- data/test/v_object/recur/event_iterator/override_first_event_test.rb +9 -9
- data/test/v_object/recur/r_date_iterator_test.rb +18 -0
- data/test/v_object/recur/r_rule_iterator_test.rb +4 -4
- data/test/v_object/splitter/i_calendar_test.rb +27 -7
- data/test/v_object/splitter/v_card_test.rb +5 -3
- data/test/v_object/test_case.rb +14 -4
- data/tilia-vobject.gemspec +2 -2
- metadata +17 -11
@@ -11,16 +11,16 @@ module Tilia
|
|
11
11
|
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
12
12
|
# not yet done, but parameters are not included.
|
13
13
|
#
|
14
|
-
# @param
|
14
|
+
# @param [String] val
|
15
15
|
#
|
16
|
-
# @return void
|
16
|
+
# @return [void]
|
17
17
|
def raw_mime_dir_value=(val)
|
18
18
|
self.value = val.to_i
|
19
19
|
end
|
20
20
|
|
21
21
|
# Returns a raw mime-dir representation of the value.
|
22
22
|
#
|
23
|
-
# @return
|
23
|
+
# @return [String]
|
24
24
|
def raw_mime_dir_value
|
25
25
|
@value
|
26
26
|
end
|
@@ -30,7 +30,7 @@ module Tilia
|
|
30
30
|
# This corresponds to the VALUE= parameter. Every property also has a
|
31
31
|
# 'default' valueType.
|
32
32
|
#
|
33
|
-
# @return
|
33
|
+
# @return [String]
|
34
34
|
def value_type
|
35
35
|
'INTEGER'
|
36
36
|
end
|
@@ -39,7 +39,7 @@ module Tilia
|
|
39
39
|
#
|
40
40
|
# This method must always return an array.
|
41
41
|
#
|
42
|
-
# @return array
|
42
|
+
# @return [array]
|
43
43
|
def json_value
|
44
44
|
[value.to_i]
|
45
45
|
end
|
@@ -47,11 +47,11 @@ module Tilia
|
|
47
47
|
# Hydrate data from a XML subtree, as it would appear in a xCard or xCal
|
48
48
|
# object.
|
49
49
|
#
|
50
|
-
# @param array value
|
50
|
+
# @param [array] value
|
51
51
|
#
|
52
|
-
# @return void
|
52
|
+
# @return [void]
|
53
53
|
def xml_value=(value)
|
54
|
-
value = value.map
|
54
|
+
value = value.map(&:to_i)
|
55
55
|
super(value)
|
56
56
|
end
|
57
57
|
end
|
@@ -8,12 +8,12 @@ module Tilia
|
|
8
8
|
# In case this is a multi-value property. This string will be used as a
|
9
9
|
# delimiter.
|
10
10
|
#
|
11
|
-
# @
|
11
|
+
# @return [String]
|
12
12
|
attr_accessor :delimiter
|
13
13
|
|
14
14
|
# List of properties that are considered 'structured'.
|
15
15
|
#
|
16
|
-
# @
|
16
|
+
# @return [array]
|
17
17
|
# RUBY: attr_accessor :structured_values
|
18
18
|
|
19
19
|
# Some text components have a minimum number of components.
|
@@ -21,7 +21,7 @@ module Tilia
|
|
21
21
|
# N must for instance be represented as 5 components, separated by ;, even
|
22
22
|
# if the last few components are unused.
|
23
23
|
#
|
24
|
-
# @
|
24
|
+
# @return [array]
|
25
25
|
# RUBY: attr_accessor :minimum_property_values
|
26
26
|
|
27
27
|
# Creates the property.
|
@@ -30,13 +30,13 @@ module Tilia
|
|
30
30
|
# parameters will automatically be created, or you can just pass a list of
|
31
31
|
# Parameter objects.
|
32
32
|
#
|
33
|
-
# @param Component root The root document
|
34
|
-
# @param
|
35
|
-
# @param
|
36
|
-
# @param array parameters List of parameters
|
37
|
-
# @param
|
33
|
+
# @param [Component] root The root document
|
34
|
+
# @param [String] name
|
35
|
+
# @param [String|array, nil] value
|
36
|
+
# @param [array] parameters List of parameters
|
37
|
+
# @param [String] group The vcard property group
|
38
38
|
#
|
39
|
-
# @return void
|
39
|
+
# @return [void]
|
40
40
|
def initialize(root, name, value = nil, parameters = [], group = nil)
|
41
41
|
super(root, name, value, parameters, group)
|
42
42
|
|
@@ -70,18 +70,18 @@ module Tilia
|
|
70
70
|
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
71
71
|
# not yet done, but parameters are not included.
|
72
72
|
#
|
73
|
-
# @param
|
73
|
+
# @param [String] val
|
74
74
|
#
|
75
|
-
# @return void
|
75
|
+
# @return [void]
|
76
76
|
def raw_mime_dir_value=(val)
|
77
77
|
self.value = Parser::MimeDir.unescape_value(val, @delimiter)
|
78
78
|
end
|
79
79
|
|
80
80
|
# Sets the value as a quoted-printable encoded string.
|
81
81
|
#
|
82
|
-
# @param
|
82
|
+
# @param [String] val
|
83
83
|
#
|
84
|
-
# @return void
|
84
|
+
# @return [void]
|
85
85
|
def quoted_printable_value=(val)
|
86
86
|
val = Mail::Encodings::QuotedPrintable.decode(val)
|
87
87
|
val = val.gsub(/\n/, "\r\n").gsub(/\r\r/, "\r")
|
@@ -105,7 +105,7 @@ module Tilia
|
|
105
105
|
|
106
106
|
# Returns a raw mime-dir representation of the value.
|
107
107
|
#
|
108
|
-
# @return
|
108
|
+
# @return [String]
|
109
109
|
def raw_mime_dir_value
|
110
110
|
val = parts
|
111
111
|
|
@@ -136,7 +136,7 @@ module Tilia
|
|
136
136
|
#
|
137
137
|
# This method must always return an array.
|
138
138
|
#
|
139
|
-
# @return array
|
139
|
+
# @return [array]
|
140
140
|
def json_value
|
141
141
|
# Structured text values should always be returned as a single
|
142
142
|
# array-item. Multi-value text should be returned as multiple items in
|
@@ -151,14 +151,14 @@ module Tilia
|
|
151
151
|
# This corresponds to the VALUE= parameter. Every property also has a
|
152
152
|
# 'default' valueType.
|
153
153
|
#
|
154
|
-
# @return
|
154
|
+
# @return [String]
|
155
155
|
def value_type
|
156
156
|
'TEXT'
|
157
157
|
end
|
158
158
|
|
159
159
|
# Turns the object back into a serialized blob.
|
160
160
|
#
|
161
|
-
# @return
|
161
|
+
# @return [String]
|
162
162
|
def serialize
|
163
163
|
# We need to kick in a special type of encoding, if it's a 2.1 vcard.
|
164
164
|
return super unless @root.document_type == Document::VCARD21
|
@@ -240,9 +240,9 @@ module Tilia
|
|
240
240
|
# This method serializes only the value of a property. This is used to
|
241
241
|
# create xCard or xCal documents.
|
242
242
|
#
|
243
|
-
# @param Xml\Writer writer XML writer.
|
243
|
+
# @param [Xml\Writer] writer XML writer.
|
244
244
|
#
|
245
|
-
# @return void
|
245
|
+
# @return [void]
|
246
246
|
def xml_serialize_value(writer)
|
247
247
|
values = parts
|
248
248
|
|
@@ -308,22 +308,7 @@ module Tilia
|
|
308
308
|
|
309
309
|
public
|
310
310
|
|
311
|
-
#
|
312
|
-
#
|
313
|
-
# The following options are supported:
|
314
|
-
# - Node::REPAIR - If something is broken, and automatic repair may
|
315
|
-
# be attempted.
|
316
|
-
#
|
317
|
-
# An array is returned with warnings.
|
318
|
-
#
|
319
|
-
# Every item in the array has the following properties:
|
320
|
-
# * level - (number between 1 and 3 with severity information)
|
321
|
-
# * message - (human readable message)
|
322
|
-
# * node - (reference to the offending node)
|
323
|
-
#
|
324
|
-
# @param int options
|
325
|
-
#
|
326
|
-
# @return array
|
311
|
+
# (see Component#validate)
|
327
312
|
def validate(options = 0)
|
328
313
|
warnings = super(options)
|
329
314
|
|
@@ -337,7 +322,7 @@ module Tilia
|
|
337
322
|
'node' => self
|
338
323
|
}
|
339
324
|
|
340
|
-
if options &
|
325
|
+
if options & REPAIR > 0
|
341
326
|
parts << '' while parts.size < minimum
|
342
327
|
self.parts = parts
|
343
328
|
end
|
@@ -8,7 +8,7 @@ module Tilia
|
|
8
8
|
# In case this is a multi-value property. This string will be used as a
|
9
9
|
# delimiter.
|
10
10
|
#
|
11
|
-
# @
|
11
|
+
# @return [String, nil]
|
12
12
|
attr_accessor :delimiter
|
13
13
|
|
14
14
|
# Returns the type of value.
|
@@ -16,16 +16,33 @@ module Tilia
|
|
16
16
|
# This corresponds to the VALUE= parameter. Every property also has a
|
17
17
|
# 'default' valueType.
|
18
18
|
#
|
19
|
-
# @return
|
19
|
+
# @return [String]
|
20
20
|
def value_type
|
21
21
|
'TIME'
|
22
22
|
end
|
23
23
|
|
24
|
+
# Sets the JSON value, as it would appear in a jCard or jCal object.
|
25
|
+
#
|
26
|
+
# The value must always be an array.
|
27
|
+
#
|
28
|
+
# @param [array] value
|
29
|
+
# @return [void]
|
30
|
+
def json_value=(value)
|
31
|
+
# Removing colons from value.
|
32
|
+
value = value.map { |v| v.delete(':') }
|
33
|
+
|
34
|
+
if value.size == 1
|
35
|
+
self.value = value.first
|
36
|
+
else
|
37
|
+
self.value = value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
24
41
|
# Returns the value, in the format it should be encoded for json.
|
25
42
|
#
|
26
43
|
# This method must always return an array.
|
27
44
|
#
|
28
|
-
# @return array
|
45
|
+
# @return [array]
|
29
46
|
def json_value
|
30
47
|
parts = DateTimeParser.parse_v_card_time(value)
|
31
48
|
time_str = ''
|
@@ -57,7 +74,13 @@ module Tilia
|
|
57
74
|
time_str += parts['second'] unless parts['second'].nil?
|
58
75
|
|
59
76
|
# Timezone
|
60
|
-
|
77
|
+
unless parts['timezone'].nil?
|
78
|
+
if parts['timezone'] == 'Z'
|
79
|
+
time_str += 'Z'
|
80
|
+
else
|
81
|
+
time_str += parts['timezone'].gsub(/([0-9]{2})([0-9]{2})$/) { "#{Regexp.last_match(1)}:#{Regexp.last_match(2)}" }
|
82
|
+
end
|
83
|
+
end
|
61
84
|
|
62
85
|
[time_str]
|
63
86
|
end
|
@@ -65,9 +88,9 @@ module Tilia
|
|
65
88
|
# Hydrate data from a XML subtree, as it would appear in a xCard or xCal
|
66
89
|
# object.
|
67
90
|
#
|
68
|
-
# @param array value
|
91
|
+
# @param [array] value
|
69
92
|
#
|
70
|
-
# @return void
|
93
|
+
# @return [void]
|
71
94
|
def xml_value=(value)
|
72
95
|
value = value.map do |v|
|
73
96
|
v.delete(':')
|
@@ -10,7 +10,7 @@ module Tilia
|
|
10
10
|
#
|
11
11
|
# This method must always return an array.
|
12
12
|
#
|
13
|
-
# @return array
|
13
|
+
# @return [array]
|
14
14
|
def json_value
|
15
15
|
[raw_mime_dir_value]
|
16
16
|
end
|
@@ -20,7 +20,7 @@ module Tilia
|
|
20
20
|
# This corresponds to the VALUE= parameter. Every property also has a
|
21
21
|
# 'default' valueType.
|
22
22
|
#
|
23
|
-
# @return
|
23
|
+
# @return [String]
|
24
24
|
def value_type
|
25
25
|
'UNKNOWN'
|
26
26
|
end
|
@@ -8,7 +8,7 @@ module Tilia
|
|
8
8
|
# In case this is a multi-value property. This string will be used as a
|
9
9
|
# delimiter.
|
10
10
|
#
|
11
|
-
# @
|
11
|
+
# @return [String, nil]
|
12
12
|
attr_accessor :delimiter
|
13
13
|
|
14
14
|
# Returns the type of value.
|
@@ -16,19 +16,38 @@ module Tilia
|
|
16
16
|
# This corresponds to the VALUE= parameter. Every property also has a
|
17
17
|
# 'default' valueType.
|
18
18
|
#
|
19
|
-
# @return
|
19
|
+
# @return [String]
|
20
20
|
def value_type
|
21
21
|
'URI'
|
22
22
|
end
|
23
23
|
|
24
|
+
# Returns an iterable list of children.
|
25
|
+
#
|
26
|
+
# @return [array]
|
27
|
+
def parameters
|
28
|
+
parameters = super
|
29
|
+
if !parameters.key?('VALUE') && ['URL', 'PHOTO'].include?(@name)
|
30
|
+
# If we are encoding a URI value, and this URI value has no
|
31
|
+
# VALUE=URI parameter, we add it anyway.
|
32
|
+
#
|
33
|
+
# This is not required by any spec, but both Apple iCal and Apple
|
34
|
+
# AddressBook (at least in version 10.8) will trip over this if
|
35
|
+
# this is not set, and so it improves compatibility.
|
36
|
+
#
|
37
|
+
# See Issue #227 and #235
|
38
|
+
parameters['VALUE'] = Parameter.new(@root, 'VALUE', 'URI')
|
39
|
+
end
|
40
|
+
parameters
|
41
|
+
end
|
42
|
+
|
24
43
|
# Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
25
44
|
#
|
26
45
|
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
27
46
|
# not yet done, but parameters are not included.
|
28
47
|
#
|
29
|
-
# @param
|
48
|
+
# @param [String] val
|
30
49
|
#
|
31
|
-
# @return void
|
50
|
+
# @return [void]
|
32
51
|
def raw_mime_dir_value=(val)
|
33
52
|
# Normally we don't need to do any type of unescaping for these
|
34
53
|
# properties, however.. we've noticed that Google Contacts
|
@@ -57,7 +76,7 @@ module Tilia
|
|
57
76
|
|
58
77
|
# Returns a raw mime-dir representation of the value.
|
59
78
|
#
|
60
|
-
# @return
|
79
|
+
# @return [String]
|
61
80
|
def raw_mime_dir_value
|
62
81
|
if @value.is_a?(Array)
|
63
82
|
value = @value[0]
|
@@ -8,7 +8,7 @@ module Tilia
|
|
8
8
|
# In case this is a multi-value property. This string will be used as a
|
9
9
|
# delimiter.
|
10
10
|
#
|
11
|
-
# @
|
11
|
+
# @return [String, nil]
|
12
12
|
attr_accessor :delimiter
|
13
13
|
|
14
14
|
# Returns the type of value.
|
@@ -16,7 +16,7 @@ module Tilia
|
|
16
16
|
# This corresponds to the VALUE= parameter. Every property also has a
|
17
17
|
# 'default' valueType.
|
18
18
|
#
|
19
|
-
# @return
|
19
|
+
# @return [String]
|
20
20
|
def value_type
|
21
21
|
'UTC-OFFSET'
|
22
22
|
end
|
@@ -25,9 +25,9 @@ module Tilia
|
|
25
25
|
#
|
26
26
|
# The value must always be an array.
|
27
27
|
#
|
28
|
-
# @param array value
|
28
|
+
# @param [array] value
|
29
29
|
#
|
30
|
-
# @return void
|
30
|
+
# @return [void]
|
31
31
|
def json_value=(value)
|
32
32
|
value = value.map do |v|
|
33
33
|
v.delete(':')
|
@@ -39,7 +39,7 @@ module Tilia
|
|
39
39
|
#
|
40
40
|
# This method must always return an array.
|
41
41
|
#
|
42
|
-
# @return array
|
42
|
+
# @return [array]
|
43
43
|
def json_value
|
44
44
|
super.map do |value|
|
45
45
|
"#{value[0...-2]}:#{value[-2..-1]}"
|
@@ -11,16 +11,16 @@ module Tilia
|
|
11
11
|
# This corresponds to the VALUE= parameter. Every property also has a
|
12
12
|
# 'default' valueType.
|
13
13
|
#
|
14
|
-
# @return
|
14
|
+
# @return [String]
|
15
15
|
def value_type
|
16
16
|
'DATE'
|
17
17
|
end
|
18
18
|
|
19
19
|
# Sets the property as a DateTime object.
|
20
20
|
#
|
21
|
-
# @param \DateTimeInterface dt
|
21
|
+
# @param [\DateTimeInterface] dt
|
22
22
|
#
|
23
|
-
# @return void
|
23
|
+
# @return [void]
|
24
24
|
def date_time=(dt)
|
25
25
|
@value = dt.strftime('%Y%m%d')
|
26
26
|
end
|
@@ -8,7 +8,7 @@ module Tilia
|
|
8
8
|
class DateAndOrTime < Property
|
9
9
|
# Field separator.
|
10
10
|
#
|
11
|
-
# @
|
11
|
+
# @return [null|string]
|
12
12
|
attr_accessor :delimiter
|
13
13
|
|
14
14
|
# Returns the type of value.
|
@@ -16,7 +16,7 @@ module Tilia
|
|
16
16
|
# This corresponds to the VALUE= parameter. Every property also has a
|
17
17
|
# 'default' valueType.
|
18
18
|
#
|
19
|
-
# @return
|
19
|
+
# @return [String]
|
20
20
|
def value_type
|
21
21
|
'DATE-AND-OR-TIME'
|
22
22
|
end
|
@@ -25,9 +25,9 @@ module Tilia
|
|
25
25
|
#
|
26
26
|
# You may also specify DateTime objects here.
|
27
27
|
#
|
28
|
-
# @param array parts
|
28
|
+
# @param [array] parts
|
29
29
|
#
|
30
|
-
# @return void
|
30
|
+
# @return [void]
|
31
31
|
def parts=(parts)
|
32
32
|
fail ArgumentError, 'Only one value allowed' if parts.size > 1
|
33
33
|
|
@@ -44,9 +44,9 @@ module Tilia
|
|
44
44
|
#
|
45
45
|
# Instead of strings, you may also use DateTime here.
|
46
46
|
#
|
47
|
-
# @param
|
47
|
+
# @param [String|array|\DateTime] value
|
48
48
|
#
|
49
|
-
# @return void
|
49
|
+
# @return [void]
|
50
50
|
def value=(value)
|
51
51
|
if value.is_a?(::Time)
|
52
52
|
self.date_time = value
|
@@ -57,9 +57,9 @@ module Tilia
|
|
57
57
|
|
58
58
|
# Sets the property as a DateTime object.
|
59
59
|
#
|
60
|
-
# @param
|
60
|
+
# @param [Time] dt
|
61
61
|
#
|
62
|
-
# @return void
|
62
|
+
# @return [void]
|
63
63
|
def date_time=(dt)
|
64
64
|
tz = dt.time_zone
|
65
65
|
is_utc = ['UTC', 'GMT', 'Z'].include?(tz.name)
|
@@ -87,7 +87,7 @@ module Tilia
|
|
87
87
|
# current values for those. So at the time of writing, if the year was
|
88
88
|
# omitted, we would have filled in 2014.
|
89
89
|
#
|
90
|
-
# @return
|
90
|
+
# @return [Time]
|
91
91
|
def date_time
|
92
92
|
now = ::Time.zone.now
|
93
93
|
|
@@ -103,14 +103,21 @@ module Tilia
|
|
103
103
|
end
|
104
104
|
|
105
105
|
# Now follows a ruby Hack
|
106
|
-
|
107
|
-
|
108
|
-
datetime =
|
109
|
-
|
110
|
-
|
106
|
+
date_parts['timezone'] = '+0000' if date_parts['timezone'] == 'Z'
|
107
|
+
done = false
|
108
|
+
datetime = nil
|
109
|
+
|
110
|
+
ActiveSupport::TimeZone.all.each do |tz|
|
111
111
|
datetime = tz.parse("#{date_parts['year']}-#{date_parts['month']}-#{date_parts['date']} #{date_parts['hour']}:#{date_parts['minute']}:#{date_parts['second']}")
|
112
|
+
|
113
|
+
next unless datetime.strftime('%z') == date_parts['timezone']
|
114
|
+
|
115
|
+
done = true
|
116
|
+
break
|
112
117
|
end
|
113
|
-
|
118
|
+
|
119
|
+
fail 'could not load correct time zone' unless done
|
120
|
+
# End ruby hack
|
114
121
|
|
115
122
|
datetime.freeze
|
116
123
|
datetime
|
@@ -120,7 +127,7 @@ module Tilia
|
|
120
127
|
#
|
121
128
|
# This method must always return an array.
|
122
129
|
#
|
123
|
-
# @return array
|
130
|
+
# @return [array]
|
124
131
|
def json_value
|
125
132
|
parts = DateTimeParser.parse_v_card_date_time(value)
|
126
133
|
|
@@ -201,9 +208,9 @@ module Tilia
|
|
201
208
|
# This method serializes only the value of a property. This is used to
|
202
209
|
# create xCard or xCal documents.
|
203
210
|
#
|
204
|
-
# @param Xml\Writer writer XML writer.
|
211
|
+
# @param [Xml\Writer] writer XML writer.
|
205
212
|
#
|
206
|
-
# @return void
|
213
|
+
# @return [void]
|
207
214
|
def xml_serialize_value(writer)
|
208
215
|
value_type = self.value_type.downcase
|
209
216
|
parts = DateTimeParser.parse_v_card_date_and_or_time(value)
|
@@ -281,47 +288,28 @@ module Tilia
|
|
281
288
|
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
282
289
|
# not yet done, but parameters are not included.
|
283
290
|
#
|
284
|
-
# @param
|
291
|
+
# @param [String] val
|
285
292
|
#
|
286
|
-
# @return void
|
293
|
+
# @return [void]
|
287
294
|
def raw_mime_dir_value=(val)
|
288
295
|
self.value = val
|
289
296
|
end
|
290
297
|
|
291
298
|
# Returns a raw mime-dir representation of the value.
|
292
299
|
#
|
293
|
-
# @return
|
300
|
+
# @return [String]
|
294
301
|
def raw_mime_dir_value
|
295
302
|
parts.join(@delimiter)
|
296
303
|
end
|
297
304
|
|
298
|
-
#
|
299
|
-
#
|
300
|
-
# The following options are supported:
|
301
|
-
# Node::REPAIR - May attempt to automatically repair the problem.
|
302
|
-
#
|
303
|
-
# This method returns an array with detected problems.
|
304
|
-
# Every element has the following properties:
|
305
|
-
#
|
306
|
-
# * level - problem level.
|
307
|
-
# * message - A human-readable string describing the issue.
|
308
|
-
# * node - A reference to the problematic node.
|
309
|
-
#
|
310
|
-
# The level means:
|
311
|
-
# 1 - The issue was repaired (only happens if REPAIR was turned on)
|
312
|
-
# 2 - An inconsequential issue
|
313
|
-
# 3 - A severe issue.
|
314
|
-
#
|
315
|
-
# @param int options
|
316
|
-
#
|
317
|
-
# @return array
|
305
|
+
# (see Component#validate)
|
318
306
|
def validate(options = 0)
|
319
307
|
messages = super(options)
|
320
308
|
value = self.value
|
321
309
|
|
322
310
|
begin
|
323
311
|
DateTimeParser.parse_v_card_date_time(value)
|
324
|
-
rescue
|
312
|
+
rescue InvalidDataException
|
325
313
|
messages << {
|
326
314
|
'level' => 3,
|
327
315
|
'message' => "The supplied value (#{value}) is not a correct DATE-AND-OR-TIME property",
|