Skip to content

Commit df36be4

Browse files
author
Jared Turner
committed
Use different tzinfo method so valid for v1 and v2
1 parent cb89247 commit df36be4

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PATH
22
remote: .
33
specs:
44
add_to_calendar (0.2.1)
5-
tzinfo (>= 1.1)
5+
tzinfo (>= 1.1, < 3)
66
tzinfo-data (~> 1.2020)
77

88
GEM

add_to_calendar.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
2828

2929
spec.required_ruby_version = '>= 2.0'
3030

31-
spec.add_dependency "tzinfo", ">= 1.1"
31+
spec.add_dependency "tzinfo", ">= 1.1", "< 3"
3232
spec.add_dependency "tzinfo-data", "~> 1.2020"
3333

3434
spec.add_development_dependency "bundler", "~> 2.0"

lib/add_to_calendar.rb

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def ical_url
118118
params[:LOCATION] = url_encode(location) if location
119119
params[:UID] = "-#{url_encode(url)}" if url
120120
params[:UID] = "-#{utc_datetime(start_datetime)}-#{url_encode(title)}" unless params[:UID] # set uid based on starttime and title only if url is unavailable
121-
121+
122122
new_line = "%0A"
123123
params.each do |key, value|
124124
calendar_url << "#{new_line}#{key}=#{value}"
@@ -194,27 +194,31 @@ def microsoft(service)
194194
end
195195

196196
def utc_datetime(datetime)
197-
t = timezone.local_time(
198-
datetime.strftime("%Y").to_i,
199-
datetime.strftime("%m").to_i,
200-
datetime.strftime("%d").to_i,
201-
datetime.strftime("%H").to_i,
202-
datetime.strftime("%M").to_i,
203-
datetime.strftime("%S").to_i
204-
).utc
197+
t = timezone.local_to_utc(
198+
Time.new(
199+
datetime.strftime("%Y").to_i,
200+
datetime.strftime("%m").to_i,
201+
datetime.strftime("%d").to_i,
202+
datetime.strftime("%H").to_i,
203+
datetime.strftime("%M").to_i,
204+
datetime.strftime("%S").to_i
205+
)
206+
)
205207

206208
return t.strftime('%Y%m%dT%H%M%SZ')
207209
end
208210

209211
def utc_datetime_microsoft(datetime)
210-
t = timezone.local_time(
211-
datetime.strftime("%Y").to_i,
212-
datetime.strftime("%m").to_i,
213-
datetime.strftime("%d").to_i,
214-
datetime.strftime("%H").to_i,
215-
datetime.strftime("%M").to_i,
216-
datetime.strftime("%S").to_i
217-
).utc
212+
t = timezone.local_to_utc(
213+
Time.new(
214+
datetime.strftime("%Y").to_i,
215+
datetime.strftime("%m").to_i,
216+
datetime.strftime("%d").to_i,
217+
datetime.strftime("%H").to_i,
218+
datetime.strftime("%M").to_i,
219+
datetime.strftime("%S").to_i
220+
)
221+
)
218222

219223
return t.strftime('%Y-%m-%dT%H:%M:%SZ')
220224
end

0 commit comments

Comments
 (0)