#17992: Public API for localtime
-------------------------------------+-------------------------------------
     Reporter:  Bradley Ayers        |                    Owner:  nobody
  <bradley.ayers@…>                  |                   Status:  new
         Type:  New feature          |                  Version:  1.4
    Component:  Core (Other)         |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:  timezone localtime   |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Description changed by aaugustin:

Old description:

> I think there should be a public API for converting timezone aware
> datetime objects to current timezone versions. This actually existed in
> django.utils.timezone as localtime, but was made private and removed from
> the documentation in https://code.djangoproject.com/changeset/17642
>
> The current options for converting a datetime to the current timezone
> are:
>
> 1. Use Python's datetime.astimezone in conjunction with
> django.utils.timezone helpers:
>
> {{{
> from django.utils import timezone
> local = dt.astimezone(timezone.get_current_timezone())
> }}}
>
> 2. Use the public API for the localtime template filter via the privatish
> module django.template.defaultfilters:
>
> {{{
> from django.template.defaultfilters import localtime
> local = localtime(dt)
> }}}
>
> While (2) is much cleaner, I'd argue it's dirty to import from
> defaultfilters.
>
> I propose re-publicising django.utils.timezone.localtime as a public API.
>
> My use-case is generating PDFs that have datetimes in their content.

New description:

 I think there should be a public API for converting timezone aware
 datetime objects to current timezone versions. This actually existed in
 django.utils.timezone as localtime, but was made private and removed from
 the documentation in https://code.djangoproject.com/changeset/17642

 The current options for converting a datetime to the current timezone are:

 1. Use Python's datetime.astimezone in conjunction with
 django.utils.timezone helpers:

 {{{
 from django.utils import timezone
 local = dt.astimezone(timezone.get_current_timezone())
 }}}

 2. Use the public API for the localtime template filter via the privatish
 module django.template.defaultfilters:

 {{{
 from django.templatetags.tz import localtime
 local = localtime(dt)
 }}}

 While (2) is much cleaner, I'd argue it's dirty to import from
 defaultfilters.

 I propose re-publicising django.utils.timezone.localtime as a public API.

 My use-case is generating PDFs that have datetimes in their content.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17992#comment:3>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to