Opened 3 years ago

Closed 2 years ago

Last modified 20 months ago

#18768 closed New feature (needsinfo)

Timezone documentation lacks some FAQ about how to deal with naive/tz aware datetimes in the Javascript

Reported by: void Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords: timezone, tz
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Timezone documentation provide information about rendering naive and timezone aware datetimes in templates, but lacks some information about working with javascript.
It would be cool if docs answered on questions like:

  • Are javascript Date() objects naive or locale-aware?
  • How is timezone conversion may be done with javascript?
  • How should I populate javascript variable from django template? Is
    {% language "en" %}
    var mydatetime = new Date('{{ mydatetime|date:"r" }}');
    {% endlanguage %}
    

ok or not?

  • What about JSON serialized datetimes? Will they be in the correct timezone automagically? What is a "correct" timezone – client's or server's?

Change History (7)

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I'm the maintainer of time zone support in Django. As far as I can tell there is some level of time zone awareness in Javascript (getTimezoneOffset). In addition you may be using a library such as jskata.timezone.js. This choice of tools is indpendent of Django.

In my opinion, this request is outside of the scope of Django. As a Python web framework, it provides some tools to generate HTML, but it doesn't delve into the JS and CSS land.

If this ticket was accepted, someone else will have to step up and provide a patch, as I don't have the knowledge required to document, recommend or endorse Javascript coding practices.

comment:2 Changed 3 years ago by void

Django does not delve into javascript very deep, but it does: at least it provide some helpers like js catalogue of translated messages. Probably questions are a bit outside of the scope, but maybe documentation can link then to some good source of information about Javascript timezones and django/js interaction in the field of datetimes/timezones?

comment:3 Changed 3 years ago by aaugustin

Can you provide a patch?

comment:4 Changed 3 years ago by void

Probably, but not very soon: I'm not the javascript guru and have to understand the domain for myself first.

comment:5 Changed 2 years ago by timo

  • Resolution set to needsinfo
  • Status changed from new to closed

@void, if you would like to provide a patch at some point, please reopen, thanks!

comment:6 Changed 20 months ago by aaugustin

I've been investigating support for time-zones JavaScript in the context of #20663 and the key points are:

  • JavaScript doesn't have any support for time zones whatsoever, and even its Date API is... err... well, JavaScript would be better if it didn't exist at all (0-indexed months, WTF?)
  • third party libraries are definitely the way to go.

comment:7 Changed 20 months ago by Aymeric Augustin <aymeric.augustin@…>

In 7e6d852bac4de2d5ed2d5ddeabf71482d644ef51:

Fixed #20663 -- "Today" and "now" admin shortcuts.

Changed the shortcuts next to date and time intput widgets
to account for the current timezone.

Refs #7717, #14253 and #18768.

Note: See TracTickets for help on using tickets.
Back to Top