icalendar 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aee422660be821b5fa0060bd0344282e673db97f
4
- data.tar.gz: 95df849c43f1868e9cf7a9f644fffc9384afce97
3
+ metadata.gz: 370af2e2d4636f906480c2a2d9faa6f71d00c572
4
+ data.tar.gz: a9bf492ff26c0d75dbe138f2a08841910882105d
5
5
  SHA512:
6
- metadata.gz: a3108d6a9d6474c9210e083653fbfd1fc9e9979f8c5093ea1bab7f03c6263c687c261c5cab8d8fecd5ff6b80d539d877f33c7b15ac782e9b75cb4c5e9c255f1b
7
- data.tar.gz: 9f6d142d8f346c422ed99d56b2f386419647f1a502f7c77787a0c730dcf4287a0fe9463abc174957808ba89413549b3082a17672f22da3e4d00adc2ff169bde0
6
+ metadata.gz: 4f73cd84ce78cb0c7bc9cb5c65a08de0c09d1cffe087ad5b9b17ef92e6ad32e0f470b23ecd53255d99198e7fd980a9eac28b317574adca005bada4294001201b
7
+ data.tar.gz: a3fae6aef26214cda39e5974cc9c38556a4626a2aff24af82a5310319a76dd79cc7f18a3cc46e093b37c809664f9ec99b694e237b06d2f3d1a88b216d58f4b93
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 1.4.0 2013-05-21
2
+ * Implement ACKNOWLEDGED property for VALARM - tsuzuki08
3
+ * Output VERSION property as first line after BEGIN:VCALENDAR
4
+ * Check for unbounded timezone transitions in tzinfo
5
+
1
6
  === 1.3.0 2013-03-31
2
7
  * Lenient parsing mode ignores unknown properties - David Grandinetti
3
8
  * VTIMEZONE positive offsets properly have "+" prepended (Fixed issue
@@ -11,7 +11,7 @@ require 'logger'
11
11
 
12
12
  module Icalendar #:nodoc:
13
13
 
14
- VERSION = '1.3.0'
14
+ VERSION = '1.4.0'
15
15
 
16
16
  # A simple error class to differentiate iCalendar library exceptions
17
17
  # from ruby language exceptions or others.
@@ -25,6 +25,20 @@ module Icalendar
25
25
  self.version = "2.0" # Version of the specification
26
26
  end
27
27
 
28
+ def print_component
29
+ "BEGIN:#{@name.upcase}\r\n" +
30
+ "VERSION:#{version}\r\n" +
31
+
32
+ # Then the properties
33
+ print_properties(@properties.select { |k,v| k != 'version' }) +
34
+
35
+ # sub components
36
+ yield +
37
+
38
+ # End of this component
39
+ "END:#{@name.upcase}\r\n"
40
+ end
41
+
28
42
  def event(&block)
29
43
  e = Event.new
30
44
  # Note: I'm not sure this is the best way to pass this down, but it works
@@ -125,10 +125,10 @@ module Icalendar
125
125
  "END:#{@name.upcase}\r\n"
126
126
  end
127
127
 
128
- def print_properties
128
+ def print_properties(properties = @properties)
129
129
  s = ""
130
130
 
131
- @properties.sort.each do |key,val|
131
+ properties.sort.each do |key,val|
132
132
  # Take out underscore for property names that conflicted
133
133
  # with built-in words.
134
134
  if key =~ /ip_.*/
@@ -29,6 +29,7 @@ module Icalendar
29
29
  ical_property :last_modified
30
30
  ical_property :timestamp
31
31
  ical_property :sequence
32
+ ical_property :acknowledged
32
33
 
33
34
  # Multi properties
34
35
  ical_multiline_property :attendee, :attendee, :attendees
@@ -291,6 +291,7 @@ module Icalendar
291
291
  @parsers["CREATED"] = m
292
292
  @parsers["DTSTAMP"] = m
293
293
  @parsers["LAST-MODIFIED"] = m
294
+ @parsers["ACKNOWLEDGED"] = m
294
295
 
295
296
  # URI's
296
297
  m = self.method(:parse_uri)
@@ -47,75 +47,94 @@ module TZInfo
47
47
  period = period_for_local(date)
48
48
  timezone = Icalendar::Timezone.new
49
49
  timezone.timezone_id = identifier
50
- timezone.add(period.daylight)
51
- timezone.add(period.standard)
52
- return timezone
50
+ if period.start_transition.nil?
51
+ timezone.add period.single
52
+ elsif period.end_transition.nil?
53
+ timezone.add period.dst? ? period.daylight : period.standard
54
+ else
55
+ timezone.add period.daylight
56
+ timezone.add period.standard
57
+ end
58
+ timezone
53
59
  end
54
60
  end
55
61
 
56
62
  class TimezoneTransitionInfo
57
63
  def offset_from
58
- a = previous_offset.utc_total_offset
59
- sprintf("%+-2.2d%2.2d", (a / 3600).to_i, ((a / 60) % 60).to_i)
64
+ previous_offset.ical_offset
60
65
  end
61
66
 
62
67
  def offset_to
63
- a = offset.utc_total_offset
64
- sprintf("%+-2.2d%2.2d", (a / 3600).to_i, ((a / 60) % 60).to_i)
68
+ offset.ical_offset
65
69
  end
66
70
 
67
71
  def rrule
68
72
  start = local_start.to_datetime
69
73
  # this is somewhat of a hack, but seems to work ok
70
74
  [sprintf(
71
- "FREQ=YEARLY;BYMONTH=%d;BYDAY=%d%s",
75
+ 'FREQ=YEARLY;BYMONTH=%d;BYDAY=%d%s',
72
76
  start.month,
73
77
  ((start.day - 1)/ 7).to_i + 1,
74
- start.strftime("%a").upcase[0,2]
78
+ start.strftime('%a').upcase[0,2]
75
79
  )]
76
80
  end
77
81
 
78
82
  def dtstart
79
- local_start.to_datetime.strftime("%Y%m%dT%H%M%S")
83
+ local_start.to_datetime.strftime '%Y%m%dT%H%M%S'
80
84
  end
85
+ end
81
86
 
87
+ class TimezoneOffsetInfo
88
+ def ical_offset
89
+ o = utc_total_offset
90
+ sprintf '%+-2.2d%2.2d', (o / 3600).to_i, ((o / 60) % 60).to_i
91
+ end
82
92
  end
83
93
 
84
94
  class TimezonePeriod
85
95
  def daylight
86
- day = Icalendar::Daylight.new
87
- if dst?
88
- day.timezone_name = abbreviation.to_s
89
- day.timezone_offset_from = start_transition.offset_from
90
- day.timezone_offset_to = start_transition.offset_to
91
- day.dtstart = start_transition.dtstart
92
- day.recurrence_rules = start_transition.rrule
93
- else
94
- day.timezone_name = abbreviation.to_s.sub("ST","DT")
95
- day.timezone_offset_from = end_transition.offset_from
96
- day.timezone_offset_to = end_transition.offset_to
97
- day.dtstart = end_transition.dtstart
98
- day.recurrence_rules = end_transition.rrule
96
+ Icalendar::Daylight.new.tap do |day|
97
+ if dst?
98
+ day.timezone_name = abbreviation.to_s
99
+ day.timezone_offset_from = start_transition.offset_from
100
+ day.timezone_offset_to = start_transition.offset_to
101
+ day.dtstart = start_transition.dtstart
102
+ day.recurrence_rules = start_transition.rrule unless end_transition.nil?
103
+ else
104
+ day.timezone_name = abbreviation.to_s.sub("ST","DT")
105
+ day.timezone_offset_from = end_transition.offset_from
106
+ day.timezone_offset_to = end_transition.offset_to
107
+ day.dtstart = end_transition.dtstart
108
+ day.recurrence_rules = end_transition.rrule
109
+ end
99
110
  end
100
- return day
101
111
  end
102
112
 
103
113
  def standard
104
- std = Icalendar::Standard.new
105
- if dst?
106
- std.timezone_name = abbreviation.to_s.sub("DT","ST")
107
- std.timezone_offset_from = end_transition.offset_from
108
- std.timezone_offset_to = end_transition.offset_to
109
- std.dtstart = end_transition.dtstart
110
- std.recurrence_rules = end_transition.rrule
111
- else
114
+ Icalendar::Standard.new.tap do |std|
115
+ if dst?
116
+ std.timezone_name = abbreviation.to_s.sub('DT', 'ST')
117
+ std.timezone_offset_from = end_transition.offset_from
118
+ std.timezone_offset_to = end_transition.offset_to
119
+ std.dtstart = end_transition.dtstart
120
+ std.recurrence_rules = end_transition.rrule
121
+ else
122
+ std.timezone_name = abbreviation.to_s
123
+ std.timezone_offset_from = start_transition.offset_from
124
+ std.timezone_offset_to = start_transition.offset_to
125
+ std.dtstart = start_transition.dtstart
126
+ std.recurrence_rules = start_transition.rrule unless end_transition.nil?
127
+ end
128
+ end
129
+ end
130
+
131
+ def single
132
+ Icalendar::Standard.new.tap do |std|
112
133
  std.timezone_name = abbreviation.to_s
113
- std.timezone_offset_from = start_transition.offset_from
114
- std.timezone_offset_to = start_transition.offset_to
115
- std.dtstart = start_transition.dtstart
116
- std.recurrence_rules = start_transition.rrule
134
+ std.timezone_offset_from = offset.ical_offset
135
+ std.timezone_offset_to = offset.ical_offset
136
+ std.dtstart = DateTime.new(1970).strftime '%Y%m%dT%H%M%S'
117
137
  end
118
- return std
119
138
  end
120
139
  end
121
140
  end
@@ -1,7 +1,7 @@
1
1
  BEGIN:VCALENDAR
2
+ VERSION:2.0
2
3
  CALSCALE:GREGORIAN
3
4
  PRODID:iCalendar-Ruby
4
- VERSION:2.0
5
5
  X-WR-CALNAME:Test Long Description
6
6
  BEGIN:VEVENT
7
7
  DESCRIPTION:FULL DETAILS:\nhttp://test.com/events/570\n\nCary Brothers walk
@@ -10,9 +10,9 @@ class TestConversions < Test::Unit::TestCase
10
10
 
11
11
  RESULT = <<EOS
12
12
  BEGIN:VCALENDAR
13
+ VERSION:2.0
13
14
  CALSCALE:GREGORIAN
14
15
  PRODID:iCalendar-Ruby
15
- VERSION:2.0
16
16
  BEGIN:VEVENT
17
17
  CATEGORIES:foo,bar,baz
18
18
  DESCRIPTION:desc
data/test/test_tzinfo.rb CHANGED
@@ -7,8 +7,8 @@ require 'icalendar/tzinfo'
7
7
 
8
8
  class TestTZInfoExt < Test::Unit::TestCase
9
9
  def setup
10
- tz = TZInfo::Timezone.get("Europe/Copenhagen")
11
- @timezone = tz.ical_timezone(DateTime.new(1970))
10
+ tz = TZInfo::Timezone.get 'Europe/Copenhagen'
11
+ @timezone = tz.ical_timezone DateTime.new(1970)
12
12
  end
13
13
 
14
14
  def test_daylight_offset
@@ -24,4 +24,34 @@ class TestTZInfoExt < Test::Unit::TestCase
24
24
  assert_equal "+0200", tz_offset_from
25
25
  assert_equal "+0100", tz_offset_to
26
26
  end
27
+
28
+ def test_no_end_transition
29
+ tz = TZInfo::Timezone.get('America/Cayman').ical_timezone DateTime.now
30
+ assert_equal <<-EXPECTED.gsub("\n", "\r\n"), tz.to_ical
31
+ BEGIN:VTIMEZONE
32
+ TZID:America/Cayman
33
+ BEGIN:STANDARD
34
+ DTSTART:19120201T000712
35
+ TZNAME:EST
36
+ TZOFFSETFROM:-0652
37
+ TZOFFSETTO:-0500
38
+ END:STANDARD
39
+ END:VTIMEZONE
40
+ EXPECTED
41
+ end
42
+
43
+ def test_no_transition
44
+ tz = TZInfo::Timezone.get('UTC').ical_timezone DateTime.now
45
+ assert_equal <<-EXPECTED.gsub("\n", "\r\n"), tz.to_ical
46
+ BEGIN:VTIMEZONE
47
+ TZID:UTC
48
+ BEGIN:STANDARD
49
+ DTSTART:19700101T000000
50
+ TZNAME:UTC
51
+ TZOFFSETFROM:+0000
52
+ TZOFFSETTO:+0000
53
+ END:STANDARD
54
+ END:VTIMEZONE
55
+ EXPECTED
56
+ end
27
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icalendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Ahearn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-01 00:00:00.000000000 Z
11
+ date: 2013-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyforge