tilia-vobject 4.0.0.pre.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rubocop.yml +32 -0
  4. data/.simplecov +4 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.sabre.md +626 -0
  7. data/CONTRIBUTING.md +25 -0
  8. data/Gemfile +17 -0
  9. data/Gemfile.lock +68 -0
  10. data/LICENSE +27 -0
  11. data/LICENSE.sabre +27 -0
  12. data/README.md +63 -0
  13. data/Rakefile +17 -0
  14. data/bin/vobject +7 -0
  15. data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
  16. data/lib/tilia/v_object/cli.rb +582 -0
  17. data/lib/tilia/v_object/component/available.rb +107 -0
  18. data/lib/tilia/v_object/component/v_alarm.rb +114 -0
  19. data/lib/tilia/v_object/component/v_availability.rb +128 -0
  20. data/lib/tilia/v_object/component/v_calendar.rb +468 -0
  21. data/lib/tilia/v_object/component/v_card.rb +457 -0
  22. data/lib/tilia/v_object/component/v_event.rb +127 -0
  23. data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
  24. data/lib/tilia/v_object/component/v_journal.rb +75 -0
  25. data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
  26. data/lib/tilia/v_object/component/v_todo.rb +147 -0
  27. data/lib/tilia/v_object/component.rb +591 -0
  28. data/lib/tilia/v_object/date_time_parser.rb +486 -0
  29. data/lib/tilia/v_object/document.rb +218 -0
  30. data/lib/tilia/v_object/element_list.rb +18 -0
  31. data/lib/tilia/v_object/eof_exception.rb +8 -0
  32. data/lib/tilia/v_object/free_busy_data.rb +149 -0
  33. data/lib/tilia/v_object/free_busy_generator.rb +465 -0
  34. data/lib/tilia/v_object/i_tip/broker.rb +909 -0
  35. data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
  36. data/lib/tilia/v_object/i_tip/message.rb +109 -0
  37. data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
  38. data/lib/tilia/v_object/i_tip.rb +10 -0
  39. data/lib/tilia/v_object/node.rb +192 -0
  40. data/lib/tilia/v_object/parameter.rb +327 -0
  41. data/lib/tilia/v_object/parse_exception.rb +7 -0
  42. data/lib/tilia/v_object/parser/json.rb +149 -0
  43. data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
  44. data/lib/tilia/v_object/parser/parser.rb +61 -0
  45. data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
  46. data/lib/tilia/v_object/parser/xml/element.rb +11 -0
  47. data/lib/tilia/v_object/parser/xml.rb +322 -0
  48. data/lib/tilia/v_object/parser.rb +10 -0
  49. data/lib/tilia/v_object/property/binary.rb +96 -0
  50. data/lib/tilia/v_object/property/boolean.rb +57 -0
  51. data/lib/tilia/v_object/property/flat_text.rb +52 -0
  52. data/lib/tilia/v_object/property/float_value.rb +107 -0
  53. data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
  54. data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
  55. data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
  56. data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
  57. data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
  58. data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
  59. data/lib/tilia/v_object/property/i_calendar.rb +14 -0
  60. data/lib/tilia/v_object/property/integer_value.rb +60 -0
  61. data/lib/tilia/v_object/property/text.rb +352 -0
  62. data/lib/tilia/v_object/property/time.rb +85 -0
  63. data/lib/tilia/v_object/property/unknown.rb +30 -0
  64. data/lib/tilia/v_object/property/uri.rb +78 -0
  65. data/lib/tilia/v_object/property/utc_offset.rb +56 -0
  66. data/lib/tilia/v_object/property/v_card/date.rb +31 -0
  67. data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
  68. data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
  69. data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
  70. data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
  71. data/lib/tilia/v_object/property/v_card.rb +13 -0
  72. data/lib/tilia/v_object/property.rb +532 -0
  73. data/lib/tilia/v_object/reader.rb +73 -0
  74. data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
  75. data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
  76. data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
  77. data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
  78. data/lib/tilia/v_object/recur.rb +10 -0
  79. data/lib/tilia/v_object/settings.rb +32 -0
  80. data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
  81. data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
  82. data/lib/tilia/v_object/splitter/v_card.rb +56 -0
  83. data/lib/tilia/v_object/splitter.rb +9 -0
  84. data/lib/tilia/v_object/string_util.rb +58 -0
  85. data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
  86. data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
  87. data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
  88. data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
  89. data/lib/tilia/v_object/time_zone_data.rb +10 -0
  90. data/lib/tilia/v_object/time_zone_util.rb +213 -0
  91. data/lib/tilia/v_object/uuid_util.rb +51 -0
  92. data/lib/tilia/v_object/v_card_converter.rb +354 -0
  93. data/lib/tilia/v_object/version.rb +9 -0
  94. data/lib/tilia/v_object/writer.rb +56 -0
  95. data/lib/tilia/v_object.rb +45 -0
  96. data/lib/tilia/vobject.rb +1 -0
  97. data/resources/schema/xcal.rng +1192 -0
  98. data/resources/schema/xcard.rng +388 -0
  99. data/test/test_helper.rb +56 -0
  100. data/test/v_object/attach_issue_test.rb +19 -0
  101. data/test/v_object/birthday_calendar_generator_test.rb +463 -0
  102. data/test/v_object/cli_mock.rb +19 -0
  103. data/test/v_object/cli_test.rb +460 -0
  104. data/test/v_object/component/available_test.rb +59 -0
  105. data/test/v_object/component/v_alarm_test.rb +160 -0
  106. data/test/v_object/component/v_availability_test.rb +388 -0
  107. data/test/v_object/component/v_calendar_test.rb +646 -0
  108. data/test/v_object/component/v_card_test.rb +258 -0
  109. data/test/v_object/component/v_event_test.rb +85 -0
  110. data/test/v_object/component/v_free_busy_test.rb +59 -0
  111. data/test/v_object/component/v_journal_test.rb +85 -0
  112. data/test/v_object/component/v_time_zone_test.rb +47 -0
  113. data/test/v_object/component/v_todo_test.rb +172 -0
  114. data/test/v_object/component_test.rb +419 -0
  115. data/test/v_object/date_time_parser_test.rb +526 -0
  116. data/test/v_object/document_test.rb +71 -0
  117. data/test/v_object/element_list_test.rb +27 -0
  118. data/test/v_object/em_client_test.rb +53 -0
  119. data/test/v_object/empty_parameter_test.rb +65 -0
  120. data/test/v_object/empty_value_issue_test.rb +25 -0
  121. data/test/v_object/fake_component.rb +21 -0
  122. data/test/v_object/free_busy_data_test.rb +285 -0
  123. data/test/v_object/free_busy_generator_test.rb +637 -0
  124. data/test/v_object/google_colon_escaping_test.rb +27 -0
  125. data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
  126. data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
  127. data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
  128. data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
  129. data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
  130. data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
  131. data/test/v_object/i_tip/broker_tester.rb +71 -0
  132. data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
  133. data/test/v_object/i_tip/evolution_test.rb +2644 -0
  134. data/test/v_object/i_tip/message_test.rb +25 -0
  135. data/test/v_object/issue153.vcf +352 -0
  136. data/test/v_object/issue153_test.rb +12 -0
  137. data/test/v_object/issue26_test.rb +25 -0
  138. data/test/v_object/issue36_work_around_test.rb +37 -0
  139. data/test/v_object/issue40_test.rb +26 -0
  140. data/test/v_object/issue64.vcf +351 -0
  141. data/test/v_object/issue64_test.rb +17 -0
  142. data/test/v_object/issue96_test.rb +22 -0
  143. data/test/v_object/issue_undefined_index_test.rb +24 -0
  144. data/test/v_object/j_cal_test.rb +150 -0
  145. data/test/v_object/j_card_test.rb +192 -0
  146. data/test/v_object/line_folding_issue_test.rb +19 -0
  147. data/test/v_object/mock_document.rb +6 -0
  148. data/test/v_object/parameter_test.rb +109 -0
  149. data/test/v_object/parser/json_test.rb +370 -0
  150. data/test/v_object/parser/mime_dir_test.rb +14 -0
  151. data/test/v_object/parser/quoted_printable_test.rb +78 -0
  152. data/test/v_object/parser/xml_test.rb +2563 -0
  153. data/test/v_object/property/binary_test.rb +12 -0
  154. data/test/v_object/property/boolean_test.rb +18 -0
  155. data/test/v_object/property/compound_test.rb +43 -0
  156. data/test/v_object/property/float_test.rb +20 -0
  157. data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
  158. data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
  159. data/test/v_object/property/i_calendar/duration_test.rb +14 -0
  160. data/test/v_object/property/i_calendar/recur_test.rb +39 -0
  161. data/test/v_object/property/text_test.rb +81 -0
  162. data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
  163. data/test/v_object/property/v_card/language_tag_test.rb +35 -0
  164. data/test/v_object/property_test.rb +338 -0
  165. data/test/v_object/reader_test.rb +403 -0
  166. data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
  167. data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
  168. data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
  169. data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
  170. data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
  171. data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
  172. data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
  173. data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
  174. data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
  175. data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
  176. data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
  177. data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
  178. data/test/v_object/recur/r_date_iterator_test.rb +44 -0
  179. data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
  180. data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
  181. data/test/v_object/slash_r_test.rb +15 -0
  182. data/test/v_object/splitter/i_calendar_test.rb +299 -0
  183. data/test/v_object/splitter/v_card_test.rb +173 -0
  184. data/test/v_object/string_util_test.rb +37 -0
  185. data/test/v_object/test_case.rb +42 -0
  186. data/test/v_object/time_zone_util_test.rb +271 -0
  187. data/test/v_object/uuid_util_test.rb +18 -0
  188. data/test/v_object/v_card21_test.rb +43 -0
  189. data/test/v_object/v_card_converter_test.rb +419 -0
  190. data/test/v_object/version_test.rb +15 -0
  191. data/test/v_object/writer_test.rb +33 -0
  192. data/tilia-vobject.gemspec +17 -0
  193. metadata +308 -0
@@ -0,0 +1,121 @@
1
+ module Tilia
2
+ module VObject
3
+ module TimeZoneData
4
+ # Automatically generated timezone file
5
+ #
6
+ # Last update: 2015-07-27T16:56:36-04:00
7
+ # Source: http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml
8
+ module WindowsZones
9
+ def self.list
10
+ {
11
+ 'AUS Central Standard Time' => 'Australia/Darwin',
12
+ 'AUS Eastern Standard Time' => 'Australia/Sydney',
13
+ 'Afghanistan Standard Time' => 'Asia/Kabul',
14
+ 'Alaskan Standard Time' => 'America/Anchorage',
15
+ 'Arab Standard Time' => 'Asia/Riyadh',
16
+ 'Arabian Standard Time' => 'Asia/Dubai',
17
+ 'Arabic Standard Time' => 'Asia/Baghdad',
18
+ 'Argentina Standard Time' => 'America/Buenos_Aires',
19
+ 'Atlantic Standard Time' => 'America/Halifax',
20
+ 'Azerbaijan Standard Time' => 'Asia/Baku',
21
+ 'Azores Standard Time' => 'Atlantic/Azores',
22
+ 'Bahia Standard Time' => 'America/Bahia',
23
+ 'Bangladesh Standard Time' => 'Asia/Dhaka',
24
+ 'Belarus Standard Time' => 'Europe/Minsk',
25
+ 'Canada Central Standard Time' => 'America/Regina',
26
+ 'Cape Verde Standard Time' => 'Atlantic/Cape_Verde',
27
+ 'Caucasus Standard Time' => 'Asia/Yerevan',
28
+ 'Cen. Australia Standard Time' => 'Australia/Adelaide',
29
+ 'Central America Standard Time' => 'America/Guatemala',
30
+ 'Central Asia Standard Time' => 'Asia/Almaty',
31
+ 'Central Brazilian Standard Time' => 'America/Cuiaba',
32
+ 'Central Europe Standard Time' => 'Europe/Budapest',
33
+ 'Central European Standard Time' => 'Europe/Warsaw',
34
+ 'Central Pacific Standard Time' => 'Pacific/Guadalcanal',
35
+ 'Central Standard Time' => 'America/Chicago',
36
+ 'Central Standard Time (Mexico)' => 'America/Mexico_City',
37
+ 'China Standard Time' => 'Asia/Shanghai',
38
+ 'Dateline Standard Time' => 'Etc/GMT+12',
39
+ 'E. Africa Standard Time' => 'Africa/Nairobi',
40
+ 'E. Australia Standard Time' => 'Australia/Brisbane',
41
+ 'E. South America Standard Time' => 'America/Sao_Paulo',
42
+ 'Eastern Standard Time' => 'America/New_York',
43
+ 'Eastern Standard Time (Mexico)' => 'America/Cancun',
44
+ 'Egypt Standard Time' => 'Africa/Cairo',
45
+ 'Ekaterinburg Standard Time' => 'Asia/Yekaterinburg',
46
+ 'FLE Standard Time' => 'Europe/Kiev',
47
+ 'Fiji Standard Time' => 'Pacific/Fiji',
48
+ 'GMT Standard Time' => 'Europe/London',
49
+ 'GTB Standard Time' => 'Europe/Bucharest',
50
+ 'Georgian Standard Time' => 'Asia/Tbilisi',
51
+ 'Greenland Standard Time' => 'America/Godthab',
52
+ 'Greenwich Standard Time' => 'Atlantic/Reykjavik',
53
+ 'Hawaiian Standard Time' => 'Pacific/Honolulu',
54
+ 'India Standard Time' => 'Asia/Calcutta',
55
+ 'Iran Standard Time' => 'Asia/Tehran',
56
+ 'Israel Standard Time' => 'Asia/Jerusalem',
57
+ 'Jordan Standard Time' => 'Asia/Amman',
58
+ 'Kaliningrad Standard Time' => 'Europe/Kaliningrad',
59
+ 'Korea Standard Time' => 'Asia/Seoul',
60
+ 'Libya Standard Time' => 'Africa/Tripoli',
61
+ 'Line Islands Standard Time' => 'Pacific/Kiritimati',
62
+ 'Magadan Standard Time' => 'Asia/Magadan',
63
+ 'Mauritius Standard Time' => 'Indian/Mauritius',
64
+ 'Middle East Standard Time' => 'Asia/Beirut',
65
+ 'Montevideo Standard Time' => 'America/Montevideo',
66
+ 'Morocco Standard Time' => 'Africa/Casablanca',
67
+ 'Mountain Standard Time' => 'America/Denver',
68
+ 'Mountain Standard Time (Mexico)' => 'America/Chihuahua',
69
+ 'Myanmar Standard Time' => 'Asia/Rangoon',
70
+ 'N. Central Asia Standard Time' => 'Asia/Novosibirsk',
71
+ 'Namibia Standard Time' => 'Africa/Windhoek',
72
+ 'Nepal Standard Time' => 'Asia/Katmandu',
73
+ 'New Zealand Standard Time' => 'Pacific/Auckland',
74
+ 'Newfoundland Standard Time' => 'America/St_Johns',
75
+ 'North Asia East Standard Time' => 'Asia/Irkutsk',
76
+ 'North Asia Standard Time' => 'Asia/Krasnoyarsk',
77
+ 'Pacific SA Standard Time' => 'America/Santiago',
78
+ 'Pacific Standard Time' => 'America/Los_Angeles',
79
+ 'Pacific Standard Time (Mexico)' => 'America/Santa_Isabel',
80
+ 'Pakistan Standard Time' => 'Asia/Karachi',
81
+ 'Paraguay Standard Time' => 'America/Asuncion',
82
+ 'Romance Standard Time' => 'Europe/Paris',
83
+ 'Russia Time Zone 10' => 'Asia/Srednekolymsk',
84
+ 'Russia Time Zone 11' => 'Asia/Kamchatka',
85
+ 'Russia Time Zone 3' => 'Europe/Samara',
86
+ 'Russian Standard Time' => 'Europe/Moscow',
87
+ 'SA Eastern Standard Time' => 'America/Cayenne',
88
+ 'SA Pacific Standard Time' => 'America/Bogota',
89
+ 'SA Western Standard Time' => 'America/La_Paz',
90
+ 'SE Asia Standard Time' => 'Asia/Bangkok',
91
+ 'Samoa Standard Time' => 'Pacific/Apia',
92
+ 'Singapore Standard Time' => 'Asia/Singapore',
93
+ 'South Africa Standard Time' => 'Africa/Johannesburg',
94
+ 'Sri Lanka Standard Time' => 'Asia/Colombo',
95
+ 'Syria Standard Time' => 'Asia/Damascus',
96
+ 'Taipei Standard Time' => 'Asia/Taipei',
97
+ 'Tasmania Standard Time' => 'Australia/Hobart',
98
+ 'Tokyo Standard Time' => 'Asia/Tokyo',
99
+ 'Tonga Standard Time' => 'Pacific/Tongatapu',
100
+ 'Turkey Standard Time' => 'Europe/Istanbul',
101
+ 'US Eastern Standard Time' => 'America/Indianapolis',
102
+ 'US Mountain Standard Time' => 'America/Phoenix',
103
+ 'UTC' => 'Etc/GMT',
104
+ 'UTC+12' => 'Etc/GMT-12',
105
+ 'UTC-02' => 'Etc/GMT+2',
106
+ 'UTC-11' => 'Etc/GMT+11',
107
+ 'Ulaanbaatar Standard Time' => 'Asia/Ulaanbaatar',
108
+ 'Venezuela Standard Time' => 'America/Caracas',
109
+ 'Vladivostok Standard Time' => 'Asia/Vladivostok',
110
+ 'W. Australia Standard Time' => 'Australia/Perth',
111
+ 'W. Central Africa Standard Time' => 'Africa/Lagos',
112
+ 'W. Europe Standard Time' => 'Europe/Berlin',
113
+ 'West Asia Standard Time' => 'Asia/Tashkent',
114
+ 'West Pacific Standard Time' => 'Pacific/Port_Moresby',
115
+ 'Yakutsk Standard Time' => 'Asia/Yakutsk'
116
+ }
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,10 @@
1
+ module Tilia
2
+ module VObject
3
+ module TimeZoneData
4
+ require 'tilia/v_object/time_zone_data/exchange_zones'
5
+ require 'tilia/v_object/time_zone_data/lotus_zones'
6
+ require 'tilia/v_object/time_zone_data/php_zones'
7
+ require 'tilia/v_object/time_zone_data/windows_zones'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,213 @@
1
+ module Tilia
2
+ module VObject
3
+ # Time zone name translation.
4
+ #
5
+ # This file translates well-known time zone names into "Olson database" time zone names.
6
+ class TimeZoneUtil
7
+ @map = nil
8
+
9
+ # List of microsoft exchange timezone ids.
10
+ #
11
+ # Source: http://msdn.microsoft.com/en-us/library/aa563018(loband).aspx
12
+ @microsoft_exchange_map = {
13
+ 0 => 'UTC',
14
+ 31 => 'Africa/Casablanca',
15
+
16
+ # Insanely, id #2 is used for both Europe/Lisbon, and Europe/Sarajevo.
17
+ # I'm not even kidding.. We handle this special case in the
18
+ # getTimeZone method.
19
+ 2 => 'Europe/Lisbon',
20
+ 1 => 'Europe/London',
21
+ 4 => 'Europe/Berlin',
22
+ 6 => 'Europe/Prague',
23
+ 3 => 'Europe/Paris',
24
+ 69 => 'Africa/Luanda', # This was a best guess
25
+ 7 => 'Europe/Athens',
26
+ 5 => 'Europe/Bucharest',
27
+ 49 => 'Africa/Cairo',
28
+ 50 => 'Africa/Harare',
29
+ 59 => 'Europe/Helsinki',
30
+ 27 => 'Asia/Jerusalem',
31
+ 26 => 'Asia/Baghdad',
32
+ 74 => 'Asia/Kuwait',
33
+ 51 => 'Europe/Moscow',
34
+ 56 => 'Africa/Nairobi',
35
+ 25 => 'Asia/Tehran',
36
+ 24 => 'Asia/Muscat', # Best guess
37
+ 54 => 'Asia/Baku',
38
+ 48 => 'Asia/Kabul',
39
+ 58 => 'Asia/Yekaterinburg',
40
+ 47 => 'Asia/Karachi',
41
+ 23 => 'Asia/Calcutta',
42
+ 62 => 'Asia/Kathmandu',
43
+ 46 => 'Asia/Almaty',
44
+ 71 => 'Asia/Dhaka',
45
+ 66 => 'Asia/Colombo',
46
+ 61 => 'Asia/Rangoon',
47
+ 22 => 'Asia/Bangkok',
48
+ 64 => 'Asia/Krasnoyarsk',
49
+ 45 => 'Asia/Shanghai',
50
+ 63 => 'Asia/Irkutsk',
51
+ 21 => 'Asia/Singapore',
52
+ 73 => 'Australia/Perth',
53
+ 75 => 'Asia/Taipei',
54
+ 20 => 'Asia/Tokyo',
55
+ 72 => 'Asia/Seoul',
56
+ 70 => 'Asia/Yakutsk',
57
+ 19 => 'Australia/Adelaide',
58
+ 44 => 'Australia/Darwin',
59
+ 18 => 'Australia/Brisbane',
60
+ 76 => 'Australia/Sydney',
61
+ 43 => 'Pacific/Guam',
62
+ 42 => 'Australia/Hobart',
63
+ 68 => 'Asia/Vladivostok',
64
+ 41 => 'Asia/Magadan',
65
+ 17 => 'Pacific/Auckland',
66
+ 40 => 'Pacific/Fiji',
67
+ 67 => 'Pacific/Tongatapu',
68
+ 29 => 'Atlantic/Azores',
69
+ 53 => 'Atlantic/Cape_Verde',
70
+ 30 => 'America/Noronha',
71
+ 8 => 'America/Sao_Paulo', # Best guess
72
+ 32 => 'America/Argentina/Buenos_Aires',
73
+ 60 => 'America/Godthab',
74
+ 28 => 'America/St_Johns',
75
+ 9 => 'America/Halifax',
76
+ 33 => 'America/Caracas',
77
+ 65 => 'America/Santiago',
78
+ 35 => 'America/Bogota',
79
+ 10 => 'America/New_York',
80
+ 34 => 'America/Indiana/Indianapolis',
81
+ 55 => 'America/Guatemala',
82
+ 11 => 'America/Chicago',
83
+ 37 => 'America/Mexico_City',
84
+ 36 => 'America/Edmonton',
85
+ 38 => 'America/Phoenix',
86
+ 12 => 'America/Denver', # Best guess
87
+ 13 => 'America/Los_Angeles', # Best guess
88
+ 14 => 'America/Anchorage',
89
+ 15 => 'Pacific/Honolulu',
90
+ 16 => 'Pacific/Midway',
91
+ 39 => 'Pacific/Kwajalein'
92
+ }
93
+
94
+ # This method will try to find out the correct timezone for an iCalendar
95
+ # date-time value.
96
+ #
97
+ # You must pass the contents of the TZID parameter, as well as the full
98
+ # calendar.
99
+ #
100
+ # If the lookup fails, this method will return the default PHP timezone
101
+ # (as configured using date_default_timezone_set, or the date.timezone ini
102
+ # setting).
103
+ #
104
+ # Alternatively, if fail_if_uncertain is set to true, it will throw an
105
+ # exception if we cannot accurately determine the timezone.
106
+ #
107
+ # @param string tzid
108
+ # @param Sabre\VObject\Component vcalendar
109
+ #
110
+ # @return DateTimeZone
111
+ def self.time_zone(tzid, vcalendar = nil, fail_if_uncertain = false)
112
+ # First we will just see if the tzid is a support timezone identifier.
113
+ #
114
+ # The only exception is if the timezone starts with (. This is to
115
+ # handle cases where certain microsoft products generate timezone
116
+ # identifiers that for instance look like:
117
+ #
118
+ # (GMT+01.00) Sarajevo/Warsaw/Zagreb
119
+ #
120
+ # Since PHP 5.5.10, the first bit will be used as the timezone and
121
+ # this method will return just GMT+01:00. This is wrong, because it
122
+ # doesn't take DST into account.
123
+
124
+ unless tzid[0] == '('
125
+
126
+ # PHP has a bug that logs PHP warnings even it shouldn't:
127
+ # https://bugs.php.net/bug.php?id=67881
128
+ #
129
+ # That's why we're checking if we'll be able to successfull instantiate
130
+ # \Date_time_zone before doing so. Otherwise we could simply instantiate
131
+ # and catch the exception.
132
+ return ActiveSupport::TimeZone.new(tzid) if ActiveSupport::TimeZone.new(tzid)
133
+ end
134
+
135
+ load_tz_maps
136
+
137
+ # Next, we check if the tzid is somewhere in our tzid map.
138
+
139
+ return ActiveSupport::TimeZone.new(@map[tzid]) if @map.key?(tzid)
140
+
141
+ # Maybe the author was hyper-lazy and just included an offset. We
142
+ # support it, but we aren't happy about it.
143
+ matches = /^GMT(\+|-)([0-9]{4})$/.match(tzid)
144
+ if matches
145
+
146
+ # Note that the path in the source will never be taken from PHP 5.5.10
147
+ # onwards. PHP 5.5.10 supports the "GMT+0100" style of format, so it
148
+ # already gets returned early in this function. Once we drop support
149
+ # for versions under PHP 5.5.10, this bit can be taken out of the
150
+ # source.
151
+ # @codeCoverageIgnoreStart
152
+ return ActiveSupport::TimeZone.new("Etc/GMT#{matches[1]}#{matches[2][0..1].gsub(/^0+/, '')}")
153
+ # @codeCoverageIgnoreEnd
154
+ end
155
+
156
+ if vcalendar
157
+ # If that didn't work, we will scan VTIMEZONE objects
158
+ vcalendar.select('VTIMEZONE').each do |vtimezone|
159
+ next unless vtimezone['TZID'].to_s == tzid
160
+ if vtimezone.key?('X-LIC-LOCATION')
161
+ lic = vtimezone['X-LIC-LOCATION'].to_s
162
+
163
+ # Libical generators may specify strings like
164
+ # "SystemV/EST5EDT". For those we must remove the
165
+ # SystemV part.
166
+ lic = lic[8..-1] if lic[0...8] == 'SystemV/'
167
+
168
+ return time_zone(lic, nil, fail_if_uncertain)
169
+ end
170
+
171
+ # Microsoft may add a magic number, which we also have an
172
+ # answer for.
173
+ next unless vtimezone.key?('X-MICROSOFT-CDO-TZID')
174
+ cdo_id = vtimezone['X-MICROSOFT-CDO-TZID'].value.to_i
175
+
176
+ # 2 can mean both Europe/Lisbon and Europe/Sarajevo.
177
+ if cdo_id == 2 && vtimezone['TZID'].to_s.index('Sarajevo')
178
+ return ActiveSupport::TimeZone.new('Europe/Sarajevo')
179
+ end
180
+
181
+ if @microsoft_exchange_map.key?(cdo_id)
182
+ return ActiveSupport::TimeZone.new(@microsoft_exchange_map[cdo_id])
183
+ end
184
+ end
185
+ end
186
+
187
+ if fail_if_uncertain
188
+ fail ArgumentError, "We were unable to determine the correct PHP timezone for tzid: #{tzid}"
189
+ end
190
+
191
+ # If we got all the way here, we default to UTC.
192
+ Time.zone
193
+ end
194
+
195
+ # This method will load in all the tz mapping information, if it's not yet
196
+ # done.
197
+ def self.load_tz_maps
198
+ return @map if @map
199
+
200
+ @map = TimeZoneData::PhpZones.list
201
+ @map.merge! TimeZoneData::ExchangeZones.list
202
+ @map.merge! TimeZoneData::LotusZones.list
203
+ @map.merge! TimeZoneData::WindowsZones.list
204
+ @map
205
+ end
206
+
207
+ class << self
208
+ attr_accessor :map
209
+ attr_accessor :microsoft_exchange_map
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,51 @@
1
+ module Tilia
2
+ module VObject
3
+ # UUID Utility.
4
+ #
5
+ # This class has static methods to generate and validate UUID's.
6
+ # UUIDs are used a decent amount within various *DAV standards, so it made
7
+ # sense to include it.
8
+ class UuidUtil
9
+ # Returns a pseudo-random v4 UUID.
10
+ #
11
+ # This function is based on a comment by Andrew Moore on php.net
12
+ #
13
+ # @see http://www.php.net/manual/en/function.uniqid.php#94959
14
+ #
15
+ # @return string
16
+ def self.uuid
17
+ format(
18
+ '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
19
+ # 32 bits for "time_low"
20
+ rand(0..0xffff),
21
+ rand(0..0xffff),
22
+
23
+ # 16 bits for "time_mid"
24
+ rand(0..0xffff),
25
+
26
+ # 16 bits for "time_hi_and_version",
27
+ # four most significant bits holds version number 4
28
+ rand(0..0x0fff) | 0x4000,
29
+
30
+ # 16 bits, 8 bits for "clk_seq_hi_res",
31
+ # 8 bits for "clk_seq_low",
32
+ # two most significant bits holds zero and one for variant DCE1.1
33
+ rand(0..0x3fff) | 0x8000,
34
+
35
+ # 48 bits for "node"
36
+ rand(0..0xffff),
37
+ rand(0..0xffff),
38
+ rand(0..0xffff)
39
+ )
40
+ end
41
+
42
+ # Checks if a string is a valid UUID.
43
+ #
44
+ # @param string $uuid
45
+ # @return bool
46
+ def self.validate_uuid(uuid)
47
+ uuid =~ /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
48
+ end
49
+ end
50
+ end
51
+ end