Skip to content
Snippets Groups Projects
Commit 42c4d463 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Always create creationTime & updateTime, default to Unix epoch

parent a1af9eb1
No related branches found
No related tags found
1 merge request!937DataFile: Don't write creationDate & updateDate unless specified
This commit is part of merge request !937. Comments created here will be created in the context of that merge request.
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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment