sdague-icalendar 1.0.2.1 → 1.0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/Rakefile +5 -3
  2. data/lib/icalendar/tzinfo.rb +118 -0
  3. data/lib/icalendar.rb +2 -0
  4. metadata +14 -5
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/rdoctask'
5
5
  require 'rake/clean'
6
6
  require 'rake/contrib/sshpublisher'
7
7
 
8
- PKG_VERSION = "1.0.2"
8
+ PKG_VERSION = "1.0.2.2"
9
9
 
10
10
  $VERBOSE = nil
11
11
  TEST_CHANGES_SINCE = Time.now - 600 # Recent tests = changed in last 10 minutes
@@ -74,8 +74,10 @@ spec = Gem::Specification.new do |s|
74
74
  s.extra_rdoc_files = ["README", "COPYING", "GPL"]
75
75
  s.rdoc_options.concat ['--main', 'README']
76
76
 
77
- s.author = "Jeff Rose"
78
- s.email = "rosejn@gmail.com"
77
+ s.add_dependency("tzinfo", ["> 0.0.0"])
78
+
79
+ s.author = "Sean Dague"
80
+ s.email = "sean@dague.net"
79
81
  end
80
82
 
81
83
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -0,0 +1,118 @@
1
+ =begin
2
+ Copyright (C) 2008 Sean Dague
3
+
4
+ This library is free software; you can redistribute it and/or modify it
5
+ under the same terms as the ruby language itself, see the file COPYING for
6
+ details.
7
+ =end
8
+
9
+ # The following adds a bunch of mixins to the tzinfo class, with the
10
+ # intent on making it very easy to load in tzinfo data for generating
11
+ # ical events. With this you can do the following:
12
+ #
13
+ # estart = DateTime.new(2008, 12, 29, 8, 0, 0)
14
+ # eend = DateTime.new(2008, 12, 29, 11, 0, 0)
15
+ # tstring = "America/Chicago"
16
+ #
17
+ # tz = TZInfo::Timezone.get(tstring)
18
+ # cal = Calendar.new
19
+ # # the mixins now generate all the timezone info for the date in question
20
+ # timezone = tz.ical_timezone(estart)
21
+ # cal.add(timezone)
22
+ #
23
+ # cal.event do
24
+ # dtstart estart
25
+ # dtend eend
26
+ # summary "Meeting with the man."
27
+ # description "Have a long lunch meeting and decide nothing..."
28
+ # klass "PRIVATE"
29
+ # end
30
+ #
31
+ # puts cal.to_ical
32
+ #
33
+ # The recurance rule calculations are hacky, and only start at the
34
+ # beginning of the current dst transition. I doubt this works for non
35
+ # dst areas yet. However, for a standard dst flipping zone, this
36
+ # seems to work fine (tested in Mozilla Thunderbird + Lightning).
37
+ # Future goal would be making this better.
38
+
39
+ require "tzinfo"
40
+
41
+ module TZInfo
42
+ class Timezone
43
+ def ical_timezone(date)
44
+ period = period_for_local(date)
45
+ timezone = Icalendar::Timezone.new
46
+ timezone.timezone_id = identifier
47
+ timezone.add(period.daylight)
48
+ timezone.add(period.standard)
49
+ return timezone
50
+ end
51
+ end
52
+
53
+ class TimezoneTransitionInfo
54
+ def offset_from
55
+ a = previous_offset.utc_total_offset
56
+ sprintf("%2.2d%2.2d", (a / 3600).to_i, ((a / 60) % 60).to_i)
57
+ end
58
+
59
+ def offset_to
60
+ a = offset.utc_total_offset
61
+ sprintf("%2.2d%2.2d", (a / 3600).to_i, ((a / 60) % 60).to_i)
62
+ end
63
+
64
+ def rrule
65
+ start = local_start.to_datetime
66
+ # this is somewhat of a hack, but seems to work ok
67
+ [sprintf(
68
+ "FREQ=YEARLY;BYMONTH=%d;BYDAY=%d%s",
69
+ start.month,
70
+ ((start.day - 1)/ 7).to_i + 1,
71
+ start.strftime("%a").upcase[0,2]
72
+ )]
73
+ end
74
+
75
+ def dtstart
76
+ local_start.to_datetime.strftime("%Y%m%dT%H%M%S")
77
+ end
78
+
79
+ end
80
+
81
+ class TimezonePeriod
82
+ def daylight
83
+ day = Icalendar::Daylight.new
84
+ if dst?
85
+ day.timezone_name = abbreviation.to_s
86
+ day.timezone_offset_from = start_transition.offset_from
87
+ day.timezone_offset_to = start_transition.offset_to
88
+ day.dtstart = start_transition.dtstart
89
+ day.recurrence_rules = start_transition.rrule
90
+ else
91
+ day.timezone_name = abbreviation.to_s.sub("ST","DT")
92
+ day.timezone_offset_from = end_transition.offset_from
93
+ day.timezone_offset_to = end_transition.offset_to
94
+ day.dtstart = end_transition.dtstart
95
+ day.recurrence_rules = end_transition.rrule
96
+ end
97
+ return day
98
+ end
99
+
100
+ def standard
101
+ std = Icalendar::Standard.new
102
+ if dst?
103
+ std.timezone_name = abbreviation.to_s.sub("DT","ST")
104
+ std.timezone_offset_from = end_transition.offset_from
105
+ std.timezone_offset_to = end_transition.offset_to
106
+ std.dtstart = end_transition.dtstart
107
+ std.recurrence_rules = end_transition.rrule
108
+ else
109
+ std.timezone_name = abbreviation.to_s
110
+ std.timezone_offset_from = start_transition.offset_from
111
+ std.timezone_offset_to = start_transition.offset_to
112
+ std.dtstart = start_transition.dtstart
113
+ std.recurrence_rules = start_transition.rrule
114
+ end
115
+ return std
116
+ end
117
+ end
118
+ end
data/lib/icalendar.rb CHANGED
@@ -34,3 +34,5 @@ require 'icalendar/component/alarm'
34
34
  # Calendar parser
35
35
  require 'icalendar/parser'
36
36
 
37
+ # TZINFO support
38
+ require 'icalendar/tzinfo'
metadata CHANGED
@@ -1,20 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdague-icalendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2.1
4
+ version: 1.0.2.2
5
5
  platform: ruby
6
6
  authors:
7
- - Jeff Rose
7
+ - Sean Dague
8
8
  autorequire: icalendar
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
12
  date: 2008-12-22 00:00:00 -08:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: tzinfo
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.0
23
+ version:
16
24
  description: Implements the iCalendar specification (RFC-2445) in Ruby. This allows for the generation and parsing of .ics files, which are used by a variety of calendaring applications.
17
- email: rosejn@gmail.com
25
+ email: sean@dague.net
18
26
  executables: []
19
27
 
20
28
  extensions: []
@@ -56,6 +64,7 @@ files:
56
64
  - lib/icalendar/component/timezone.rb
57
65
  - lib/icalendar/component/freebusy.rb
58
66
  - lib/icalendar/conversions.rb
67
+ - lib/icalendar/tzinfo.rb
59
68
  - lib/icalendar/helpers.rb
60
69
  - lib/meta.rb
61
70
  - lib/icalendar.rb