pretty timezone names

This commit is contained in:
0Pranav 2019-11-14 11:25:49 +05:30
parent 4006eb5277
commit 793ba8fc06
2 changed files with 21 additions and 5 deletions

View File

@ -13,7 +13,7 @@ async function initialise_select_date() {
} }
async function get_global_variables() { async function get_global_variables() {
// Using await // Using await through this file instead of then.
window.appointment_settings = (await frappe.call({ window.appointment_settings = (await frappe.call({
method: 'erpnext.www.book-appointment.index.get_appointment_settings' method: 'erpnext.www.book-appointment.index.get_appointment_settings'
})).message; })).message;
@ -24,15 +24,20 @@ async function get_global_variables() {
} }
function setup_timezone_selector() { function setup_timezone_selector() {
/**
* window.timezones is a dictionary with the following structure
* { IANA name: Pretty name}
* For example : { Asia/Kolkata : "India Time - Asia/Kolkata"}
*/
let timezones_element = document.getElementById('appointment-timezone'); let timezones_element = document.getElementById('appointment-timezone');
let offset = new Date().getTimezoneOffset(); let offset = new Date().getTimezoneOffset();
window.timezones.forEach(timezone => { Object.keys(window.timezones).forEach((timezone) => {
let opt = document.createElement('option'); let opt = document.createElement('option');
opt.value = timezone; opt.value = timezone;
if (timezone == moment.tz.guess()) { if (timezone == moment.tz.guess()) {
opt.selected = true; opt.selected = true;
} }
opt.innerHTML = timezone; opt.innerHTML = window.timezones[timezone]
timezones_element.appendChild(opt) timezones_element.appendChild(opt)
}); });
} }

View File

@ -25,7 +25,18 @@ def get_appointment_settings():
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def get_timezones(): def get_timezones():
return pytz.all_timezones from babel.dates import get_timezone, get_timezone_name, Locale
from frappe.utils.momentjs import get_all_timezones
translated_dict = {}
locale = Locale.parse(frappe.local.lang, sep="-")
for tz in get_all_timezones():
timezone_name = get_timezone_name(get_timezone(tz), locale=locale, width='short')
if timezone_name:
translated_dict[tz] = timezone_name + ' - ' + tz
return translated_dict
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def get_appointment_slots(date, timezone): def get_appointment_slots(date, timezone):