Skip to content

Commit 1c616a6

Browse files
committed
fix: timezones in ical
1 parent 237bcbf commit 1c616a6

File tree

4 files changed

+54
-10
lines changed

4 files changed

+54
-10
lines changed

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ gem "jekyll-include-cache", "~> 0.2.1"
1818
gem "execjs", "~> 2.9"
1919

2020
gem "nokogiri", "~> 1.16"
21+
22+
gem "tzinfo", "~> 2.0"
23+
24+
gem "tzinfo-data", "~> 1.2024"

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ GEM
9595
google-protobuf (>= 3.25, < 5.0)
9696
terminal-table (3.0.2)
9797
unicode-display_width (>= 1.1.1, < 3)
98+
tzinfo (2.0.6)
99+
concurrent-ruby (~> 1.0)
100+
tzinfo-data (1.2024.2)
101+
tzinfo (>= 1.0.0)
98102
unicode-display_width (2.5.0)
99103
webrick (1.8.2)
100104

@@ -114,6 +118,8 @@ DEPENDENCIES
114118
jekyll-sitemap
115119
kramdown-parser-gfm
116120
nokogiri (~> 1.16)
121+
tzinfo (~> 2.0)
122+
tzinfo-data (~> 1.2024)
117123
webrick (~> 1.8)
118124

119125
BUNDLED WITH

_layouts/calendar-deadlines.ics

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ DTSTART:19700101T000000Z
1010
TZOFFSETFROM:+0000
1111
TZOFFSETTO:+0000
1212
END:STANDARD
13-
END:VTIMEZONE{% for conf in site.data.conferences %}
13+
END:VTIMEZONE
14+
{% for conf in site.data.conferences %}
1415
{%- if conf.cfp_ext -%}
1516
{%- assign cfp = conf.cfp_ext -%}
1617
{%- assign extended = "(extended)" -%}
@@ -19,34 +20,34 @@ END:VTIMEZONE{% for conf in site.data.conferences %}
1920
{%- assign extended = "" -%}
2021
{%- endif -%}
2122
{%- capture desc -%}<a href="{{conf.link}}">{{ conf.conference }} {{ conf.year }}</a> found on <a href="https://pythondeadlin.es">PythonDeadlin.es</a>.{%- endcapture -%}
22-
{% if conf.workshop_deadline and conf.workshop_deadline != "TBA" %}
23+
{%- if conf.workshop_deadline and conf.workshop_deadline != "TBA" -%}
2324
BEGIN:VEVENT
2425
SUMMARY:{{ conf.conference }} {{ conf.year }} Workshop Deadline
2526
UID:{{ conf.conference | slugify: "latin" }}-{{ conf.year }}[email protected]
2627
DTSTAMP:{{ site.time | date: "%Y%m%dT%H%M%SZ" }}
27-
DTSTART:{{ conf.workshop_deadline | date: "%Y%m%dT%H%M%SZ" }}
28+
DTSTART:{{ conf.workshop_deadline | to_utc: conf.timezone }}
2829
{{ desc | prepend: "DESCRIPTION:" | normalize_whitespace | wrap_lines }}
2930
ORGANIZER;CN=PythonDeadlines:mailto:[email protected]
3031
END:VEVENT
31-
{% endif %}
32-
{% if conf.tutorial_deadline and conf.tutorial_deadline != "TBA" %}
32+
{%- endif -%}
33+
{%- if conf.tutorial_deadline and conf.tutorial_deadline != "TBA" -%}
3334
BEGIN:VEVENT
3435
SUMMARY:{{ conf.conference }} {{ conf.year }} Tutorial Deadline
3536
UID:{{ conf.conference | slugify: "latin" }}-{{ conf.year }}[email protected]
3637
DTSTAMP:{{ site.time | date: "%Y%m%dT%H%M%SZ" }}
37-
DTSTART:{{ conf.tutorial_deadline | date: "%Y%m%dT%H%M%SZ" }}
38+
DTSTART:{{ conf.tutorial_deadline | to_utc: conf.timezone }}
3839
{{ desc | prepend: "DESCRIPTION:" | normalize_whitespace | wrap_lines }}
3940
ORGANIZER;CN=PythonDeadlines:mailto:[email protected]
4041
END:VEVENT
41-
{% endif %}
42-
{% if cfp != "TBA" and cfp != "None" and cfp != "Cancelled" %}
42+
{%- endif -%}
43+
{%- if cfp != "TBA" and cfp != "None" and cfp != "Cancelled" -%}
4344
BEGIN:VEVENT
4445
SUMMARY:{{ conf.conference }} {{ conf.year }} Deadline {{ extended }}
4546
UID:{{ conf.conference | slugify: "latin" }}-{{ conf.year }}@pythondeadlin.es
4647
DTSTAMP:{{ site.time | date: "%Y%m%dT%H%M%SZ" }}
47-
DTSTART:{{ cfp | date: "%Y%m%dT%H%M%SZ" }}
48+
DTSTART:{{ cfp | to_utc: conf.timezone }}
4849
{{ desc | prepend: "DESCRIPTION:" | normalize_whitespace | wrap_lines }}
4950
ORGANIZER;CN=PythonDeadlines:mailto:[email protected]
5051
END:VEVENT
51-
{% endif %}{% endfor %}
52+
{%- endif -%}{% endfor %}
5253
END:VCALENDAR

_plugins/jekyll-timezone-finder.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# _plugins/timezone_filters.rb
2+
require 'tzinfo'
3+
4+
module Jekyll
5+
module TimezoneFilters
6+
def to_utc(date, timezone = "Etc/GMT+12")
7+
return nil if date.nil? || date == "TBA" || date == "None" || date == "Cancelled"
8+
9+
date = Time.parse(date.to_s) unless date.is_a?(Time)
10+
11+
begin
12+
if timezone&.start_with?("UTC")
13+
offset = timezone[3..-1].to_i
14+
offset_seconds = offset * 3600
15+
time_with_offset = Time.at(date.to_i - offset_seconds).utc
16+
time_with_offset.strftime("%Y%m%dT%H%M%SZ")
17+
else
18+
tz = TZInfo::Timezone.get(timezone)
19+
local = tz.local_datetime(date.year, date.month, date.day, date.hour, date.min, date.sec)
20+
utc = tz.local_to_utc(local)
21+
utc.strftime("%Y%m%dT%H%M%SZ")
22+
end
23+
rescue TZInfo::InvalidTimezoneIdentifier
24+
tz = TZInfo::Timezone.get("Etc/GMT+12")
25+
local = tz.local_datetime(date.year, date.month, date.day, date.hour, date.min, date.sec)
26+
utc = tz.local_to_utc(local)
27+
utc.strftime("%Y%m%dT%H%M%SZ")
28+
end
29+
end
30+
end
31+
end
32+
33+
Liquid::Template.register_filter(Jekyll::TimezoneFilters)

0 commit comments

Comments
 (0)