Skip to content
This repository has been archived by the owner on Apr 29, 2023. It is now read-only.

TypeError: can't compare offset-naive and offset-aware datetimes #108

Open
sherpya opened this issue Feb 11, 2019 · 3 comments
Open

TypeError: can't compare offset-naive and offset-aware datetimes #108

sherpya opened this issue Feb 11, 2019 · 3 comments
Labels
Milestone

Comments

@sherpya
Copy link

sherpya commented Feb 11, 2019

I have a type:

  <xs:simpleType name="DataFatturaType">
    <xs:restriction base="xs:date">
      <xs:minInclusive value="1970-01-01" />
    </xs:restriction>
  </xs:simpleType>

if the date in the xml I want to check has timezone the comparison fails (I had to raise the real error because it is being masked).

The date is 2019-01-11+01:00 and yes I known a date only with a timezone is pointless but iso8601 allows it, and someone apparently uses it, it would be better to strip timezone if date only

@pabigot pabigot added the bug label Feb 11, 2019
@pabigot pabigot added this to the PyXB-1.2.7 milestone Feb 11, 2019
@pabigot
Copy link
Owner

pabigot commented Feb 12, 2019

As best I can tell PyXB correctly supports timezones for xsd:date instances and provides it through xsdRecoverableTzinfo.

Offhand it looks like this is a bug, but due to #100 this probably isn't going to get worked. It's slightly more likely to happen if you can attach a standalone test case to this issue.

It might also be related to the comparison value not having a timezone. One potential quick fix would be to use 1970-01-01Z. Dunno if it'd work, or if it'd just break comparison when there isn't a timezone, but it's worth a try.

@sherpya
Copy link
Author

sherpya commented Feb 12, 2019

unfortunately using timezone aware constraint will fail comparison with non timezone aware values in xml, but since timezone in date only is pointless even for comparison, I suppose you can just drop the tzinfo value in the offset

@sherpya
Copy link
Author

sherpya commented Feb 12, 2019

btw I can provide a testcase

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants