gmggroup / omf-python

Python library for working with OMF files
MIT License
79 stars 20 forks source link

DateTimeData can't make a round trip? #127

Open WesleyTheGeolien opened 1 year ago

WesleyTheGeolien commented 1 year ago

I tried creating a "basic" datetime object to serialize and deserialize in omf v1.0.1 (see example below). The object is written to disk without issue however upon deserialization I get a ValueError (ValueError: time data '1-01-01T00:00:00Z' does not match format '%Y-%m-%dT%H:%M:%SZ')

Looking at the technical details here it looks like in some cases only years > 1000 should / could be accepted. I agree the %Y should be zero padding according to the docs but it doesn't look like it. This does look like a datetime bug? but maybe omf could / should be handling this?

eg. This does not work but probably should?

value = datetime.strftime(datetime(1,1,1), '%Y-%m-%dT%H:%M:%SZ')
datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')

My question are:

import datetime as dt
import omf

pts = omf.PointSetElement(
            name=f'Points',
            geometry=omf.PointSetGeometry(
                vertices=np.array([0,0,0])
            ),
            data=[
                omf.DateTimeData(
                    array=[dt.datetime(1,1,1)],
                    location='vertices'
                ),
            ],
        )

proj = omf.Project()
proj.elements = [pts]

omf.OMFWriter(proj, "test.omf")

reader = omf.OMFReader("test.omf")
reader.get_project()

OS: Pop-os! (Ubuntu 22.02 derived) Python: 3.10 omf: 1.0.1