Skip to content

Commit

Permalink
Improve detection of Time-Zone inconsistencies
Browse files Browse the repository at this point in the history
We have a track record of Time-Zone inconsistencies in the events of the
project website (e.g. #1616, #1805, #2288, #2418, #2422, #2431, #2449).

In order to detect these inconsistencies earlier, make the `tz`
mandatory and check that the Time-Zone offset match the Time-Zone name.
These checks require a working bundle so run it on GitHub actions and
keep the old pre-commit check to only check date formatting using basic
UNIX tooling.

Adjust the events templates to match what we expect.

While here, also check that non-online events have the needed
`location.city` and `location.country`.

Signed-off-by: Romain Tartière <[email protected]>
  • Loading branch information
smortex committed Nov 28, 2023
1 parent 22c7eef commit a924d21
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 17 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/jekyll-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ jobs:
ruby-version: '3.0'
bundler-cache: true
- run: |
malformed_event_dates=$(grep -Er --files-without-match '^eventdate: [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [-+][0-9]{4}$' _events)
if [ -n "${malformed_event_dates}" ]; then
echo "Malformed event date in:" >&2
echo "${malformed_event_dates}" >&2
exit 1
fi
bundle exec _scripts/_malformedevents.rb
bundle exec jekyll build --future
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ group :jekyll_plugins do
gem "jekyll-sitemap"
end

group :test do
gem "activesupport"
end

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
platforms :mingw, :x64_mingw, :mswin, :jruby do
Expand Down
3 changes: 1 addition & 2 deletions _events/_0000-0000-communitymeeting-template.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
eventdate: 2023-02-28 15:00:00 -0800
title: OpenSearch Community Meeting - 2023-02-28
online: true
# If the event is online, remove the next line, otherwise uncomment and adjust it:
# tz: Pacific/Tahiti
tz: America/Los_Angeles
signup:
url: https://www.meetup.com/opensearch/events/290444926/
title: Join on Meetup
Expand Down
3 changes: 1 addition & 2 deletions _events/_0000-0000-dev-officehours-dashboards.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ eventdate: 2023-05-05 10:00:00 -0700
title: OpenSearch Dashboards Developer Office Hours - YYYY-MM-DD
# if your event has an online component, put it here (mind the time-zone and daylight saving time!):
online: true
# If the event is online, remove the next line, otherwise uncomment and adjust it:
# tz: Pacific/Tahiti
tz: America/Los_Angeles
# This is for the sign up button
signup:
# the link URL
Expand Down
6 changes: 3 additions & 3 deletions _events/_sample.markdown
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
# put your event date and time (24 hr) here (mind the time-zone and daylight saving time!):
eventdate: 2021-01-01 12:34:00 -0700
eventdate: 2021-01-01 12:34:00 -0800
# If the event last multiple day, also add the end date:
# enddate: 2021-01-03 20:00:00 -0700
# enddate: 2021-01-03 20:00:00 -0800

# the title - this is how it will show up in listing and headings on the site:
title: Your Event Title
online: true
tz: America/Los_Angeles
# If the event is online, remove the next lines, otherwise uncomment and adjust:
# tz: Pacific/Tahiti
# location:
# city: Papeete
# country: French Polynesia
Expand Down
8 changes: 4 additions & 4 deletions _scripts/_malformeddates.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/bin/sh

malformed_event_dates=$(grep -Er --files-without-match '^eventdate: [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [-+][0-9]{4}$' _events)
if [ -n "${malformed_event_dates}" ]; then
echo "Malformed event date in:" >&2
echo "${malformed_event_dates}" >&2
exit 1
echo "Malformed event date in:" >&2
echo "${malformed_event_dates}" >&2
exit 1
fi
67 changes: 67 additions & 0 deletions _scripts/_malformedevents.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env ruby

require 'active_support'
require 'active_support/time'

require 'yaml'

issues = 0

Dir['_events/*'].each do |filename|
data = YAML.safe_load_file(filename, permitted_classes: [Time])
start_date = data['eventdate']
end_date = data['enddate']
tz = data['tz']

if tz.nil?
message = "#{filename}: All events must have a 'tz' key"
if start_date
message += %{ (based on the time-zone offset of 'eventdate' (#{start_date}), it may be "#{ActiveSupport::TimeZone[start_date.utc_offset].tzinfo.identifier}")}
end

warn message
issues += 1
end

if data['online'] == false
if data.dig('location', 'city').nil?
warn "#{filename}: non-online events must have a 'location.city' key"
issues += 1
end

if data.dig('location', 'country').nil?
warn "#{filename}: non-online events must have a 'location.country' key"
issues += 1
end
end

if start_date.nil?
warn "#{filename}: All events must have an 'eventdate' key"
issues += 1
elsif start_date.is_a?(Time)
x = start_date.in_time_zone(tz)
if x.utc_offset != start_date.utc_offset
warn %{#{filename}: event 'eventdate' (#{start_date}) in not in 'tz' (#{tz}) (did you mean "#{x}"?)}
issues += 1
end
else
warn "#{filename}: event 'eventdate' (#{start_date}) is not a valid RFC822 date"
issues += 1
end

if end_date.is_a?(Time)
x = end_date.in_time_zone(tz)
if x.utc_offset != start_date.utc_offset
warn %{#{filename}: event 'enddate' (#{end_date}) in not in 'tz' (#{tz}) (did you mean "#{x}"?)}
issues += 1
end
elsif end_date
warn "#{filename}: event 'enddate' (#{end_date}) is not a valid RFC822 date"
issues += 1
end
end

if issues > 0
warn "#{issues} problems found in events."
exit 1
end

0 comments on commit a924d21

Please sign in to comment.