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

Change datetime fields to date fields in BagInfoMetadata model #636

Merged
merged 7 commits into from Nov 8, 2023

Conversation

helrond
Copy link
Member

@helrond helrond commented Nov 2, 2023

This PR is from @McDaPick for Issue #506

After updating the date_start and date_end fields in the BagInfoMetadata model from

date_start = models.DateTimeField()
date_end = models.DateTimeField()

to

date_start = models.DateField()
date_end = models.DateField()

and running a migration, the date was being saved as one day earlier than what was in the bag-info file.

Transfer's Bag Info:

External Identifier: records-2017-12-11T20:09:48.238148
BagIt-Profile-Identifier: http://localhost:8000/api/bagit_profiles/2/
Bagging-Date: 2017-12-11T20:09:48.238148
Date-End: 2005-06-22
Date-Start: 2003-05-14

The Transfer's data through the Django shell after being imported:

>>> from bag_transfer.models import BagInfoMetadata
>>> x = BagInfoMetadata.objects.get(external_identifier="records-2017-12-11T20:09:48.238148")
>>> print(x.date_end)
2005-06-21
>>> print(x.date_start)
2003-05-13

Inside of the Transfer's detail view:

image

After reading @helrond comment about timezone/daylight, I started to take a look around and saw that config.py has the time zone set as America/New_York on line 15.

DJANGO_TIME_ZONE = "America/New_York"  # TZ database name for local timezone (string)

Updating this value to UTC allowed for the date_field to save correctly.

DJANGO_TIME_ZONE = "UTC"  # TZ database name for local timezone (string)

Transfer's Bag Info:

External Identifier: records-2017-12-11T20:09:48.238148
BagIt-Profile-Identifier: http://localhost:8000/api/bagit_profiles/2/
Bagging-Date: 2017-12-11T20:09:48.238148
Date-End: 2005-06-22
Date-Start: 2003-05-14

The Transfer's data through the Django shell after DJANGO_TIME_ZONE was updated:

>>> from bag_transfer.models import BagInfoMetadata
>>> x = BagInfoMetadata.objects.get(external_identifier="records-2017-12-11T20:09:48.238148")
>>> print(x.date_end)
2005-06-22
>>> print(x.date_start)
2003-05-14

Inside of the Transfer's detail view:

image

Side Note:

This update to the DJANGO_TIME_ZONE also seems to fix the bagging_date time being fives hours off of its value in bag-data.

@helrond
Copy link
Member Author

helrond commented Nov 2, 2023

OK @McDaPick I had to do a few additional things to get this to pass CI:

  • Merged to a branch on this repo so we can pick up the Docker credentials
  • Added a migration (needed whenever you change a database field)
  • Remove the timezone from the base fixture

If you're good with this I can push this through development and into base.

@McDaPick
Copy link
Contributor

McDaPick commented Nov 4, 2023

Hi @helrond !

Thank you so much, that sounds great to me. I'll make a note of the updates you made for the future.

Let me know if I can lend a hand anywhere else!

@helrond helrond merged commit 8726e6b into development Nov 8, 2023
2 checks passed
@helrond helrond deleted the issue-506 branch November 8, 2023 19:01
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

2 participants