diff --git a/src/MCPClient/lib/clientScripts/store_file_modification_dates.py b/src/MCPClient/lib/clientScripts/store_file_modification_dates.py index 581b44b2af..0dab5ad6d9 100755 --- a/src/MCPClient/lib/clientScripts/store_file_modification_dates.py +++ b/src/MCPClient/lib/clientScripts/store_file_modification_dates.py @@ -21,22 +21,20 @@ import django django.setup() -# archivematicaCommon from custom_handlers import get_script_logger from django.db import transaction - -# dashboard +from django.utils.timezone import get_current_timezone from main import models logger = get_script_logger("archivematica.mcp.client.storeFileModificationDates") -def get_modification_date(file_path): +def get_modification_date(file_path, timezone): mod_time = os.path.getmtime(file_path) - return datetime.datetime.utcfromtimestamp(int(mod_time)) + return datetime.datetime.fromtimestamp(int(mod_time), tz=timezone) -def main(transfer_uuid, shared_directory_path): +def main(transfer_uuid, shared_directory_path, timezone): transfer = models.Transfer.objects.get(uuid=transfer_uuid) files = models.File.objects.filter(transfer=transfer) @@ -57,7 +55,7 @@ def main(transfer_uuid, shared_directory_path): file_path = file_path_relative_to_shared_directory.replace( "%sharedPath%", shared_directory_path, 1 ) - transfer_file.modificationtime = get_modification_date(file_path) + transfer_file.modificationtime = get_modification_date(file_path, timezone) transfer_file.save() mods_stored += 1 @@ -65,10 +63,11 @@ def main(transfer_uuid, shared_directory_path): def call(jobs): + timezone = get_current_timezone() with transaction.atomic(): for job in jobs: with job.JobContext(logger=logger): transfer_uuid = job.args[1] shared_directory_path = job.args[2] - main(transfer_uuid, shared_directory_path) + main(transfer_uuid, shared_directory_path, timezone) job.set_status(0) diff --git a/tests/MCPClient/test_store_file_modification.py b/tests/MCPClient/test_store_file_modification.py index bb27e9cc3d..f6639e7f14 100644 --- a/tests/MCPClient/test_store_file_modification.py +++ b/tests/MCPClient/test_store_file_modification.py @@ -4,6 +4,8 @@ import store_file_modification_dates from django.test import TestCase +from django.test import override_settings +from django.utils.timezone import get_current_timezone from main import models THIS_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -25,6 +27,7 @@ def tearDown(self): ) shutil.rmtree(transfer_path) + @override_settings(TIME_ZONE="US/Eastern") def test_store_file_modification_dates(self): """Test store_file_modification_dates. @@ -47,19 +50,22 @@ def test_store_file_modification_dates(self): os.makedirs(dirname) with open(path, "wb") as f: f.write(path.encode("utf8")) - os.utime(path, (1339485682, 1339485682)) + os.utime(path, (1049597970, 1049597970)) # Store file modification dates - store_file_modification_dates.main(self.transfer_uuid, self.temp_dir + "/") + store_file_modification_dates.main( + self.transfer_uuid, self.temp_dir + "/", get_current_timezone() + ) # Assert files have expected modification times + expected_time = "2003-04-06 02:59:30+00:00" assert ( str( models.File.objects.get( pk="47813453-6872-442b-9d65-6515be3c5aa1" ).modificationtime ) - == "2012-06-12 07:21:22+00:00" + == expected_time ) assert ( str( @@ -67,7 +73,7 @@ def test_store_file_modification_dates(self): pk="60e5c61b-14ef-4e92-89ec-9b9201e68adb" ).modificationtime ) - == "2012-06-12 07:21:22+00:00" + == expected_time ) assert ( str( @@ -75,7 +81,7 @@ def test_store_file_modification_dates(self): pk="791e07ea-ad44-4315-b55b-44ec771e95cf" ).modificationtime ) - == "2012-06-12 07:21:22+00:00" + == expected_time ) assert ( str( @@ -83,5 +89,5 @@ def test_store_file_modification_dates(self): pk="8a1f0b59-cf94-47ef-8078-647b77c8a147" ).modificationtime ) - == "2012-06-12 07:21:22+00:00" + == expected_time )