tilia-vobject 4.0.0.pre.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rubocop.yml +32 -0
- data/.simplecov +4 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.sabre.md +626 -0
- data/CONTRIBUTING.md +25 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +68 -0
- data/LICENSE +27 -0
- data/LICENSE.sabre +27 -0
- data/README.md +63 -0
- data/Rakefile +17 -0
- data/bin/vobject +7 -0
- data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
- data/lib/tilia/v_object/cli.rb +582 -0
- data/lib/tilia/v_object/component/available.rb +107 -0
- data/lib/tilia/v_object/component/v_alarm.rb +114 -0
- data/lib/tilia/v_object/component/v_availability.rb +128 -0
- data/lib/tilia/v_object/component/v_calendar.rb +468 -0
- data/lib/tilia/v_object/component/v_card.rb +457 -0
- data/lib/tilia/v_object/component/v_event.rb +127 -0
- data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
- data/lib/tilia/v_object/component/v_journal.rb +75 -0
- data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
- data/lib/tilia/v_object/component/v_todo.rb +147 -0
- data/lib/tilia/v_object/component.rb +591 -0
- data/lib/tilia/v_object/date_time_parser.rb +486 -0
- data/lib/tilia/v_object/document.rb +218 -0
- data/lib/tilia/v_object/element_list.rb +18 -0
- data/lib/tilia/v_object/eof_exception.rb +8 -0
- data/lib/tilia/v_object/free_busy_data.rb +149 -0
- data/lib/tilia/v_object/free_busy_generator.rb +465 -0
- data/lib/tilia/v_object/i_tip/broker.rb +909 -0
- data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
- data/lib/tilia/v_object/i_tip/message.rb +109 -0
- data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
- data/lib/tilia/v_object/i_tip.rb +10 -0
- data/lib/tilia/v_object/node.rb +192 -0
- data/lib/tilia/v_object/parameter.rb +327 -0
- data/lib/tilia/v_object/parse_exception.rb +7 -0
- data/lib/tilia/v_object/parser/json.rb +149 -0
- data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
- data/lib/tilia/v_object/parser/parser.rb +61 -0
- data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
- data/lib/tilia/v_object/parser/xml/element.rb +11 -0
- data/lib/tilia/v_object/parser/xml.rb +322 -0
- data/lib/tilia/v_object/parser.rb +10 -0
- data/lib/tilia/v_object/property/binary.rb +96 -0
- data/lib/tilia/v_object/property/boolean.rb +57 -0
- data/lib/tilia/v_object/property/flat_text.rb +52 -0
- data/lib/tilia/v_object/property/float_value.rb +107 -0
- data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
- data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
- data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
- data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
- data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
- data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
- data/lib/tilia/v_object/property/i_calendar.rb +14 -0
- data/lib/tilia/v_object/property/integer_value.rb +60 -0
- data/lib/tilia/v_object/property/text.rb +352 -0
- data/lib/tilia/v_object/property/time.rb +85 -0
- data/lib/tilia/v_object/property/unknown.rb +30 -0
- data/lib/tilia/v_object/property/uri.rb +78 -0
- data/lib/tilia/v_object/property/utc_offset.rb +56 -0
- data/lib/tilia/v_object/property/v_card/date.rb +31 -0
- data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
- data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
- data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
- data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
- data/lib/tilia/v_object/property/v_card.rb +13 -0
- data/lib/tilia/v_object/property.rb +532 -0
- data/lib/tilia/v_object/reader.rb +73 -0
- data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
- data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
- data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
- data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
- data/lib/tilia/v_object/recur.rb +10 -0
- data/lib/tilia/v_object/settings.rb +32 -0
- data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
- data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
- data/lib/tilia/v_object/splitter/v_card.rb +56 -0
- data/lib/tilia/v_object/splitter.rb +9 -0
- data/lib/tilia/v_object/string_util.rb +58 -0
- data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
- data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
- data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
- data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
- data/lib/tilia/v_object/time_zone_data.rb +10 -0
- data/lib/tilia/v_object/time_zone_util.rb +213 -0
- data/lib/tilia/v_object/uuid_util.rb +51 -0
- data/lib/tilia/v_object/v_card_converter.rb +354 -0
- data/lib/tilia/v_object/version.rb +9 -0
- data/lib/tilia/v_object/writer.rb +56 -0
- data/lib/tilia/v_object.rb +45 -0
- data/lib/tilia/vobject.rb +1 -0
- data/resources/schema/xcal.rng +1192 -0
- data/resources/schema/xcard.rng +388 -0
- data/test/test_helper.rb +56 -0
- data/test/v_object/attach_issue_test.rb +19 -0
- data/test/v_object/birthday_calendar_generator_test.rb +463 -0
- data/test/v_object/cli_mock.rb +19 -0
- data/test/v_object/cli_test.rb +460 -0
- data/test/v_object/component/available_test.rb +59 -0
- data/test/v_object/component/v_alarm_test.rb +160 -0
- data/test/v_object/component/v_availability_test.rb +388 -0
- data/test/v_object/component/v_calendar_test.rb +646 -0
- data/test/v_object/component/v_card_test.rb +258 -0
- data/test/v_object/component/v_event_test.rb +85 -0
- data/test/v_object/component/v_free_busy_test.rb +59 -0
- data/test/v_object/component/v_journal_test.rb +85 -0
- data/test/v_object/component/v_time_zone_test.rb +47 -0
- data/test/v_object/component/v_todo_test.rb +172 -0
- data/test/v_object/component_test.rb +419 -0
- data/test/v_object/date_time_parser_test.rb +526 -0
- data/test/v_object/document_test.rb +71 -0
- data/test/v_object/element_list_test.rb +27 -0
- data/test/v_object/em_client_test.rb +53 -0
- data/test/v_object/empty_parameter_test.rb +65 -0
- data/test/v_object/empty_value_issue_test.rb +25 -0
- data/test/v_object/fake_component.rb +21 -0
- data/test/v_object/free_busy_data_test.rb +285 -0
- data/test/v_object/free_busy_generator_test.rb +637 -0
- data/test/v_object/google_colon_escaping_test.rb +27 -0
- data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
- data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
- data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
- data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
- data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
- data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
- data/test/v_object/i_tip/broker_tester.rb +71 -0
- data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
- data/test/v_object/i_tip/evolution_test.rb +2644 -0
- data/test/v_object/i_tip/message_test.rb +25 -0
- data/test/v_object/issue153.vcf +352 -0
- data/test/v_object/issue153_test.rb +12 -0
- data/test/v_object/issue26_test.rb +25 -0
- data/test/v_object/issue36_work_around_test.rb +37 -0
- data/test/v_object/issue40_test.rb +26 -0
- data/test/v_object/issue64.vcf +351 -0
- data/test/v_object/issue64_test.rb +17 -0
- data/test/v_object/issue96_test.rb +22 -0
- data/test/v_object/issue_undefined_index_test.rb +24 -0
- data/test/v_object/j_cal_test.rb +150 -0
- data/test/v_object/j_card_test.rb +192 -0
- data/test/v_object/line_folding_issue_test.rb +19 -0
- data/test/v_object/mock_document.rb +6 -0
- data/test/v_object/parameter_test.rb +109 -0
- data/test/v_object/parser/json_test.rb +370 -0
- data/test/v_object/parser/mime_dir_test.rb +14 -0
- data/test/v_object/parser/quoted_printable_test.rb +78 -0
- data/test/v_object/parser/xml_test.rb +2563 -0
- data/test/v_object/property/binary_test.rb +12 -0
- data/test/v_object/property/boolean_test.rb +18 -0
- data/test/v_object/property/compound_test.rb +43 -0
- data/test/v_object/property/float_test.rb +20 -0
- data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
- data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
- data/test/v_object/property/i_calendar/duration_test.rb +14 -0
- data/test/v_object/property/i_calendar/recur_test.rb +39 -0
- data/test/v_object/property/text_test.rb +81 -0
- data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
- data/test/v_object/property/v_card/language_tag_test.rb +35 -0
- data/test/v_object/property_test.rb +338 -0
- data/test/v_object/reader_test.rb +403 -0
- data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
- data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
- data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
- data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
- data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
- data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
- data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
- data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
- data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
- data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
- data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
- data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
- data/test/v_object/recur/r_date_iterator_test.rb +44 -0
- data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
- data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
- data/test/v_object/slash_r_test.rb +15 -0
- data/test/v_object/splitter/i_calendar_test.rb +299 -0
- data/test/v_object/splitter/v_card_test.rb +173 -0
- data/test/v_object/string_util_test.rb +37 -0
- data/test/v_object/test_case.rb +42 -0
- data/test/v_object/time_zone_util_test.rb +271 -0
- data/test/v_object/uuid_util_test.rb +18 -0
- data/test/v_object/v_card21_test.rb +43 -0
- data/test/v_object/v_card_converter_test.rb +419 -0
- data/test/v_object/version_test.rb +15 -0
- data/test/v_object/writer_test.rb +33 -0
- data/tilia-vobject.gemspec +17 -0
- metadata +308 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
# Float property.
|
5
|
+
#
|
6
|
+
# This object represents FLOAT values. These can be 1 or more floating-point
|
7
|
+
# numbers.
|
8
|
+
class FloatValue < Property
|
9
|
+
# In case this is a multi-value property. This string will be used as a
|
10
|
+
# delimiter.
|
11
|
+
#
|
12
|
+
# @var string|null
|
13
|
+
attr_accessor :delimiter
|
14
|
+
|
15
|
+
# Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
16
|
+
#
|
17
|
+
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
18
|
+
# not yet done, but parameters are not included.
|
19
|
+
#
|
20
|
+
# @param string val
|
21
|
+
#
|
22
|
+
# @return void
|
23
|
+
def raw_mime_dir_value=(val)
|
24
|
+
val = val.split(@delimiter)
|
25
|
+
val = val.map(&:to_f)
|
26
|
+
self.parts = val
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns a raw mime-dir representation of the value.
|
30
|
+
#
|
31
|
+
# @return string
|
32
|
+
def raw_mime_dir_value
|
33
|
+
parts.join(@delimiter)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the type of value.
|
37
|
+
#
|
38
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
39
|
+
# 'default' valueType.
|
40
|
+
#
|
41
|
+
# @return string
|
42
|
+
def value_type
|
43
|
+
'FLOAT'
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns the value, in the format it should be encoded for JSON.
|
47
|
+
#
|
48
|
+
# This method must always return an array.
|
49
|
+
#
|
50
|
+
# @return array
|
51
|
+
def json_value
|
52
|
+
val = parts.map(&:to_f)
|
53
|
+
|
54
|
+
# Special-casing the GEO property.
|
55
|
+
#
|
56
|
+
# See:
|
57
|
+
# http://tools.ietf.org/html/draft-ietf-jcardcal-jcal-04#section-3.4.1.2
|
58
|
+
return [val] if @name == 'GEO'
|
59
|
+
|
60
|
+
val
|
61
|
+
end
|
62
|
+
|
63
|
+
# Hydrate data from a XML subtree, as it would appear in a xCard or xCal
|
64
|
+
# object.
|
65
|
+
#
|
66
|
+
# @param array value
|
67
|
+
#
|
68
|
+
# @return void
|
69
|
+
def xml_value=(value)
|
70
|
+
value = value.values if value.is_a?(Hash)
|
71
|
+
value = value.map(&:to_f)
|
72
|
+
super(value)
|
73
|
+
end
|
74
|
+
|
75
|
+
protected
|
76
|
+
|
77
|
+
# This method serializes only the value of a property. This is used to
|
78
|
+
# create xCard or xCal documents.
|
79
|
+
#
|
80
|
+
# @param Xml\Writer writer XML writer.
|
81
|
+
#
|
82
|
+
# @return void
|
83
|
+
def xml_serialize_value(writer)
|
84
|
+
# Special-casing the GEO property.
|
85
|
+
#
|
86
|
+
# See:
|
87
|
+
# http://tools.ietf.org/html/rfc6321#section-3.4.1.2
|
88
|
+
if @name == 'GEO'
|
89
|
+
value = parts.map(&:to_f)
|
90
|
+
|
91
|
+
writer.write_element('latitude', value[0])
|
92
|
+
writer.write_element('longitude', value[1])
|
93
|
+
else
|
94
|
+
super(writer)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
public
|
99
|
+
|
100
|
+
def initialize(*args)
|
101
|
+
super(*args)
|
102
|
+
@delimiter = ';'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module ICalendar
|
5
|
+
# CalAddress property.
|
6
|
+
#
|
7
|
+
# This object encodes CAL-ADDRESS values, as defined in rfc5545
|
8
|
+
class CalAddress < Text
|
9
|
+
# In case this is a multi-value property. This string will be used as a
|
10
|
+
# delimiter.
|
11
|
+
#
|
12
|
+
# @var string|null
|
13
|
+
attr_accessor :delimiter
|
14
|
+
|
15
|
+
# Returns the type of value.
|
16
|
+
#
|
17
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
18
|
+
# 'default' valueType.
|
19
|
+
#
|
20
|
+
# @return string
|
21
|
+
def value_type
|
22
|
+
'CAL-ADDRESS'
|
23
|
+
end
|
24
|
+
|
25
|
+
# This returns a normalized form of the value.
|
26
|
+
#
|
27
|
+
# This is primarily used right now to turn mixed-cased schemes in user
|
28
|
+
# uris to lower-case.
|
29
|
+
#
|
30
|
+
# Evolution in particular tends to encode mailto: as MAILTO:.
|
31
|
+
#
|
32
|
+
# @return string
|
33
|
+
def normalized_value
|
34
|
+
input = value
|
35
|
+
return input unless input.index(':')
|
36
|
+
|
37
|
+
(schema, everything_else) = input.split(':', 2)
|
38
|
+
"#{schema.downcase}:#{everything_else}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(*args)
|
42
|
+
super(*args)
|
43
|
+
@delimiter = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module ICalendar
|
5
|
+
# DateTime property.
|
6
|
+
#
|
7
|
+
# This object represents DATE values, as defined here:
|
8
|
+
#
|
9
|
+
# http://tools.ietf.org/html/rfc5545#section-3.3.5
|
10
|
+
class Date < DateTime
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,330 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module ICalendar
|
5
|
+
# DateTime property.
|
6
|
+
#
|
7
|
+
# This object represents DATE-TIME values, as defined here:
|
8
|
+
#
|
9
|
+
# http://tools.ietf.org/html/rfc5545#section-3.3.4
|
10
|
+
#
|
11
|
+
# This particular object has a bit of hackish magic that it may also in some
|
12
|
+
# cases represent a DATE value. This is because it's a common usecase to be
|
13
|
+
# able to change a DATE-TIME into a DATE.
|
14
|
+
class DateTime < Property
|
15
|
+
# In case this is a multi-value property. This string will be used as a
|
16
|
+
# delimiter.
|
17
|
+
#
|
18
|
+
# @var string|null
|
19
|
+
attr_accessor :delimiter
|
20
|
+
|
21
|
+
# Sets a multi-valued property.
|
22
|
+
#
|
23
|
+
# You may also specify DateTime objects here.
|
24
|
+
#
|
25
|
+
# @param array parts
|
26
|
+
#
|
27
|
+
# @return void
|
28
|
+
def parts=(parts)
|
29
|
+
if parts[0].is_a?(::Time)
|
30
|
+
self.date_times = parts
|
31
|
+
else
|
32
|
+
super(parts)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Updates the current value.
|
37
|
+
#
|
38
|
+
# This may be either a single, or multiple strings in an array.
|
39
|
+
#
|
40
|
+
# Instead of strings, you may also use DateTime here.
|
41
|
+
#
|
42
|
+
# @param string|array|DateTimeInterface value
|
43
|
+
#
|
44
|
+
# @return void
|
45
|
+
def value=(value)
|
46
|
+
if value.is_a?(Array) && value[0].is_a?(::Time)
|
47
|
+
self.date_times = value
|
48
|
+
elsif value.is_a?(::Time)
|
49
|
+
self.date_times = [value]
|
50
|
+
else
|
51
|
+
super(value)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
56
|
+
#
|
57
|
+
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
58
|
+
# not yet done, but parameters are not included.
|
59
|
+
#
|
60
|
+
# @param string val
|
61
|
+
#
|
62
|
+
# @return void
|
63
|
+
def raw_mime_dir_value=(val)
|
64
|
+
self.value = val.split(@delimiter)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns a raw mime-dir representation of the value.
|
68
|
+
#
|
69
|
+
# @return string
|
70
|
+
def raw_mime_dir_value
|
71
|
+
parts.join(@delimiter)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns true if this is a DATE-TIME value, false if it's a DATE.
|
75
|
+
#
|
76
|
+
# @return bool
|
77
|
+
def time?
|
78
|
+
self['VALUE'].to_s.upcase != 'DATE'
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns true if this is a floating DATE or DATE-TIME.
|
82
|
+
#
|
83
|
+
# Note that DATE is always floating.
|
84
|
+
def floating?
|
85
|
+
!self.time? || (!self.key?('TZID') && !value.index('Z'))
|
86
|
+
end
|
87
|
+
|
88
|
+
# Returns a date-time value.
|
89
|
+
#
|
90
|
+
# Note that if this property contained more than 1 date-time, only the
|
91
|
+
# first will be returned. To get an array with multiple values, call
|
92
|
+
# getDateTimes.
|
93
|
+
#
|
94
|
+
# If no timezone information is known, because it's either an all-day
|
95
|
+
# property or floating time, we will use the DateTimeZone argument to
|
96
|
+
# figure out the exact date.
|
97
|
+
#
|
98
|
+
# @param DateTimeZone time_zone
|
99
|
+
#
|
100
|
+
# @return DateTimeImmutable
|
101
|
+
def date_time(time_zone = nil)
|
102
|
+
dt = date_times(time_zone)
|
103
|
+
return nil unless dt
|
104
|
+
|
105
|
+
dt[0]
|
106
|
+
end
|
107
|
+
|
108
|
+
# Returns multiple date-time values.
|
109
|
+
#
|
110
|
+
# If no timezone information is known, because it's either an all-day
|
111
|
+
# property or floating time, we will use the DateTimeZone argument to
|
112
|
+
# figure out the exact date.
|
113
|
+
#
|
114
|
+
# @param DateTimeZone time_zone
|
115
|
+
#
|
116
|
+
# @return DateTimeImmutable[]
|
117
|
+
# @return \DateTime[]
|
118
|
+
def date_times(time_zone = nil)
|
119
|
+
# Does the property have a TZID?
|
120
|
+
tzid = self['TZID']
|
121
|
+
|
122
|
+
time_zone = Tilia::VObject::TimeZoneUtil.time_zone(tzid.to_s, @root) if tzid
|
123
|
+
|
124
|
+
dts = []
|
125
|
+
parts.each do |part|
|
126
|
+
dts << Tilia::VObject::DateTimeParser.parse(part, time_zone)
|
127
|
+
end
|
128
|
+
dts
|
129
|
+
end
|
130
|
+
|
131
|
+
# Sets the property as a DateTime object.
|
132
|
+
#
|
133
|
+
# @param DateTimeInterface dt
|
134
|
+
# @param bool isFloating If set to true, timezones will be ignored.
|
135
|
+
#
|
136
|
+
# @return void
|
137
|
+
def date_time=(dt)
|
138
|
+
self.date_times = [dt]
|
139
|
+
end
|
140
|
+
|
141
|
+
# Sets the property as multiple date-time objects.
|
142
|
+
#
|
143
|
+
# The first value will be used as a reference for the timezones, and all
|
144
|
+
# the otehr values will be adjusted for that timezone
|
145
|
+
#
|
146
|
+
# @param DateTimeInterface[] dt
|
147
|
+
# @param bool isFloating If set to true, timezones will be ignored.
|
148
|
+
#
|
149
|
+
# @return void
|
150
|
+
def date_times=(dt)
|
151
|
+
update_date_times(dt)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Returns the type of value.
|
155
|
+
#
|
156
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
157
|
+
# 'default' valueType.
|
158
|
+
#
|
159
|
+
# @return string
|
160
|
+
def value_type
|
161
|
+
time? ? 'DATE-TIME' : 'DATE'
|
162
|
+
end
|
163
|
+
|
164
|
+
# Returns the value, in the format it should be encoded for JSON.
|
165
|
+
#
|
166
|
+
# This method must always return an array.
|
167
|
+
#
|
168
|
+
# @return array
|
169
|
+
def json_value
|
170
|
+
dts = date_times
|
171
|
+
|
172
|
+
tz = dts[0].time_zone
|
173
|
+
is_utc = floating? ? false : ['UTC', 'GMT', 'Z'].include?(tz.name)
|
174
|
+
|
175
|
+
dts.map do |dt|
|
176
|
+
if time?
|
177
|
+
dt.strftime('%Y-%m-%dT%H:%M:%S') + (is_utc ? 'Z' : '')
|
178
|
+
else
|
179
|
+
dt.strftime('%Y-%m-%d')
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# Sets the json value, as it would appear in a jCard or jCal object.
|
185
|
+
#
|
186
|
+
# The value must always be an array.
|
187
|
+
#
|
188
|
+
# @param array value
|
189
|
+
#
|
190
|
+
# @return void
|
191
|
+
def json_value=(value)
|
192
|
+
# dates and times in jCal have one difference to dates and times in
|
193
|
+
# iCalendar. In jCal date-parts are separated by dashes, and
|
194
|
+
# time-parts are separated by colons. It makes sense to just remove
|
195
|
+
# those.
|
196
|
+
self.value = value.map do |item|
|
197
|
+
item.delete(':').delete('-')
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
# We need to intercept offsetSet, because it may be used to alter the
|
202
|
+
# VALUE from DATE-TIME to DATE or vice-versa.
|
203
|
+
#
|
204
|
+
# @param string name
|
205
|
+
# @param mixed value
|
206
|
+
#
|
207
|
+
# @return void
|
208
|
+
def []=(name, value)
|
209
|
+
super
|
210
|
+
|
211
|
+
return nil unless name.upcase == 'VALUE'
|
212
|
+
|
213
|
+
# This will ensure that dates are correctly encoded.
|
214
|
+
update_date_times(date_times)
|
215
|
+
end
|
216
|
+
|
217
|
+
# Validates the node for correctness.
|
218
|
+
#
|
219
|
+
# The following options are supported:
|
220
|
+
# Node::REPAIR - May attempt to automatically repair the problem.
|
221
|
+
#
|
222
|
+
# This method returns an array with detected problems.
|
223
|
+
# Every element has the following properties:
|
224
|
+
#
|
225
|
+
# * level - problem level.
|
226
|
+
# * message - A human-readable string describing the issue.
|
227
|
+
# * node - A reference to the problematic node.
|
228
|
+
#
|
229
|
+
# The level means:
|
230
|
+
# 1 - The issue was repaired (only happens if REPAIR was turned on)
|
231
|
+
# 2 - An inconsequential issue
|
232
|
+
# 3 - A severe issue.
|
233
|
+
#
|
234
|
+
# @param int options
|
235
|
+
#
|
236
|
+
# @return array
|
237
|
+
def validate(options = 0)
|
238
|
+
messages = super(options)
|
239
|
+
value_type = self.value_type
|
240
|
+
values = parts
|
241
|
+
|
242
|
+
begin
|
243
|
+
save_val = nil
|
244
|
+
values.each do |value|
|
245
|
+
save_val = value
|
246
|
+
case value_type
|
247
|
+
when 'DATE'
|
248
|
+
Tilia::VObject::DateTimeParser.parse_date(value)
|
249
|
+
when 'DATE-TIME'
|
250
|
+
Tilia::VObject::DateTimeParser.parse_date_time(value)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
rescue RuntimeError
|
254
|
+
messages << {
|
255
|
+
'level' => 3,
|
256
|
+
'message' => "The supplied value (#{save_val}) is not a correct #[value_type}",
|
257
|
+
'node' => self
|
258
|
+
}
|
259
|
+
end
|
260
|
+
|
261
|
+
messages
|
262
|
+
end
|
263
|
+
|
264
|
+
protected
|
265
|
+
|
266
|
+
# Raw values of dates for post_processing
|
267
|
+
#
|
268
|
+
# @return [Array<TIME>]
|
269
|
+
attr_accessor :raw_values
|
270
|
+
|
271
|
+
public
|
272
|
+
|
273
|
+
def initialize(*args)
|
274
|
+
super
|
275
|
+
@delimiter = ','
|
276
|
+
@raw_values = []
|
277
|
+
end
|
278
|
+
|
279
|
+
def update_date_times(dt, is_floating = false)
|
280
|
+
values = []
|
281
|
+
|
282
|
+
if time?
|
283
|
+
tz = nil
|
284
|
+
is_utc = false
|
285
|
+
|
286
|
+
dt.each do |d|
|
287
|
+
if is_floating
|
288
|
+
values << d.strftime('%Y%m%dT%H%M%S')
|
289
|
+
next
|
290
|
+
end
|
291
|
+
|
292
|
+
if tz.nil?
|
293
|
+
tz = d.time_zone
|
294
|
+
is_utc = ['UTC', 'GMT', 'Z', '+00:00'].include?(tz.name)
|
295
|
+
|
296
|
+
self['TZID'] = tz.name unless is_utc
|
297
|
+
else
|
298
|
+
d = d.in_time_zone(tz)
|
299
|
+
end
|
300
|
+
|
301
|
+
if is_utc
|
302
|
+
values << d.strftime('%Y%m%dT%H%M%SZ')
|
303
|
+
else
|
304
|
+
values << d.strftime('%Y%m%dT%H%M%S')
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
delete('TZID') if is_utc || is_floating
|
309
|
+
else
|
310
|
+
dt.each do |d|
|
311
|
+
values << d.strftime('%Y%m%d')
|
312
|
+
end
|
313
|
+
delete('TZID')
|
314
|
+
end
|
315
|
+
|
316
|
+
@value = values
|
317
|
+
end
|
318
|
+
|
319
|
+
def floating
|
320
|
+
floating?
|
321
|
+
end
|
322
|
+
|
323
|
+
def floating=(is_floating)
|
324
|
+
update_date_times(date_times, is_floating)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module ICalendar
|
5
|
+
# Duration property.
|
6
|
+
#
|
7
|
+
# This object represents DURATION values, as defined here:
|
8
|
+
#
|
9
|
+
# http://tools.ietf.org/html/rfc5545#section-3.3.6
|
10
|
+
class Duration < Property
|
11
|
+
# In case this is a multi-value property. This string will be used as a
|
12
|
+
# delimiter.
|
13
|
+
#
|
14
|
+
# @var string|null
|
15
|
+
attr_accessor :delimiter
|
16
|
+
|
17
|
+
# Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
18
|
+
#
|
19
|
+
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
20
|
+
# not yet done, but parameters are not included.
|
21
|
+
#
|
22
|
+
# @param string val
|
23
|
+
#
|
24
|
+
# @return void
|
25
|
+
def raw_mime_dir_value=(val)
|
26
|
+
self.value = val.split(@delimiter)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns a raw mime-dir representation of the value.
|
30
|
+
#
|
31
|
+
# @return string
|
32
|
+
def raw_mime_dir_value
|
33
|
+
parts.join(@delimiter)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the type of value.
|
37
|
+
#
|
38
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
39
|
+
# 'default' valueType.
|
40
|
+
#
|
41
|
+
# @return string
|
42
|
+
def value_type
|
43
|
+
'DURATION'
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns a DateInterval representation of the Duration property.
|
47
|
+
#
|
48
|
+
# If the property has more than one value, only the first is returned.
|
49
|
+
#
|
50
|
+
# @return \DateInterval
|
51
|
+
def date_interval
|
52
|
+
parts = self.parts
|
53
|
+
value = parts[0]
|
54
|
+
DateTimeParser.parse_duration(value)
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize(*args)
|
58
|
+
super(*args)
|
59
|
+
@delimiter = ','
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module ICalendar
|
5
|
+
# Period property.
|
6
|
+
#
|
7
|
+
# This object represents PERIOD values, as defined here:
|
8
|
+
#
|
9
|
+
# http://tools.ietf.org/html/rfc5545#section-3.8.2.6
|
10
|
+
class Period < Property
|
11
|
+
# In case this is a multi-value property. This string will be used as a
|
12
|
+
# delimiter.
|
13
|
+
#
|
14
|
+
# @var string|null
|
15
|
+
attr_accessor :delimiter
|
16
|
+
|
17
|
+
# Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
18
|
+
#
|
19
|
+
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
20
|
+
# not yet done, but parameters are not included.
|
21
|
+
#
|
22
|
+
# @param string val
|
23
|
+
#
|
24
|
+
# @return void
|
25
|
+
def raw_mime_dir_value=(val)
|
26
|
+
self.value = val.split(@delimiter)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns a raw mime-dir representation of the value.
|
30
|
+
#
|
31
|
+
# @return string
|
32
|
+
def raw_mime_dir_value
|
33
|
+
parts.join(@delimiter)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the type of value.
|
37
|
+
#
|
38
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
39
|
+
# 'default' valueType.
|
40
|
+
#
|
41
|
+
# @return string
|
42
|
+
def value_type
|
43
|
+
'PERIOD'
|
44
|
+
end
|
45
|
+
|
46
|
+
# Sets the json value, as it would appear in a jCard or jCal object.
|
47
|
+
#
|
48
|
+
# The value must always be an array.
|
49
|
+
#
|
50
|
+
# @param array value
|
51
|
+
#
|
52
|
+
# @return void
|
53
|
+
def json_value=(value)
|
54
|
+
value = value.values if value.is_a?(Hash)
|
55
|
+
value = value.map do |item|
|
56
|
+
item = item.values if item.is_a?(Hash)
|
57
|
+
item.join('/').delete(':').delete('-')
|
58
|
+
end
|
59
|
+
super(value)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the value, in the format it should be encoded for json.
|
63
|
+
#
|
64
|
+
# This method must always return an array.
|
65
|
+
#
|
66
|
+
# @return array
|
67
|
+
def json_value
|
68
|
+
result = []
|
69
|
+
parts.each do |item|
|
70
|
+
(start, ending) = item.split('/', 2)
|
71
|
+
|
72
|
+
start = Tilia::VObject::DateTimeParser.parse_date_time(start)
|
73
|
+
|
74
|
+
# This is a duration value.
|
75
|
+
if ending[0] == 'P'
|
76
|
+
result << [
|
77
|
+
start.strftime('%Y-%m-%dT%H:%M:%S'),
|
78
|
+
ending
|
79
|
+
]
|
80
|
+
else
|
81
|
+
ending = Tilia::VObject::DateTimeParser.parse_date_time(ending)
|
82
|
+
result << [
|
83
|
+
start.strftime('%Y-%m-%dT%H:%M:%S'),
|
84
|
+
ending.strftime('%Y-%m-%dT%H:%M:%S')
|
85
|
+
]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
result
|
90
|
+
end
|
91
|
+
|
92
|
+
protected
|
93
|
+
|
94
|
+
# This method serializes only the value of a property. This is used to
|
95
|
+
# create xCard or xCal documents.
|
96
|
+
#
|
97
|
+
# @param Xml\Writer writer XML writer.
|
98
|
+
#
|
99
|
+
# @return void
|
100
|
+
def xml_serialize_value(writer)
|
101
|
+
writer.start_element(value_type.downcase)
|
102
|
+
|
103
|
+
value = json_value
|
104
|
+
writer.write_element('start', value[0][0])
|
105
|
+
|
106
|
+
if value[0][1][0] == 'P'
|
107
|
+
writer.write_element('duration', value[0][1])
|
108
|
+
else
|
109
|
+
writer.write_element('end', value[0][1])
|
110
|
+
end
|
111
|
+
writer.end_element
|
112
|
+
end
|
113
|
+
|
114
|
+
public
|
115
|
+
|
116
|
+
def initialize(*args)
|
117
|
+
super(*args)
|
118
|
+
@delimiter = ','
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|