-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allowing storing/updating time_zone in mobile app user settings table #2601
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
engine/apps/mobile_app/migrations/0010_mobileappusersettings_time_zone.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 3.2.20 on 2023-07-20 14:53 | ||
|
||
from django.db import migrations, models | ||
from django_add_default_value import AddDefaultValue | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('mobile_app', '0009_fcmdevice'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='mobileappusersettings', | ||
name='time_zone', | ||
field=models.CharField(default='UTC', max_length=100), | ||
), | ||
# migrations.AddField enforces the default value on the app level, which leads to the issues during release | ||
# adding same default value on the database level | ||
AddDefaultValue( | ||
model_name='mobileappusersettings', | ||
name='time_zone', | ||
value='UTC', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
from common.api_helpers.utils import create_engine_url | ||
from common.custom_celery_tasks import shared_dedicated_queue_retry_task | ||
from common.l10n import format_localized_datetime, format_localized_time | ||
from common.timezones import is_valid_timezone | ||
|
||
if typing.TYPE_CHECKING: | ||
from apps.mobile_app.models import FCMDevice, MobileAppUserSettings | ||
|
@@ -235,7 +234,6 @@ def _get_youre_going_oncall_notification_subtitle( | |
schedule: OnCallSchedule, | ||
schedule_event: ScheduleEvent, | ||
mobile_app_user_settings: "MobileAppUserSettings", | ||
user_timezone: typing.Optional[str], | ||
) -> str: | ||
shift_start = schedule_event["start"] | ||
shift_end = schedule_event["end"] | ||
|
@@ -244,16 +242,11 @@ def _get_youre_going_oncall_notification_subtitle( | |
|
||
def _format_datetime(dt: datetime.datetime) -> str: | ||
""" | ||
1. Convert the shift datetime to the user's configured timezone, if set, otherwise fallback to UTC | ||
1. Convert the shift datetime to the user's mobile device's timezone | ||
2. Display the timezone aware datetime as a formatted string that is based on the user's configured mobile | ||
app locale, otherwise fallback to "en" | ||
""" | ||
if user_timezone is None or not is_valid_timezone(user_timezone): | ||
user_tz = "UTC" | ||
else: | ||
user_tz = user_timezone | ||
|
||
localized_dt = dt.astimezone(pytz.timezone(user_tz)) | ||
localized_dt = dt.astimezone(pytz.timezone(mobile_app_user_settings.time_zone)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. main change of the PR |
||
return dt_formatter_func(localized_dt, mobile_app_user_settings.locale) | ||
|
||
formatted_shift = f"{_format_datetime(shift_start)} - {_format_datetime(shift_end)}" | ||
|
@@ -277,7 +270,7 @@ def _get_youre_going_oncall_fcm_message( | |
|
||
notification_title = _get_youre_going_oncall_notification_title(seconds_until_going_oncall) | ||
notification_subtitle = _get_youre_going_oncall_notification_subtitle( | ||
schedule, schedule_event, mobile_app_user_settings, user.timezone | ||
schedule, schedule_event, mobile_app_user_settings | ||
) | ||
|
||
data: FCMMessageData = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are already using "UTC" as the fallback value here if a value is not set in the
user
object.