PIC-IRIS / PH5

Library of PH5 clients, apis, and utilities
Other
15 stars 9 forks source link

[BUG] ph5tostationxml outputs stationxml that is does not comply with the stationxml xsd schema #432

Closed timronan closed 3 years ago

timronan commented 3 years ago

Describe the bug Ph5tostationxml outputs stationxml that is does not comply with the stationxml xsd schema.

Specifically the field :

2020-10-08 21:58:09.039103

Is formatted incorrectly.

It should at least have a T inbetween the day and hour, similar to:

2020-10-08T21:58:09.039103

This bug can be quickly addressed by changing the format created=datetime.now() on line 955 clients.ph5tostationxml to created=datetime.now().isoformat(sep='T') or created=datetime.now().strftime('%Y-%m-%dT%H:%M:%S')

Environment (please complete the following information):

To Reproduce Steps to reproduce the behavior: run ph5tostationxml run the output stationxml document through the validator. Expected behavior Output stationxml doucment should pass validation.

Additional context Issue started to occur after updating obspy. We should be explicit with our date times so we don't run into this issue.

nick-falco commented 3 years ago

@timronan I think the correct date string format should be:

'%Y-%m-%dT%H:%M:%S.%f'

Note the .%f at the end of the date string.

>>> from datetime import datetime
>>> created = datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')
>>> print (created)
2020-10-09T11:47:25.525567
timronan commented 3 years ago

@nick-falco thanks for the catch.

nick-falco commented 3 years ago

Actually it may be better to use the Obspy UTCDateTime class instead and also put a "Z" at the end of the format string. I think the times should be in UTC.

ascire-pic commented 3 years ago

@timronan Are you planning to work on this issue?

timronan commented 3 years ago

@ascire-pic I can fix this issue but I need to finish all of my outstanding projects before I start on this one. There may be a delay before I can work on this patch.

ascire-pic commented 3 years ago

Sounds good! Was looking through the open issues and just wanted to check.

gbbofh commented 3 years ago

@timronan I can start on a pull request to fix this if you haven't started working on it yet.

timronan commented 3 years ago

@gbbofh please start this PR if you have time. I will likely be able to get to it next week if it is not done before. The fix seems to be outlined in this issue.

gbbofh commented 3 years ago

@timronan I should have a PR fixing this issue up later today.

timronan commented 3 years ago

@gbbofh sounds good. I will review the PR when it is posted.