question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

datetime field localtime() issue

See original GitHub issue

Describe the bug Django DateTime Import

To Reproduce Import DateTime data and you’ll hit a “localtime() cannot be applied to a naive datetime”, I’ve been using the package for a while now and use the admin import page as well as a custom import page for users. Both work fine for non-datetime data.

I’ve tried this with adding with tz +00 and without 2020-07-17 7:42:39 2020-07-17 7:42:39+00

I’ve tried the DateTimeWidget where format=“%Y-%m-%d %H:%M:%S” format=“%Y-%m-%d %H:%M:%S$z” format=None

I’ve posted a SOF question regarding it https://stackoverflow.com/questions/62990575/django-import-export-datetime-naive-datetime-error

And had a convo specific to it on SOF https://chat.stackoverflow.com/rooms/218260/django-import-export

The end result seems that the issue may be in the django-import-export package.

Versions (please complete the following information):

  • django-import-export==2.2.0
  • Python 3.7.4
  • Django==3.0.2

settings.py

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

Expected behavior I was expecting the datetime to import the dates in my csv file

Screenshots View 2 links above

Additional context View 2 links above

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:21 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
matthewhegartycommented, Jul 22, 2020

Alex and I discussed this on SO chat. The issue seemed to be that when a naive datetime was imported via the Admin console, then it couldn’t be displayed because the render() method in DateTimeWidget couldn’t handle a naive datetime. However I couldn’t reproduce this issue. I’ll do some more research, but my current thinking is that it is not a bug.

0reactions
matthewhegartycommented, Sep 2, 2022

Closing again - does not affect DateWidget because it has no TZ information.

For applications requiring aware objects, datetime and time objects have an optional time zone information attribute, tzinfo, that can be set to an instance of a subclass of the abstract tzinfo class. These tzinfo objects capture information about the offset from UTC time, the time zone name, and whether daylight saving time is in effect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DateTimeField: how to retrieve date/time in my local time
1 Answer 1 ... As far as I know Django uses serializers to transform datetime fields. In this case you use the (db)...
Read more >
Date and Time Field Displayed in Local Time Instead of UTC
Issue. Date and time fields are displayed in local or system time, instead of UTC. Environment. Tableau Desktop; Tableau Server ...
Read more >
<input type="datetime-local"> - HTML - MDN Web Docs
The problem is with the client side of things: parsing of dates with more than 4 digits in the year. <!--midnight of January...
Read more >
Date/time field displaying GMT vs. local date/time - ServiceNow
Solved: A newly created Date/Time field defaulting to an existing Date/Time field displays GMT vs. local time zone.
Read more >
visualforce - Timezone issue with Datetime Field [again
timeValue').children().each(function(){ var currentText ... hour: Returns the hour component of a Datetime in the local time zone of the context user
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found