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

Fix minor date formatting issue for date with years < 1000 #1285

Conversation

matthewhegarty
Copy link
Contributor

Problem

There is a minor bug in DateWidget and DateTimeWidget where dates with years < 1000 are not formatted with 4 digits.
This is a minor issue but is a bug that may affect anyone exporting data with historic dates.

4 digit years are OK

>>> from import_export.widgets import DateWidget
>>> from datetime import date
>>> w = DateWidget()
>>> d = date(1000, 5, 3)
>>> w.render(d)
'1000-05-03'

<4 digit years don't render with leading zeroes

Before fix

>>> d = date(999, 5, 3)
>>> w.render(d)
'999-05-03'

After fix

>>> d = date(999, 5, 3)
>>> w.render(d)
'0999-05-03'

Solution

This PR fixes that by using the datetime_safe module in Django

There was an earlier fix to address dates before 1900, which was a previous issue in Django, however that fix did not address this bug. Also that fix applied only to DateWidget and not DateTimeWidget.

The original Django issue was updated once python2 was unsupported.

Acceptance Criteria

  • Added tests which cover this scenario
  • Improved widgets.py coverage to 100%

@matthewhegarty matthewhegarty changed the title fix minor date formatting issue for date with years < 1000 Fix minor date formatting issue for date with years < 1000 May 3, 2021
@coveralls
Copy link

coveralls commented May 3, 2021

Coverage Status

Coverage increased (+0.5%) to 97.849% when pulling 7826db9 on matthewhegarty:widget-handle-dates-before-1000 into bf4a51d on django-import-export:main.

Copy link
Member

@andrewgy8 andrewgy8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @matthewhegarty for the extra test coverage too!

@andrewgy8 andrewgy8 merged commit 4167a16 into django-import-export:main May 4, 2021
@matthewhegarty matthewhegarty deleted the widget-handle-dates-before-1000 branch August 9, 2021 09:21
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

Successfully merging this pull request may close these issues.

None yet

3 participants