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,78 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
# URI property.
|
5
|
+
#
|
6
|
+
# This object encodes URI values. vCard 2.1 calls these URL.
|
7
|
+
class Uri < Text
|
8
|
+
# In case this is a multi-value property. This string will be used as a
|
9
|
+
# delimiter.
|
10
|
+
#
|
11
|
+
# @var string|null
|
12
|
+
attr_accessor :delimiter
|
13
|
+
|
14
|
+
# Returns the type of value.
|
15
|
+
#
|
16
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
17
|
+
# 'default' valueType.
|
18
|
+
#
|
19
|
+
# @return string
|
20
|
+
def value_type
|
21
|
+
'URI'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
25
|
+
#
|
26
|
+
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
27
|
+
# not yet done, but parameters are not included.
|
28
|
+
#
|
29
|
+
# @param string val
|
30
|
+
#
|
31
|
+
# @return void
|
32
|
+
def raw_mime_dir_value=(val)
|
33
|
+
# Normally we don't need to do any type of unescaping for these
|
34
|
+
# properties, however.. we've noticed that Google Contacts
|
35
|
+
# specifically escapes the colon (:) with a blackslash. While I have
|
36
|
+
# no clue why they thought that was a good idea, I'm unescaping it
|
37
|
+
# anyway.
|
38
|
+
#
|
39
|
+
# Good thing backslashes are not allowed in urls. Makes it easy to
|
40
|
+
# assume that a backslash is always intended as an escape character.
|
41
|
+
if name == 'URL'
|
42
|
+
new_val = ''
|
43
|
+
val.split(/ (?: (\\\\ (?: \\\\ | : ) ) ) /x).each do |match|
|
44
|
+
case match
|
45
|
+
when '\\:'
|
46
|
+
new_val += ':'
|
47
|
+
else
|
48
|
+
new_val << match
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
@value = new_val
|
53
|
+
else
|
54
|
+
@value = val.gsub('\\,', ',')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns a raw mime-dir representation of the value.
|
59
|
+
#
|
60
|
+
# @return string
|
61
|
+
def raw_mime_dir_value
|
62
|
+
if @value.is_a?(Array)
|
63
|
+
value = @value[0]
|
64
|
+
else
|
65
|
+
value = @value
|
66
|
+
end
|
67
|
+
|
68
|
+
value.gsub(',', '\\,')
|
69
|
+
end
|
70
|
+
|
71
|
+
def initialize(*args)
|
72
|
+
super(*args)
|
73
|
+
@delimiter = nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
# UtcOffset property.
|
5
|
+
#
|
6
|
+
# This object encodes UTC-OFFSET values.
|
7
|
+
class UtcOffset < Text
|
8
|
+
# In case this is a multi-value property. This string will be used as a
|
9
|
+
# delimiter.
|
10
|
+
#
|
11
|
+
# @var string|null
|
12
|
+
attr_accessor :delimiter
|
13
|
+
|
14
|
+
# Returns the type of value.
|
15
|
+
#
|
16
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
17
|
+
# 'default' valueType.
|
18
|
+
#
|
19
|
+
# @return string
|
20
|
+
def value_type
|
21
|
+
'UTC-OFFSET'
|
22
|
+
end
|
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
|
+
#
|
30
|
+
# @return void
|
31
|
+
def json_value=(value)
|
32
|
+
value = value.map do |v|
|
33
|
+
v.delete(':')
|
34
|
+
end
|
35
|
+
super(value)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the value, in the format it should be encoded for JSON.
|
39
|
+
#
|
40
|
+
# This method must always return an array.
|
41
|
+
#
|
42
|
+
# @return array
|
43
|
+
def json_value
|
44
|
+
super.map do |value|
|
45
|
+
"#{value[0...-2]}:#{value[-2..-1]}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def initialize(*args)
|
50
|
+
super(*args)
|
51
|
+
@delimiter = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module VCard
|
5
|
+
# Date property.
|
6
|
+
#
|
7
|
+
# This object encodes vCard DATE values.
|
8
|
+
class Date < DateAndOrTime
|
9
|
+
# Returns the type of value.
|
10
|
+
#
|
11
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
12
|
+
# 'default' valueType.
|
13
|
+
#
|
14
|
+
# @return string
|
15
|
+
def value_type
|
16
|
+
'DATE'
|
17
|
+
end
|
18
|
+
|
19
|
+
# Sets the property as a DateTime object.
|
20
|
+
#
|
21
|
+
# @param \DateTimeInterface dt
|
22
|
+
#
|
23
|
+
# @return void
|
24
|
+
def date_time=(dt)
|
25
|
+
@value = dt.strftime('%Y%m%d')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,343 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module VCard
|
5
|
+
# DateAndOrTime property.
|
6
|
+
#
|
7
|
+
# This object encodes DATE-AND-OR-TIME values.
|
8
|
+
class DateAndOrTime < Property
|
9
|
+
# Field separator.
|
10
|
+
#
|
11
|
+
# @var null|string
|
12
|
+
attr_accessor :delimiter
|
13
|
+
|
14
|
+
# Returns the type of value.
|
15
|
+
#
|
16
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
17
|
+
# 'default' valueType.
|
18
|
+
#
|
19
|
+
# @return string
|
20
|
+
def value_type
|
21
|
+
'DATE-AND-OR-TIME'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Sets a multi-valued property.
|
25
|
+
#
|
26
|
+
# You may also specify DateTime objects here.
|
27
|
+
#
|
28
|
+
# @param array parts
|
29
|
+
#
|
30
|
+
# @return void
|
31
|
+
def parts=(parts)
|
32
|
+
fail ArgumentError, 'Only one value allowed' if parts.size > 1
|
33
|
+
|
34
|
+
if parts[0].is_a?(::Time)
|
35
|
+
self.date_time = parts[0]
|
36
|
+
else
|
37
|
+
super(parts)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Updates the current value.
|
42
|
+
#
|
43
|
+
# This may be either a single, or multiple strings in an array.
|
44
|
+
#
|
45
|
+
# Instead of strings, you may also use DateTime here.
|
46
|
+
#
|
47
|
+
# @param string|array|\DateTime value
|
48
|
+
#
|
49
|
+
# @return void
|
50
|
+
def value=(value)
|
51
|
+
if value.is_a?(::Time)
|
52
|
+
self.date_time = value
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Sets the property as a DateTime object.
|
59
|
+
#
|
60
|
+
# @param DateTimeInterface dt
|
61
|
+
#
|
62
|
+
# @return void
|
63
|
+
def date_time=(dt)
|
64
|
+
tz = dt.time_zone
|
65
|
+
is_utc = ['UTC', 'GMT', 'Z'].include?(tz.name)
|
66
|
+
|
67
|
+
if is_utc
|
68
|
+
value = dt.strftime('%Y%m%dT%H%M%SZ')
|
69
|
+
else
|
70
|
+
# Calculating the offset.
|
71
|
+
value = dt.strftime('%Y%m%dT%H%M%S%z')
|
72
|
+
end
|
73
|
+
|
74
|
+
@value = value
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns a date-time value.
|
78
|
+
#
|
79
|
+
# Note that if this property contained more than 1 date-time, only the
|
80
|
+
# first will be returned. To get an array with multiple values, call
|
81
|
+
# getDateTimes.
|
82
|
+
#
|
83
|
+
# If no time was specified, we will always use midnight (in the default
|
84
|
+
# timezone) as the time.
|
85
|
+
#
|
86
|
+
# If parts of the date were omitted, such as the year, we will grab the
|
87
|
+
# current values for those. So at the time of writing, if the year was
|
88
|
+
# omitted, we would have filled in 2014.
|
89
|
+
#
|
90
|
+
# @return DateTimeImmutable
|
91
|
+
def date_time
|
92
|
+
now = ::Time.zone.now
|
93
|
+
|
94
|
+
tz_format = now.utc_offset == 0 ? 'Z' : '%z'
|
95
|
+
now_parts = DateTimeParser.parse_v_card_date_time(now.strftime('%Y%m%dT%H%M%S' + tz_format))
|
96
|
+
date_parts = DateTimeParser.parse_v_card_date_time(value)
|
97
|
+
|
98
|
+
# This sets all the missing parts to the current date/time.
|
99
|
+
# So if the year was missing for a birthday, we're making it 'this
|
100
|
+
# year'.
|
101
|
+
date_parts.each do |k, v|
|
102
|
+
date_parts[k] = now_parts[k] unless v
|
103
|
+
end
|
104
|
+
|
105
|
+
# Now follows a ruby Hack
|
106
|
+
offset = date_parts['timezone'][0..2].to_f + date_parts['timezone'][3..4].to_f / 100
|
107
|
+
tz = ActiveSupport::TimeZone.new(offset)
|
108
|
+
datetime = tz.parse("#{date_parts['year']}-#{date_parts['month']}-#{date_parts['date']} #{date_parts['hour']}:#{date_parts['minute']}:#{date_parts['second']}")
|
109
|
+
unless datetime.strftime('%z') == date_parts['timezone']
|
110
|
+
tz = ActiveSupport::TimeZone.new(offset - 1.0)
|
111
|
+
datetime = tz.parse("#{date_parts['year']}-#{date_parts['month']}-#{date_parts['date']} #{date_parts['hour']}:#{date_parts['minute']}:#{date_parts['second']}")
|
112
|
+
end
|
113
|
+
# continue as usual
|
114
|
+
|
115
|
+
datetime.freeze
|
116
|
+
datetime
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns the value, in the format it should be encoded for json.
|
120
|
+
#
|
121
|
+
# This method must always return an array.
|
122
|
+
#
|
123
|
+
# @return array
|
124
|
+
def json_value
|
125
|
+
parts = DateTimeParser.parse_v_card_date_time(value)
|
126
|
+
|
127
|
+
date_str = ''
|
128
|
+
|
129
|
+
# Year
|
130
|
+
if !parts['year'].nil?
|
131
|
+
date_str += format('%02i', parts['year'])
|
132
|
+
|
133
|
+
unless parts['month'].nil?
|
134
|
+
# If a year and a month is set, we need to insert a separator
|
135
|
+
# dash.
|
136
|
+
date_str += '-'
|
137
|
+
end
|
138
|
+
else
|
139
|
+
if !parts['month'].nil? || !parts['date'].nil?
|
140
|
+
# Inserting two dashes
|
141
|
+
date_str += '--'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Month
|
146
|
+
if !parts['month'].nil?
|
147
|
+
date_str += format('%02i', parts['month'])
|
148
|
+
|
149
|
+
if parts['date']
|
150
|
+
# If month and date are set, we need the separator dash.
|
151
|
+
date_str += '-'
|
152
|
+
end
|
153
|
+
elsif parts['date']
|
154
|
+
# If the month is empty, and a date is set, we need a 'empty
|
155
|
+
# dash'
|
156
|
+
date_str += '-'
|
157
|
+
end
|
158
|
+
|
159
|
+
# Date
|
160
|
+
date_str += format('%02i', parts['date']) unless parts['date'].nil?
|
161
|
+
|
162
|
+
# Early exit if we don't have a time string.
|
163
|
+
if parts['hour'].nil? && parts['minute'].nil? && parts['second'].nil?
|
164
|
+
return [date_str]
|
165
|
+
end
|
166
|
+
|
167
|
+
date_str += 'T'
|
168
|
+
|
169
|
+
# Hour
|
170
|
+
if !parts['hour'].nil?
|
171
|
+
date_str += format('%02i', parts['hour'])
|
172
|
+
|
173
|
+
date_str += ':' unless parts['minute'].nil?
|
174
|
+
else
|
175
|
+
# We know either minute or second _must_ be set, so we insert a
|
176
|
+
# dash for an empty value.
|
177
|
+
date_str += '-'
|
178
|
+
end
|
179
|
+
|
180
|
+
# Minute
|
181
|
+
if !parts['minute'].nil?
|
182
|
+
date_str += format('%02i', parts['minute'])
|
183
|
+
|
184
|
+
date_str += ':' unless parts['second'].nil?
|
185
|
+
elsif parts['second']
|
186
|
+
# Dash for empty minute
|
187
|
+
date_str += '-'
|
188
|
+
end
|
189
|
+
|
190
|
+
# Second
|
191
|
+
date_str += format('%02i', parts['second']) unless parts['second'].nil?
|
192
|
+
|
193
|
+
# Timezone
|
194
|
+
date_str += parts['timezone'] unless parts['timezone'].nil?
|
195
|
+
|
196
|
+
[date_str]
|
197
|
+
end
|
198
|
+
|
199
|
+
protected
|
200
|
+
|
201
|
+
# This method serializes only the value of a property. This is used to
|
202
|
+
# create xCard or xCal documents.
|
203
|
+
#
|
204
|
+
# @param Xml\Writer writer XML writer.
|
205
|
+
#
|
206
|
+
# @return void
|
207
|
+
def xml_serialize_value(writer)
|
208
|
+
value_type = self.value_type.downcase
|
209
|
+
parts = DateTimeParser.parse_v_card_date_and_or_time(value)
|
210
|
+
value = ''
|
211
|
+
|
212
|
+
# d = defined
|
213
|
+
d = lambda do |part|
|
214
|
+
!parts[part].nil?
|
215
|
+
end
|
216
|
+
|
217
|
+
# r = read
|
218
|
+
r = lambda do |part|
|
219
|
+
parts[part] || ''
|
220
|
+
end
|
221
|
+
|
222
|
+
# From the Relax NG Schema.
|
223
|
+
#
|
224
|
+
# # 4.3.1
|
225
|
+
# value-date = element date {
|
226
|
+
# xsd:string { pattern = "\d{8}|\d{4}-\d\d|--\d\d(\d\d)?|---\d\d" }
|
227
|
+
# }
|
228
|
+
if (d.call('year') || d.call('month') || d.call('date')) && (!d.call('hour') && !d.call('minute') && !d.call('second') && !d.call('timezone'))
|
229
|
+
if d.call('year') && d.call('month') && d.call('date')
|
230
|
+
value += r.call('year') + r.call('month') + r.call('date')
|
231
|
+
elsif d.call('year') && d.call('month') && !d.call('date')
|
232
|
+
value += r.call('year') + '-' + r.call('month')
|
233
|
+
elsif !d.call('year') && d.call('month')
|
234
|
+
value += '--' + r.call('month') + r.call('date')
|
235
|
+
elsif !d.call('year') && !d.call('month') && d.call('date')
|
236
|
+
value += '---' + r.call('date')
|
237
|
+
end
|
238
|
+
|
239
|
+
# # 4.3.2
|
240
|
+
# value-time = element time {
|
241
|
+
# xsd:string { pattern = "(\d\d.call(\d\d.call(\d\d)?)?|-\d\d.call(\d\d?)|--\d\d)"
|
242
|
+
# ~ "(Z|[+\-]\d\d.call(\d\d)?)?" }
|
243
|
+
# }
|
244
|
+
elsif (!d.call('year') && !d.call('month') && !d.call('date')) && (d.call('hour') || d.call('minute') || d.call('second'))
|
245
|
+
if d.call('hour')
|
246
|
+
value += r.call('hour') + r.call('minute') + r.call('second')
|
247
|
+
elsif d.call('minute')
|
248
|
+
value += '-' + r.call('minute') + r.call('second')
|
249
|
+
elsif d.call('second')
|
250
|
+
value += '--' + r.call('second')
|
251
|
+
end
|
252
|
+
|
253
|
+
value += r.call('timezone')
|
254
|
+
|
255
|
+
# # 4.3.3
|
256
|
+
# value-date-time = element date-time {
|
257
|
+
# xsd:string { pattern = "(\d{8}|--\d{4}|---\d\d)T\d\d.call(\d\d.call(\d\d)?)?"
|
258
|
+
# ~ "(Z|[+\-]\d\d.call(\d\d)?)?" }
|
259
|
+
# }
|
260
|
+
elsif d.call('date') && d.call('hour')
|
261
|
+
|
262
|
+
if d.call('year') && d.call('month') && d.call('date')
|
263
|
+
value += r.call('year') + r.call('month') + r.call('date')
|
264
|
+
elsif !d.call('year') && d.call('month') && d.call('date')
|
265
|
+
value += '--' + r.call('month') + r.call('date')
|
266
|
+
elsif !d.call('year') && !d.call('month') && d.call('date')
|
267
|
+
value += '---' + r.call('date')
|
268
|
+
end
|
269
|
+
|
270
|
+
value += 'T' + r.call('hour') + r.call('minute') + r.call('second') +
|
271
|
+
r.call('timezone')
|
272
|
+
end
|
273
|
+
|
274
|
+
writer.write_element(value_type, value)
|
275
|
+
end
|
276
|
+
|
277
|
+
public
|
278
|
+
|
279
|
+
# Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
280
|
+
#
|
281
|
+
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
282
|
+
# not yet done, but parameters are not included.
|
283
|
+
#
|
284
|
+
# @param string val
|
285
|
+
#
|
286
|
+
# @return void
|
287
|
+
def raw_mime_dir_value=(val)
|
288
|
+
self.value = val
|
289
|
+
end
|
290
|
+
|
291
|
+
# Returns a raw mime-dir representation of the value.
|
292
|
+
#
|
293
|
+
# @return string
|
294
|
+
def raw_mime_dir_value
|
295
|
+
parts.join(@delimiter)
|
296
|
+
end
|
297
|
+
|
298
|
+
# Validates the node for correctness.
|
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
|
318
|
+
def validate(options = 0)
|
319
|
+
messages = super(options)
|
320
|
+
value = self.value
|
321
|
+
|
322
|
+
begin
|
323
|
+
DateTimeParser.parse_v_card_date_time(value)
|
324
|
+
rescue ArgumentError
|
325
|
+
messages << {
|
326
|
+
'level' => 3,
|
327
|
+
'message' => "The supplied value (#{value}) is not a correct DATE-AND-OR-TIME property",
|
328
|
+
'node' => self
|
329
|
+
}
|
330
|
+
end
|
331
|
+
|
332
|
+
messages
|
333
|
+
end
|
334
|
+
|
335
|
+
def initialize(*args)
|
336
|
+
super(*args)
|
337
|
+
@delimiter = nil
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module VCard
|
5
|
+
# DateTime property.
|
6
|
+
#
|
7
|
+
# This object encodes DATE-TIME values for vCards.
|
8
|
+
class DateTime < DateAndOrTime
|
9
|
+
# Returns the type of value.
|
10
|
+
#
|
11
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
12
|
+
# 'default' valueType.
|
13
|
+
#
|
14
|
+
# @return string
|
15
|
+
def value_type
|
16
|
+
'DATE-TIME'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module VCard
|
5
|
+
# LanguageTag property.
|
6
|
+
#
|
7
|
+
# This object represents LANGUAGE-TAG values as used in vCards.
|
8
|
+
class LanguageTag < Property
|
9
|
+
# Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
10
|
+
#
|
11
|
+
# This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
12
|
+
# not yet done, but parameters are not included.
|
13
|
+
#
|
14
|
+
# @param string val
|
15
|
+
#
|
16
|
+
# @return void
|
17
|
+
def raw_mime_dir_value=(val)
|
18
|
+
self.value = val
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns a raw mime-dir representation of the value.
|
22
|
+
#
|
23
|
+
# @return string
|
24
|
+
def raw_mime_dir_value
|
25
|
+
value
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the type of value.
|
29
|
+
#
|
30
|
+
# This corresponds to the VALUE= parameter. Every property also has a
|
31
|
+
# 'default' valueType.
|
32
|
+
#
|
33
|
+
# @return string
|
34
|
+
def value_type
|
35
|
+
'LANGUAGE-TAG'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module VCard
|
5
|
+
# TimeStamp property.
|
6
|
+
#
|
7
|
+
# This object encodes TIMESTAMP values.
|
8
|
+
class TimeStamp < 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
|
+
'TIMESTAMP'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the value, in the format it should be encoded for json.
|
26
|
+
#
|
27
|
+
# This method must always return an array.
|
28
|
+
#
|
29
|
+
# @return array
|
30
|
+
def json_value
|
31
|
+
parts = DateTimeParser.parse_v_card_date_time(value)
|
32
|
+
|
33
|
+
date_str = format(
|
34
|
+
'%04i-%02i-%02iT%02i:%02i:%02i',
|
35
|
+
parts['year'],
|
36
|
+
parts['month'],
|
37
|
+
parts['date'],
|
38
|
+
parts['hour'],
|
39
|
+
parts['minute'],
|
40
|
+
parts['second']
|
41
|
+
)
|
42
|
+
|
43
|
+
# Timezone
|
44
|
+
date_str += parts['timezone'] unless parts['timezone'].blank?
|
45
|
+
|
46
|
+
[date_str]
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
# This method serializes only the value of a property. This is used to
|
52
|
+
# create xCard or xCal documents.
|
53
|
+
#
|
54
|
+
# @param Xml\Writer writer XML writer.
|
55
|
+
#
|
56
|
+
# @return void
|
57
|
+
def xml_serialize_value(writer)
|
58
|
+
# xCard is the only XML and JSON format that has the same date and time
|
59
|
+
# format than vCard.
|
60
|
+
value_type = self.value_type.downcase
|
61
|
+
writer.write_element(value_type, value)
|
62
|
+
end
|
63
|
+
|
64
|
+
public
|
65
|
+
|
66
|
+
def initialize(*args)
|
67
|
+
super(*args)
|
68
|
+
@delimiter = nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Property
|
4
|
+
module VCard
|
5
|
+
require 'tilia/v_object/property/v_card/date_and_or_time'
|
6
|
+
require 'tilia/v_object/property/v_card/date'
|
7
|
+
require 'tilia/v_object/property/v_card/date_time'
|
8
|
+
require 'tilia/v_object/property/v_card/language_tag'
|
9
|
+
require 'tilia/v_object/property/v_card/time_stamp'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|