Opened 10 years ago

Closed 9 years ago

Last modified 5 years ago

#3378 closed Uncategorized (wontfix)

new template filter to convert datetime from utc to other timezone

Reported by: arvin Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords: timezone, utc
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I prefer to keep all datetime as UTC in the database as convert them during display.
Attached is a filter to perform this conversion. It assumes that the input datetime
is in UTC. Unfortunately value.tzinfo is not set originally. But I'm not into DB
stuff so I don't know how to change that.

Attachments (2)

astimezone.py (755 bytes) - added by arvin 10 years ago.
datetime convert filter
astimezone.2.py (834 bytes) - added by arvin 10 years ago.
filter to convert between timezones

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by arvin

Attachment: astimezone.py added

datetime convert filter

comment:1 Changed 10 years ago by arvin

A better patch can convert from the TIME_ZONE setting to anther timezone (attached).

But as I've seen in the meantime at least Postgresql can do timezone conversions so
a much better solution would be to simply retrieve the datetime from the database in
the desired timezone. I suppose that would require a timezone setting per session/user
which I'm not up to.

Changed 10 years ago by arvin

Attachment: astimezone.2.py added

filter to convert between timezones

comment:2 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Component: UncategorizedTemplate system
Needs documentation: set
Needs tests: set
Owner: changed from Jacob to Adrian Holovaty
Summary: new filter to convert datetime from utc to other timezonenew template filter to convert datetime from utc to other timezone
Triage Stage: UnreviewedDesign decision needed

comment:3 in reply to:  1 Changed 10 years ago by enlight

Replying to arvin:

But as I've seen in the meantime at least Postgresql can do timezone conversions so
a much better solution would be to simply retrieve the datetime from the database in
the desired timezone.

I'm not sure if letting the db do the timezone conversion is necessarily better, it'll be less flexible for sure. A filter seems to me like the best way to go about this.

comment:4 Changed 9 years ago by Jacob

Resolution: wontfix
Status: newclosed

This type of conversion ought to be done at the view level, not in a template tag.

comment:5 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

This should be resolved by #2626.

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