Skip to content

Commit

Permalink
Try removing timezone and trailing second decimals when parsing czi a…
Browse files Browse the repository at this point in the history
…quisition datetime
  • Loading branch information
erikogabrielsson committed Nov 6, 2024
1 parent 453430f commit 909775e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Parsing of aquisition datetime for czi-files with zone designation with Python <3.11.

## [0.15.0] - 2024-10-21

### Added
Expand Down
8 changes: 7 additions & 1 deletion wsidicomizer/sources/czi/czi_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Metadata for czi file."""

import re
from datetime import datetime
from functools import cached_property
from typing import List, Optional, Sequence, Tuple, Type, TypeVar
Expand Down Expand Up @@ -56,7 +57,12 @@ def aquisition_datetime(self) -> Optional[datetime]:
str,
nested=["Metadata", "Information", "Image"],
)
return datetime.fromisoformat(value)
try:
return datetime.fromisoformat(value)
except ValueError:
# Remove timezone and keep only microseconds for Python <3.11 compatibility
value = re.split(r"Z|[-|+]\d{2}.\d{2}$", value)[0][:26]
return datetime.fromisoformat(value)

@property
def scanner_model(self) -> Optional[str]:
Expand Down

0 comments on commit 909775e

Please sign in to comment.