ABF1: read 2-digit-year (YYMMDD) acquisition dates correctly#1872
ABF1: read 2-digit-year (YYMMDD) acquisition dates correctly#1872h-mayorquin wants to merge 4 commits into
Conversation
zm711
left a comment
There was a problem hiding this comment.
Just one question @h-mayorquin
| # - older files use YYMMDD (2-digit year), e.g. 180618 -> 2018-06-18 | ||
| # Detect the old form from the value rather than the version number (whose exact cutoff we | ||
| # cannot pin down): a real 4-digit year is >= 1000, so a year field below 100 is a 2-digit | ||
| # year. We assume such years are in the 2000s, as no ABF recording predates 2000. |
There was a problem hiding this comment.
How do we know this is true?
There was a problem hiding this comment.
The assumption you mean?
There was a problem hiding this comment.
Yeah exactly the assumption of only after 2000.
There was a problem hiding this comment.
Thanks for making me check this. I was basing that on the heuristic that the ABF acquisition system came after this, but it seems there are recordings in the 90s so that goes out the window. The heuristic is wrong.
So I dropped the century assumption entirely and disambiguate with the one hard invariant we do have: a recording cannot be in the future. A 2-digit year is mapped to the 2000s, and only falls back to the 1900s if that would land past the current year:
if year_is_two_digit:
year += 2000
if year > datetime.datetime.now().year:
year -= 100 # e.g. 98 -> 1998 rather than a not-yet-happened 2098That gives:
180618 -> 2018-06-18(the fixture; still passes)980618 -> 1998-06-18(a real 90s file now dates correctly instead of 2098)20050611 -> 2005-06-11(4-digit path unchanged)
Worth noting the 2-digit form is not a "this recording is old" signal: the test fixture is a 2018 recording that still emits YYMMDD, so it is a software/version quirk rather than an era marker. And since Axon didn't exist before the 1990s, every 2-digit year that can appear in a real file resolves unambiguously under this rule. Until we get to 2090 or something like that :P
I found another bug @zm711
PR #1870 started reading the real acquisition date from
lFileStartDatein ABF (Axon Binary Format) version 1 files, assuming that field is always packed as YYYYMMDD but older ABF version 1 files pack it as YYMMDD with a 2-digit year instead, so a file storing180618came back as year 18 rather than 2018-06-18. This handles both packings.