From 1f70c27e9f3ec11ce04bd857d7cae6f2ff2356bc Mon Sep 17 00:00:00 2001 From: hrwx Date: Mon, 15 Nov 2021 14:33:28 +0000 Subject: [PATCH] chore: rename timezone keys --- frappe/boot.py | 4 ++-- .../system_settings/system_settings.js | 6 ++--- frappe/core/doctype/user/user.js | 6 ++--- frappe/core/doctype/user/user.py | 14 +++++------- .../js/frappe/form/controls/datetime.js | 2 +- frappe/public/js/frappe/utils/datetime.js | 22 +++++++++++-------- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/frappe/boot.py b/frappe/boot.py index fd7564d75a..e671d8b37d 100644 --- a/frappe/boot.py +++ b/frappe/boot.py @@ -329,6 +329,6 @@ def get_notification_settings(): def set_time_zone(bootinfo): bootinfo.time_zone = { - "system_time_zone": get_time_zone(), - "user_time_zone": bootinfo.get("user_info", {}).get(frappe.session.user, {}).get("time_zone", None) or get_time_zone() + "system": get_time_zone(), + "user": bootinfo.get("user_info", {}).get(frappe.session.user, {}).get("time_zone", None) or get_time_zone() } diff --git a/frappe/core/doctype/system_settings/system_settings.js b/frappe/core/doctype/system_settings/system_settings.js index aefe3786bd..0164a1a683 100644 --- a/frappe/core/doctype/system_settings/system_settings.js +++ b/frappe/core/doctype/system_settings/system_settings.js @@ -34,9 +34,7 @@ frappe.ui.form.on("System Settings", { } }, after_save: function(frm) { - if (frappe.boot.time_zone && frappe.boot.time_zone.system_time_zone !== frm.doc.time_zone) { - // Clear cache after saving to refresh the values of time_zone - frappe.ui.toolbar.clear_cache(); - } + // Clear cache after saving to refresh the values of boot. + frappe.ui.toolbar.clear_cache(); } }); diff --git a/frappe/core/doctype/user/user.js b/frappe/core/doctype/user/user.js index 48dc2d1672..681080b2b3 100644 --- a/frappe/core/doctype/user/user.js +++ b/frappe/core/doctype/user/user.js @@ -274,10 +274,8 @@ frappe.ui.form.on('User', { }); }, after_save: function(frm) { - if (frappe.boot.time_zone && frappe.boot.time_zone.user_time_zone !== frm.doc.time_zone) { - // Clear cache after saving to refresh the values of time_zone - frappe.ui.toolbar.clear_cache(); - } + // Clear cache after saving to refresh the values of boot. + frappe.ui.toolbar.clear_cache(); } }); diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index fd19f4d82e..76bdbbbeb8 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -7,7 +7,7 @@ import frappe.defaults import frappe.permissions from frappe.model.document import Document from frappe.utils import (cint, flt, has_gravatar, escape_html, format_datetime, - now_datetime, get_formatted_email, today) + now_datetime, get_formatted_email, today, get_time_zone) from frappe import throw, msgprint, _ from frappe.utils.password import update_password as _update_password, check_password, get_password_reset_limit from frappe.desk.notifications import clear_notifications @@ -231,11 +231,11 @@ class User(Document): def validate_share(self, docshare): pass # if docshare.user == self.name: - # if self.user_type=="System User": - # if docshare.share != 1: - # frappe.throw(_("Sorry! User should have complete access to their own record.")) - # else: - # frappe.throw(_("Sorry! Sharing with Website User is prohibited.")) + # if self.user_type=="System User": + # if docshare.share != 1: + # frappe.throw(_("Sorry! User should have complete access to their own record.")) + # else: + # frappe.throw(_("Sorry! Sharing with Website User is prohibited.")) def send_password_notification(self, new_password): try: @@ -592,8 +592,6 @@ class User(Document): return user def set_time_zone(self): - from frappe.utils import get_time_zone - if not self.time_zone: self.time_zone = get_time_zone() diff --git a/frappe/public/js/frappe/form/controls/datetime.js b/frappe/public/js/frappe/form/controls/datetime.js index b69f40e9c4..3142f1bf0f 100644 --- a/frappe/public/js/frappe/form/controls/datetime.js +++ b/frappe/public/js/frappe/form/controls/datetime.js @@ -63,7 +63,7 @@ frappe.ui.form.ControlDatetime = class ControlDatetime extends frappe.ui.form.Co super.set_description(); } get_user_time_zone() { - return frappe.boot.time_zone ? frappe.boot.time_zone.user_time_zone : frappe.sys_defaults.time_zone; + return frappe.boot.time_zone ? frappe.boot.time_zone.user : frappe.sys_defaults.time_zone; } set_datepicker() { super.set_datepicker(); diff --git a/frappe/public/js/frappe/utils/datetime.js b/frappe/public/js/frappe/utils/datetime.js index 71fdbbb897..c85cbd42e7 100644 --- a/frappe/public/js/frappe/utils/datetime.js +++ b/frappe/public/js/frappe/utils/datetime.js @@ -16,10 +16,10 @@ $.extend(frappe.datetime, { // Converts the datetime string to system time zone first since the database only stores datetime in // system time zone and then convert the string to user time zone(from User doctype). let date_obj = null; - if (frappe.boot.time_zone && frappe.boot.time_zone.system_time_zone && frappe.boot.time_zone.user_time_zone) { - date_obj = moment.tz(date, frappe.boot.time_zone.system_time_zone) + if (frappe.boot.time_zone && frappe.boot.time_zone.system && frappe.boot.time_zone.user) { + date_obj = moment.tz(date, frappe.boot.time_zone.system) .clone() - .tz(frappe.boot.time_zone.user_time_zone); + .tz(frappe.boot.time_zone.user); } else { date_obj = moment(date); } @@ -34,10 +34,10 @@ $.extend(frappe.datetime, { // This is done so that only one timezone is present in database and we do not end up storing local timezone since it changes // as per the location of user. let date_obj = null; - if (frappe.boot.time_zone && frappe.boot.time_zone.system_time_zone && frappe.boot.time_zone.user_time_zone) { - date_obj = moment.tz(date, frappe.boot.time_zone.user_time_zone) + if (frappe.boot.time_zone && frappe.boot.time_zone.system && frappe.boot.time_zone.user) { + date_obj = moment.tz(date, frappe.boot.time_zone.user) .clone() - .tz(frappe.boot.time_zone.system_time_zone); + .tz(frappe.boot.time_zone.system); } else { date_obj = moment(date); } @@ -46,13 +46,17 @@ $.extend(frappe.datetime, { }, is_system_time_zone: function() { - if (frappe.boot.time_zone && frappe.boot.time_zone.system_time_zone && frappe.boot.time_zone.user_time_zone) { - return moment().tz(frappe.boot.time_zone.system_time_zone).utcOffset() === moment().tz(frappe.boot.time_zone.user_time_zone).utcOffset(); + if (frappe.boot.time_zone && frappe.boot.time_zone.system && frappe.boot.time_zone.user) { + return moment().tz(frappe.boot.time_zone.system).utcOffset() === moment().tz(frappe.boot.time_zone.user).utcOffset(); } return true; }, + is_timezone_same: function() { + return frappe.datetime.is_system_time_zone(); + }, + str_to_obj: function(d) { return moment(d, frappe.defaultDatetimeFormat)._d; }, @@ -204,7 +208,7 @@ $.extend(frappe.datetime, { * This will make sure that at any point we know which timezone the user if following and not have random timezone * when the timezone of the local machine changes. */ - let time_zone = frappe.boot.time_zone ? frappe.boot.time_zone.user_time_zone || frappe.boot.time_zone.system_time_zone : frappe.sys_defaults.time_zone; + let time_zone = frappe.boot.time_zone ? frappe.boot.time_zone.user || frappe.boot.time_zone.system : frappe.sys_defaults.time_zone; let date = moment.tz(time_zone); return as_obj ? frappe.datetime.moment_to_date_obj(date) : date.format(format);