From bec14d35d7a70e3da54152a1fbd6e673b94f0565 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 20 2018 10:04:50 +0000 Subject: [PATCH 1/3] Ensure the time-zones are always sorted --- diff --git a/fedocal/forms.py b/fedocal/forms.py index f25699b..631ec66 100644 --- a/fedocal/forms.py +++ b/fedocal/forms.py @@ -148,7 +148,7 @@ class AddMeetingForm(i18nforms.Form): meeting_timezone = wtforms.SelectField( _('Time zone'), [wtforms.validators.Required()], - choices=[(tzone, tzone) for tzone in common_timezones]) + choices=[(tzone, tzone) for tzone in sorted(common_timezones)]) wiki_link = wtforms.TextField(_('More information URL')) From 6ae4a91962c742e10e9efbcf3164160e18b38c9f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 20 2018 10:04:50 +0000 Subject: [PATCH 2/3] Make the start and stop time of the meeting be in the same format --- diff --git a/fedocal/templates/default/view_meeting.html b/fedocal/templates/default/view_meeting.html index 0fe00a2..ccc15c2 100644 --- a/fedocal/templates/default/view_meeting.html +++ b/fedocal/templates/default/view_meeting.html @@ -36,7 +36,8 @@ {{ _('End:') }} {{ next_meeting.meeting_date_end.strftime('%a, %B %d, %Y') }} - {{ - next_meeting.meeting_time_stop }} {{ tzone }} + next_meeting.meeting_time_stop.strftime('%H:%M') }} {{ tzone }} +
From 37cec1e30ea5529ed353cfc93a678504546eea4b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 20 2018 10:04:50 +0000 Subject: [PATCH 3/3] Fix showing the meeting in its proper time Basically we were converting the meeting to UTC before retrieving its next occurrence which meant that around DST changes the date/time conversion was getting messed up. With this change we are fixing this conversion and adding tests to check it behaves as expected. --- diff --git a/fedocal/__init__.py b/fedocal/__init__.py index 9ba8ea3..d67be01 100644 --- a/fedocal/__init__.py +++ b/fedocal/__init__.py @@ -1077,9 +1077,6 @@ def view_meeting_page(meeting_id, full): 'errors') return flask.redirect(flask.url_for('index')) - meeting_utc = fedocallib.convert_meeting_timezone( - org_meeting, org_meeting.meeting_timezone, 'UTC') - editor = False if is_meeting_manager(org_meeting) or is_calendar_admin( org_meeting.calendar): @@ -1093,9 +1090,13 @@ def view_meeting_page(meeting_id, full): pass next_meeting = fedocallib.update_date_rec_meeting( - meeting_utc, action='next', date_limit=date_limit) + org_meeting, action='next', date_limit=date_limit) + + meeting_utc = fedocallib.convert_meeting_timezone( + next_meeting, org_meeting.meeting_timezone, 'UTC') + next_meeting = fedocallib.convert_meeting_timezone( - next_meeting, 'UTC', tzone) + next_meeting, org_meeting.meeting_timezone, tzone) return flask.render_template( 'view_meeting.html', diff --git a/tests/test_flask.py b/tests/test_flask.py index 4e7ff12..d8fa0df 100644 --- a/tests/test_flask.py +++ b/tests/test_flask.py @@ -2,7 +2,7 @@ #-*- coding: utf-8 -*- """ - (c) 2012 - Copyright Pierre-Yves Chibon + (c) 2012-2017 - Copyright Pierre-Yves Chibon Author: Pierre-Yves Chibon Distributed under License GPLv3 or later @@ -597,6 +597,118 @@ class Flasktests(Modeltests): flask.g.fas_user = FakeUser(['gitr2spec']) self.assertFalse(fedocal.is_calendar_admin(calendar)) + def test_view_meeting_page_dst(self): + """ Test the view_meeting_page function accross the DST time change + """ + # Create calendar + obj = model.Calendar( + calendar_name='test_calendar', + calendar_contact='test@example.com', + calendar_description='This is a test calendar', + calendar_editor_group='fi-apprentice', + calendar_admin_group='infrastructure-main2') + obj.save(self.session) + self.session.commit() + self.assertNotEqual(obj, None) + + # Add a meeting + mdate = date(2017, 1, 2) + obj = model.Meeting( # id:1 + meeting_name='Fedora-fr-test-meeting', + meeting_date=mdate, + meeting_date_end=mdate, + meeting_time_start=time(9, 00), + meeting_time_stop=time(10, 00), + meeting_timezone='America/New_York', + meeting_information='This is a test meeting', + calendar_name='test_calendar', + recursion_frequency=7, + recursion_ends=mdate + timedelta(days=365) + ) + obj.add_manager(self.session, 'pingou, shaiton,') + obj.save(self.session) + self.session.commit() + self.assertNotEqual(obj, None) + + # Winter time + output = self.app.get('/meeting/1/?from_date=2017-02-27') + self.assertEqual(output.status_code, 200) + self.assertTrue( + 'Meeting "Fedora-fr-test-meeting" - Fedocal' + in output.data) + self.assertTrue( + 'Mon, February 27, 2017 - 14:00 UTC' + in output.data) + self.assertTrue( + 'Mon, February 27, 2017 - 15:00:00 UTC' + in output.data) + + # Summer time + output = self.app.get('/meeting/1/?from_date=2017-03-13') + self.assertEqual(output.status_code, 200) + self.assertTrue( + 'Meeting "Fedora-fr-test-meeting" - Fedocal' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 13:00 UTC' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 14:00 UTC' + in output.data) + + # Summer time in the US + output = self.app.get( + '/meeting/1/?from_date=2017-03-13&tzone=America/New_York') + self.assertEqual(output.status_code, 200) + self.assertTrue( + 'Meeting "Fedora-fr-test-meeting" - Fedocal' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 13:00:00 UTC' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 14:00:00 UTC' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 09:00 America/New_York' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 10:00 America/New_York' + in output.data) + + # Summer time in the US but not in Europe + output = self.app.get( + '/meeting/1/?from_date=2017-03-13&tzone=Europe/Paris') + self.assertEqual(output.status_code, 200) + self.assertTrue( + 'Meeting "Fedora-fr-test-meeting" - Fedocal' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 13:00:00 UTC' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 14:00:00 UTC' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 14:00 Europe/Paris' + in output.data) + self.assertTrue( + 'Mon, March 13, 2017 - 15:00 Europe/Paris' + in output.data) + + # Winter time again + output = self.app.get('/meeting/1/?from_date=2017-11-20') + self.assertEqual(output.status_code, 200) + self.assertTrue( + 'Meeting "Fedora-fr-test-meeting" - Fedocal' + in output.data) + self.assertTrue( + 'Mon, November 20, 2017 - 14:00 UTC' + in output.data) + self.assertTrue( + 'Mon, November 20, 2017 - 15:00 UTC' + in output.data) + def test_is_calendar_manager(self): """ Test the is_calendar_manager function. """ self.__setup_db()