Dates, when read in from IVY are coming across as EST, and they must be ingested as such.

This commit is contained in:
Dan 2021-02-02 14:59:24 -05:00
parent 6a43e6f5eb
commit 4c4ecfe245
2 changed files with 23 additions and 0 deletions

View File

@ -3,6 +3,7 @@ from datetime import datetime
from parser import ParserError
import globus_sdk
import pytz
import sentry_sdk
from dateutil import parser
@ -70,6 +71,8 @@ class IvyService(object):
try:
try:
sample.date = parser.parse(dictionary["Test Date Time"])
tz = pytz.timezone("America/New_York")
sample.date = tz.localize(sample.date)
except Exception as pe:
sentry_sdk.capture_message(f"Failed to parse date for barcode '{dictionary['Test Bar Code']}', '{pe}'")
sample.date = datetime.now()

View File

@ -1,3 +1,7 @@
import datetime
import pytz
from tests.base_test import BaseTest
import os
import unittest
@ -31,6 +35,22 @@ class IvyServiceTest(BaseTest):
self.assertEquals(4, len(records))
self.assertEquals('987655321-TN-20212719-4321', records[2].barcode)
def test_timezone_offset(self):
"""The date and time returned from the lab / Globus is in EST, be sure to save it as such to
avoid a 5 hour offset, when it is assumed to be in GMT."""
records = IvyService.samples_from_ivy_file(self.ivy_file)
self.assertEqual("987654321", records[0].student_id)
self.assertIsNotNone(records[0].date.tzinfo, "on ingestion, the date should be in EST")
# original date "202009030809"
date_string = '202009031209' # UTC is 4 hours head for this date
date = datetime.datetime.strptime(date_string, '%Y%m%d%H%M')
db.session.add(records[0])
db.session.commit()
self.assertEqual(date, records[0].date)
def test_load_directory(self):
self.assertEqual(0, db.session.query(IvyFile).count())
app.config['IVY_IMPORT_DIR'] = os.path.join(app.root_path, '..', 'tests', 'data', 'import_directory')