diff --git a/cron.yaml b/cron.yaml index 507c288c..f3368e59 100644 --- a/cron.yaml +++ b/cron.yaml @@ -2,19 +2,19 @@ cron: - description: Syncs employee data from s3 url: /tasks/populate_employees schedule: every day 03:00 - timezone: US/Pacific + timezone: America/Los_Angeles - description: weekly meeting spec generation url: /tasks/generate_meeting_specs_for_week schedule: every monday 9:00 - timezone: US/Pacific + timezone: America/Los_Angeles - description: weekly opt-in email url: /tasks/email_users_for_weekly_opt_in schedule: every monday 11:00 - timezone: US/Pacific + timezone: America/Los_Angeles - description: weekly match url: /tasks/match_employees schedule: every wednesday 11:00 - timezone: US/Pacific + timezone: America/Los_Angeles diff --git a/js/reducers/preferences.js b/js/reducers/preferences.js index d6a3aa0c..e13e4414 100644 --- a/js/reducers/preferences.js +++ b/js/reducers/preferences.js @@ -5,7 +5,7 @@ const defaultValue = [ id: 'None', location: 'Unknown', title: 'No Meetings Set Up', - timezone: 'US/Pacific', + timezone: 'America/Los_Angeles', size: 0, office: 'None', datetime: [], diff --git a/tests/conftest.py b/tests/conftest.py index 65133706..a268d32b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,8 +12,6 @@ import pytest from google.appengine.ext import ndb from google.appengine.ext import testbed -from pytz import timezone -from pytz import utc from yelp_beans import send_email from yelp_beans.logic.subscription import get_specs_from_subscription @@ -73,17 +71,11 @@ def subscription(): def _subscription(): - zone = 'US/Pacific' - preference_1 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 23, 0, tzinfo=utc)) - # Easier to think/verify in Pacific time since we are based in SF - assert preference_1.datetime.astimezone(timezone(zone)).hour == 15 - preference_1.datetime = preference_1.datetime.replace(tzinfo=None) + zone = 'America/Los_Angeles' + preference_1 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 13, 0)) preference_1.put() - preference_2 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 19, 0, tzinfo=utc)) - # Easier to think/verify in Pacific time since we are based in SF - assert preference_2.datetime.astimezone(timezone(zone)).hour == 11 - preference_2.datetime = preference_2.datetime.replace(tzinfo=None) + preference_2 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 11, 0)) preference_2.put() rule = Rule(name='office', value='USA: CA SF New Montgomery Office').put() diff --git a/tests/logic/subscription_test.py b/tests/logic/subscription_test.py index 26d20526..bfccb4a6 100644 --- a/tests/logic/subscription_test.py +++ b/tests/logic/subscription_test.py @@ -3,22 +3,37 @@ from __future__ import print_function from __future__ import unicode_literals +from datetime import datetime + import pytest +from yelp_beans.logic.meeting_spec import get_meeting_datetime from yelp_beans.logic.subscription import filter_subscriptions_by_user_data from yelp_beans.logic.subscription import get_specs_from_subscription from yelp_beans.logic.subscription import get_subscription_dates from yelp_beans.logic.subscription import merge_subscriptions_with_preferences from yelp_beans.logic.subscription import store_specs_from_subscription from yelp_beans.models import MeetingSpec +from yelp_beans.models import MeetingSubscription from yelp_beans.models import Rule +from yelp_beans.models import SubscriptionDateTime from yelp_beans.models import User from yelp_beans.models import UserSubscriptionPreferences -def test_get_specs_from_subscription(database): - week_start, specs = get_specs_from_subscription(database.sub) - assert len(specs) == 2 +def test_get_specs_from_subscription_pst(minimal_database): + preference = SubscriptionDateTime(datetime=datetime(2017, 7, 20, 13, 0)).put() + subscription = MeetingSubscription(timezone='America/Los_Angeles', datetime=[preference]).put() + _, specs = get_specs_from_subscription(subscription.get()) + assert len(specs) == 1 + assert get_meeting_datetime(specs[0]).hour == 13 + + +def test_get_specs_from_subscription_pdt(minimal_database): + preference = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 13, 0)).put() + subscription = MeetingSubscription(timezone='America/Los_Angeles', datetime=[preference]).put() + _, specs = get_specs_from_subscription(subscription.get()) + assert get_meeting_datetime(specs[0]).hour == 13 def test_store_specs_from_subscription(database): @@ -30,7 +45,7 @@ def test_store_specs_from_subscription(database): def test_get_subscription_dates(database): dates = get_subscription_dates(database.sub) assert len(dates) == 2 - assert dates[1]['date'] == '2017-01-20T19:00:00+00:00' + assert dates[1]['date'] == '2017-01-20T11:00:00' def test_merge_subscriptions_with_preferences(database, fake_user): @@ -40,18 +55,18 @@ def test_merge_subscriptions_with_preferences(database, fake_user): 'title': 'Yelp Weekly', 'location': '8th Floor', 'office': 'USA: CA SF New Montgomery Office', - 'timezone': 'US/Pacific', + 'timezone': 'America/Los_Angeles', 'size': 2, 'rule_logic': None, 'datetime': [ { 'active': True, - 'date': '2017-01-20T23:00:00+00:00', + 'date': '2017-01-20T13:00:00', 'id': database.sub.datetime[0].urlsafe() }, { 'active': False, - 'date': '2017-01-20T19:00:00+00:00', + 'date': '2017-01-20T11:00:00', 'id': database.sub.datetime[1].urlsafe() } ] diff --git a/tests/routes/api/v1/metrics_test.py b/tests/routes/api/v1/metrics_test.py index d58d1794..a9721f3e 100644 --- a/tests/routes/api/v1/metrics_test.py +++ b/tests/routes/api/v1/metrics_test.py @@ -50,22 +50,10 @@ def test_get_meeting_participants(app, database): MeetingParticipant(meeting=meeting1, user=user2.key).put() with app.test_request_context('/v1/metrics/meeting_participants'): participants = json.loads(meeting_participants()) - assert participants == [ - { - 'date': '2017-10-27T23:00:00', - 'meeting': 'agx0ZXN0YmVkLXRlc3RyDQsSB01lZXRpbmcYCgw', - 'meeting_title': 'Yelp Weekly', - 'participant': 'a@yelp.com', - 'time': '04:00PM' - }, - { - 'date': '2017-10-27T23:00:00', - 'meeting': 'agx0ZXN0YmVkLXRlc3RyDQsSB01lZXRpbmcYCgw', - 'meeting_title': 'Yelp Weekly', - 'participant': 'b@yelp.com', - 'time': '04:00PM' - } - ] + assert len(participants) == 2 + assert set(participants[0].keys()) == set(['date', 'meeting', 'meeting_title', 'participant', 'time']) + assert participants[0]['date'] == database.specs[0].datetime.isoformat() + assert participants[0]['time'] == database.specs[0].datetime.strftime('%I:%M%p') def test_get_meeting_requests(app, database): diff --git a/tests/routes/api/v1/preference_test.py b/tests/routes/api/v1/preference_test.py index 3fc457f3..617244ed 100644 --- a/tests/routes/api/v1/preference_test.py +++ b/tests/routes/api/v1/preference_test.py @@ -25,18 +25,18 @@ def test_preferences_api_user_exists(app, database, fake_user): 'title': 'Yelp Weekly', 'location': '8th Floor', 'office': 'USA: CA SF New Montgomery Office', - 'timezone': 'US/Pacific', + 'timezone': 'America/Los_Angeles', 'size': 2, 'rule_logic': None, 'datetime': [ { 'active': True, - 'date': '2017-01-20T23:00:00+00:00', + 'date': '2017-01-20T13:00:00', 'id': database.sub.datetime[0].urlsafe() }, { 'active': False, - 'date': '2017-01-20T19:00:00+00:00', + 'date': '2017-01-20T11:00:00', 'id': database.sub.datetime[1].urlsafe() } ], diff --git a/yelp_beans/logic/meeting_spec.py b/yelp_beans/logic/meeting_spec.py index 311c1c14..ed4b1240 100644 --- a/yelp_beans/logic/meeting_spec.py +++ b/yelp_beans/logic/meeting_spec.py @@ -8,7 +8,6 @@ from datetime import timedelta from pytz import timezone -from pytz import utc from yelp_beans.models import MeetingSpec from yelp_beans.models import User @@ -56,6 +55,11 @@ def get_users_from_spec(meeting_spec): def get_meeting_datetime(meeting_spec): + """ + Given a meeting_spec, returns the meeting datetime in the appropriate timezone. + :param meeting_spec: models.meeting_spec + :return: datetime.datetime in the correct timezone + """ meeting_datetime = meeting_spec.datetime - meeting_timezone = meeting_spec.meeting_subscription.get().timezone - return meeting_datetime.replace(tzinfo=utc).astimezone(timezone(meeting_timezone)) + meeting_timezone = timezone(meeting_spec.meeting_subscription.get().timezone) + return meeting_timezone.localize(meeting_datetime) diff --git a/yelp_beans/logic/subscription.py b/yelp_beans/logic/subscription.py index f4de8396..449ba893 100644 --- a/yelp_beans/logic/subscription.py +++ b/yelp_beans/logic/subscription.py @@ -8,7 +8,6 @@ from google.appengine.ext import ndb from google.appengine.ext.db import NeedIndexError -from pytz import utc from yelp_beans.models import MeetingSpec from yelp_beans.models import MeetingSubscription @@ -87,7 +86,7 @@ def get_subscription_dates(subscription): return [ { 'id': date.urlsafe(), - 'date': date.get().datetime.replace(tzinfo=utc).isoformat(), + 'date': date.get().datetime.isoformat(), 'active': False } for date in subscription.datetime diff --git a/yelp_beans/send_email.py b/yelp_beans/send_email.py index aa9827f3..7d05542e 100644 --- a/yelp_beans/send_email.py +++ b/yelp_beans/send_email.py @@ -143,8 +143,8 @@ def send_match_email(user, participants, meeting_spec): 'location': subscription.office + " " + subscription.location, 'meeting_start_day': meeting_datetime.strftime('%A'), 'meeting_start_date': meeting_datetime.strftime('%m/%d/%Y'), - 'meeting_start_time': meeting_datetime.strftime('%I:%M %p'), - 'meeting_end_time': meeting_datetime_end.strftime('%I:%M %p'), + 'meeting_start_time': meeting_datetime.strftime('%I:%M %p %Z'), + 'meeting_end_time': meeting_datetime_end.strftime('%I:%M %p %Z'), 'calendar_invite_url': create_google_calendar_invitation_link( participants, subscription.title,