#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): Replying to [comment:3 jdufresne]: > I don't think this is about naive vs aware, but about accuracy. I would say that it's mostly a matter of providing a complete, but not redundant or overwhelming set of date/time/zones related APIs. > If a server's time zone is different than `settings.TIME_ZONE`, then it is important to be able to answer the question "what is today in the the timezone of `settings.TIME_ZONE`?" accurately. Actually the server's time zone doesn't matter for Django on Unix/Linux because Django sets the process' time zone to the value defined by `TIME_ZONE`, and that's the default time zone for the application. There are two cases where the server's time zone matters: - on Windows, it must match `TIME_ZONE` because Windows doesn't support setting a process' time zone - if `TIME_ZONE = None`, Django uses the server time zone > Near midnight different time zones will have different values for "today". Yes, I guess that's the reason why Baptiste filed this ticket. > I have the following two convenience functions in my application to help make this job easier. For my application, they are always preferred over `datetime.date.today()`, etc. They are heavily used. > > {{{ > def local_date(): > return timezone.localtime(timezone.now()).date() > > > def local_time(): > return timezone.localtime(timezone.now()).time() > }}} Since `django.utils.timezone.localtime` is currently used to convert an aware datetime to a specific time zone, we have a bit of a naming problem here, but I'm +0 for adding the first of these two functions (under a name to be defined). I'm not +1 because I believe that it's hard to get that kind of code right if you don't understand what you're doing, and writing these two one- liners is a good way to make sure the developer knows what's going on. -- Ticket URL: <https://code.djangoproject.com/ticket/27082#comment:7> 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.a5be2bc9540d58a7c4d19219a4d4572f%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.