Merge lp:~trimardio/widelands-website/scheduler_utc_fix into lp:widelands-website

Proposed by Trimardio
Status: Merged
Merged at revision: 542
Proposed branch: lp:~trimardio/widelands-website/scheduler_utc_fix
Merge into: lp:widelands-website
Diff against target: 103 lines (+14/-15)
4 files modified
wlscheduling/static/js/scheduling.js (+9/-10)
wlscheduling/templates/wlscheduling/find.html (+1/-1)
wlscheduling/templates/wlscheduling/scheduling.html (+1/-1)
wlscheduling/views.py (+3/-3)
To merge this branch: bzr merge lp:~trimardio/widelands-website/scheduler_utc_fix
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+369479@code.launchpad.net

Commit message

Fix the display of UTC. Currently, if there was no difference between your profile registered UTC and your browser's the text just says "you are currently noted as UTC" instead of "UTC + x"

To post a comment you must log in.
Revision history for this message
kaputtnik (franku) wrote :

Looks good so far :)

+1 for renaming the function!

Can you please also take care of the '2 hours problem' which i reported in the forum? I guess it's caused by the js_offset in line 205?:

https://bazaar.launchpad.net/~trimardio/widelands-website/scheduler_utc_fix/view/head:/wlscheduling/static/js/scheduling.js#L205

543. By Trimard \<email address hidden>

fix displayed hour from other users

544. By Trimard \<email address hidden>

forbid adding of an hour that has already passed

Revision history for this message
kaputtnik (franku) wrote :

OK, this is merged and deployed now.

Users may have to press CTRL+F5 to reload the js.

Thanks for the fix :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'wlscheduling/static/js/scheduling.js'
2--- wlscheduling/static/js/scheduling.js 2018-11-22 17:50:41 +0000
3+++ wlscheduling/static/js/scheduling.js 2019-06-30 17:48:43 +0000
4@@ -17,17 +17,17 @@
5
6
7 // Add warning in case of disparency between browser and profil timezone
8-function addTimeZoneWarningIfNeeded() {
9+function addTimeZoneInfo() {
10 var userTimeZone = document.getElementById('django-data').getAttribute('user-time-zone')
11 var browserTimeZone = - new Date().getTimezoneOffset()/60
12 if ( browserTimeZone != userTimeZone) {
13 document.getElementById('timezone-error').removeAttribute("hidden");
14- profilTime = document.getElementsByClassName('profil-time');
15- for (var element in profilTime) {
16- profilTime[element].innerHTML = cleanAndAddSign(userTimeZone);
17- }
18- document.getElementById('browser-time').innerHTML = cleanAndAddSign(browserTimeZone);
19- }
20+ }
21+ profilTime = document.getElementsByClassName('profil-time');
22+ for (var element in profilTime) {
23+ profilTime[element].innerHTML = cleanAndAddSign(userTimeZone);
24+ }
25+ document.getElementById('browser-time').innerHTML = cleanAndAddSign(browserTimeZone);
26 }
27
28 function addPreviousDateFromUser(calendar) {
29@@ -171,6 +171,7 @@
30 }
31
32 function createUserDivOrUpdateIt(user, availTime) {
33+ // Create User div
34 if (!document.getElementById("user-" + user)){
35 var original = document.getElementById('other-user-template');
36 // We clone the date and fix different attributes
37@@ -201,10 +202,8 @@
38 } else {
39 otherUser = document.getElementById("user-" + user);
40 }
41+ // get exact hour from string
42 var dtavailTime = new Date(availTime + ":00:00");
43- // Remove timezone offset which js automatically add...
44- js_offset = dtavailTime.getTimezoneOffset()/60
45- dtavailTime = dtavailTime.addHours(js_offset);
46 textDate = dtavailTime.toDateString();
47 var dateFormated = dtavailTime.getFullYear() + "-" + dtavailTime.getMonth() + '-' + dtavailTime.getDay()
48 var availTimeFormated = dtavailTime.getHours()
49
50=== modified file 'wlscheduling/templates/wlscheduling/find.html'
51--- wlscheduling/templates/wlscheduling/find.html 2018-11-09 07:00:30 +0000
52+++ wlscheduling/templates/wlscheduling/find.html 2019-06-30 17:48:43 +0000
53@@ -10,7 +10,7 @@
54 {% block content_main %}
55 <script type="text/javascript">
56 document.addEventListener('DOMContentLoaded', function(){
57- addTimeZoneWarningIfNeeded();
58+ addTimeZoneInfo();
59 addOtherUsersAvailabilities();
60 }, false);
61 </script>
62
63=== modified file 'wlscheduling/templates/wlscheduling/scheduling.html'
64--- wlscheduling/templates/wlscheduling/scheduling.html 2018-03-11 16:12:19 +0000
65+++ wlscheduling/templates/wlscheduling/scheduling.html 2019-06-30 17:48:43 +0000
66@@ -12,7 +12,7 @@
67 <script type="text/javascript">
68 document.addEventListener('DOMContentLoaded', function(){
69 var calendar = createCalendar();
70- addTimeZoneWarningIfNeeded();
71+ addTimeZoneInfo();
72 addPreviousDateFromUser(calendar);
73 addOtherUsersAvailabilities();
74
75
76=== modified file 'wlscheduling/views.py'
77--- wlscheduling/views.py 2019-04-11 15:06:09 +0000
78+++ wlscheduling/views.py 2019-06-30 17:48:43 +0000
79@@ -26,7 +26,7 @@
80 other_users_availabilities = {}
81 for a in Availabilities.objects.exclude(user=current_user).order_by('avail_time'):
82 user_utc_dt_avail_time = a.avail_time
83- if datetime.now() < user_utc_dt_avail_time:
84+ if datetime.utcnow() < user_utc_dt_avail_time:
85 other_user = a.user
86 current_user_timezone = current_user.wlprofile.time_zone
87 user_dt_avail_time = user_utc_dt_avail_time + timedelta(hours= current_user_timezone)
88@@ -63,13 +63,13 @@
89
90 for request_avail_time in request_avail_times:
91 dt_avail_time = datetime.strptime(request_avail_time, TIME_FORMAT)
92- # Actual change of timezone, we got back to UTC
93+ # Actual change of timezone, we go back to UTC
94 utc_dt_avail_time = dt_avail_time + timedelta(hours= - user_timezone)
95 avail_time_already_exist = False
96 for a in Availabilities.objects.filter(user=current_user, avail_time=utc_dt_avail_time):
97 avail_time_already_exist = True
98
99- if not avail_time_already_exist:
100+ if not avail_time_already_exist and datetime.utcnow() < utc_dt_avail_time :
101 a = Availabilities.objects.create(
102 user=current_user,
103 avail_time=utc_dt_avail_time

Subscribers

People subscribed via source and target branches