Skip to content

Commit

Permalink
Convert DOB from datetime object to string
Browse files Browse the repository at this point in the history
  • Loading branch information
edeno committed Apr 28, 2023
1 parent 530a901 commit 356d4ef
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions rec_to_nwb/processing/metadata/metadata_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@


class MetadataExtractor:

@staticmethod
def extract_metadata(metadata_path):
with open(metadata_path, 'r') as stream:
return json.loads(
json.dumps(yaml.safe_load(stream)),
parse_int=str,
parse_float=str)
with open(metadata_path, "r") as stream:
yaml_dict = yaml.safe_load(stream)

# yaml automatically converts date_of_birth to a datetime object, need to convert back
yaml_dict["subject"]["date_of_birth"] = yaml_dict["subject"][
"date_of_birth"
].strftime("%Y-%m-%dT%H:%M:%S.%fZ")

# for some reason they want to convert all ints, float to strings
return json.loads(json.dumps(yaml_dict), parse_int=str, parse_float=str)

0 comments on commit 356d4ef

Please sign in to comment.