#27082: Make timezone.localtime() default to timezone.now() when no value is given -----------------------------+-------------------------------------- Reporter: bmispelon | Owner: nobody Type: New feature | Status: new Component: Utilities | Version: 1.10 Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -----------------------------+--------------------------------------
Comment (by aaugustin): Ah you're right. `datetime.date.today()` uses the default time zone, not the current time zone. (I'm saying "default time zone" to mean "the time zone defined by settings.TIME_ZONE", which may be different from the system time zone.) That's because Django calls `time.tzset(settings.TIME_ZONE)` on start up, but doesn't call `time.tzset` when changing the active time zone. So, yeah, `timezone.localtime(timezone.now()).date()` is the best you can do at this point. I think there's a ticket or a PR discussing `timezone.localdate(aware_datetime) -> date` somewhere. `timezone.localnow` has also been proposed in the past. I suppose we should add one or both. -- Ticket URL: <https://code.djangoproject.com/ticket/27082#comment:4> 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/067.133b8180b21bc8f747893ae8a9f847d5%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.