#20663: Admin Now and Today buttons use confusing time / timezone
-------------------------------+-------------------------------------
     Reporter:  imfletcher     |                    Owner:  aaugustin
         Type:  Bug            |                   Status:  assigned
    Component:  contrib.admin  |                  Version:  1.5
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  1              |      Needs documentation:  1
  Needs tests:  1              |  Patch needs improvement:  1
Easy pickings:  1              |                    UI/UX:  0
-------------------------------+-------------------------------------

Comment (by loic84):

 I've tried to come up with selenium tests but it turned out to be
 problematic because both the LiveServer (which runs in a different thread)
 and the browser (because of selenium) run in the default time zone
 (America/Chicago).

 I tried changing the time zone for either selenium or the LiveServer with
 a custom `setUpClass()` but I didn't manage.

 I came up with the following JavaScript monkey-patch which makes the
 browser pretend to be running in a different time zone (at least for our
 purpose), but I failed to inject it before the DOM ready event.

 {{{
 # UTC offset in minutes as given by JavaScript Date.getTimezoneOffset().
 browser_offset = 480  # Singapore.
 server_offset =
 datetime.now(timezone.get_current_timezone()).utcoffset().total_seconds()
 / 60

 monkeypatch = """
 Date.prototype.getTimezoneOffset = function() { return %d; };
 var originalGetTime = Date.prototype.getTime;
 Date.prototype.getTime = function() { return originalGetTime.apply(this) -
 %d; };
 console.log('monkeypatch');
 """ % (browser_offset, (browser_offset + server_offset) * 60 * 1000)

 self.selenium.execute_script(monkeypatch)
 }}}

 I'm pretty much out of ideas. In case anyone want to have a go at this,
 the basic testcase looks like this: https://gist.github.com/loic/5899006.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20663#comment:16>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.6885055b25eaf1031cf4efaa43f7bfd4%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to