Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submission publish_date doesn't consider dst #274

Open
woodz- opened this issue Mar 15, 2019 · 4 comments
Open

submission publish_date doesn't consider dst #274

woodz- opened this issue Mar 15, 2019 · 4 comments

Comments

@woodz-
Copy link

woodz- commented Mar 15, 2019

Hi,
I am on UTC+1 (MEZ) timezone. I was filing a test nsl between 00:00 and 01:00 am. During this period of time the day of the archive url was 1 day past the day of the Submission object.
The dst calculation seems to be correct (this time without dst, winter time +00:00):
2019-03-15 00:00:14+00:00
But the hour is too low by 1 and thus the day gets also too low by one during 00:00 and 01:00 am.
The timestamp given should read as: 2019-03-15 01:00:14+00:00

Curios because the day gets calculated from the model's get_absolute_url(self) method of the Submission object, which uses:

publish_date = models.DateTimeField( verbose_name=_('publication date'), blank=True, null=True, default=now, db_index=True )

The archive template makes use of this method and the Submission object holds it.
So from where do we get the deviation of 1 day for 1 hour?

@dokterbob
Copy link
Collaborator

dokterbob commented Mar 15, 2019 via email

@woodz-
Copy link
Author

woodz- commented Mar 15, 2019

Can we be sure, that everything to and from the DB is handled as UTC? I found one place where the timezone is requested from settings and a python datetime object gets mixed in:

def _make_date_lookup_arg(self, value):
"""
Convert a date into a datetime when the date field is a DateTimeField.

When time zone support is enabled,date is assumed to be in the
default time zone, so that displayed items are consistent with the URL.

Related discussion:
https://github.com/dokterbob/django-newsletter/issues/74
"""
value = datetime.datetime.combine(value, datetime.time.min)
if settings.USE_TZ:
value = timezone.make_aware(value, timezone.get_default_timezone())
return value

but I could not find, where this method gets called. Can someone give a hand here? Does it hang around idle? Probably related: #74

@dokterbob
Copy link
Collaborator

dokterbob commented Mar 15, 2019 via email

@woodz-
Copy link
Author

woodz- commented Mar 15, 2019

Yes, most changes are for newsletter/tests/test_web.py and the method _make_date_lookup_arg came in with that issue (in views.py). But no call from anywhere as I can see. From where should it be called?
In respect to the comment: Convert a date into a datetime when the date field is a DateTimeField
it sounds this method shall be made a kind of a property and be a wrapper for DateTimeField of django model.
For me it's still hard to believe that DateTimeField isn't able to handle all that stuff by itself. It should be UTC compliant and if USE_TZ is set in settings, everything should run. Otherwise any django application would need such a hand made wrapping if it makes use of DateTimeField(s) in the model. Is it serious?
looking onto the linked issue more specific: which inherits from DateDetailView. DateDetailView is a django built in, so one can fulminate a django bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants