diff --git a/src/cal_tools/files.py b/src/cal_tools/files.py index edb73070ce2350eb8a29057586e6364a2b9d6e5e..91766f0662f436cfa975eb566478c091c7d73071 100644 --- a/src/cal_tools/files.py +++ b/src/cal_tools/files.py @@ -1,5 +1,5 @@ -from datetime import datetime +from datetime import datetime, timezone from itertools import chain from numbers import Integral from pathlib import Path @@ -310,14 +310,20 @@ class DataFile(h5py.File): if sequence is None: sequence = self.__sequence + if creation_date is None: + creation_date = datetime.fromtimestamp(0, tz=timezone.utc) + elif creation_date is True: + creation_date = datetime.now(timezone.utc) + if update_date is None: update_date = creation_date + elif update_date is True: + update_date = datetime.now(timezone.utc) md_group = self.require_group('METADATA') - if creation_date is not None: - md_group.create_dataset( - 'creationDate', shape=(1,), - data=creation_date.strftime('%Y%m%dT%H%M%SZ').encode('ascii')) + md_group.create_dataset( + 'creationDate', shape=(1,), + data=creation_date.strftime('%Y%m%dT%H%M%SZ').encode('ascii')) md_group.create_dataset('daqLibrary', shape=(1,), data=daq_library.encode('ascii')) md_group.create_dataset('dataFormatVersion', shape=(1,), data=b'1.2') @@ -358,10 +364,9 @@ class DataFile(h5py.File): 'runNumber', shape=(1,), dtype=np.uint32, data=run) md_group.create_dataset( 'sequenceNumber', shape=(1,), dtype=np.uint32, data=sequence) - if update_date is not None: - md_group.create_dataset( - 'updateDate', shape=(1,), - data=update_date.strftime('%Y%m%dT%H%M%SZ').encode('ascii')) + md_group.create_dataset( + 'updateDate', shape=(1,), + data=update_date.strftime('%Y%m%dT%H%M%SZ').encode('ascii')) class ControlSource(h5py.Group):