wavebitscientific / datetime-fortran

Date and time manipulation for modern Fortran
MIT License
137 stars 51 forks source link

strptime does not handle errors #47

Closed dongli closed 1 year ago

dongli commented 7 years ago

When I fed strptime with a wrong time string, it just returns a normal result, but I expect an error report:

type(datetime) time

time = strptime('', '%Y-%m-%dT%H:%M:%SZ')
print *, time%isoformat()

=> 1900-01-00T00:00:00.000

time = strptime('XXX', '%Y-%m-%dT%H:%M:%SZ')
print *, time%isoformat()

=> 1900-01-00T00:00:00.000

time = strptime('2017-01-0 15:30:00Z', '%Y-%m-%dT%H:%M:%SZ')
print *, time%isoformat()

=> 2017-01-00T00:00:00.000

...

Maybe it could set some field of datetime to indicate an invalid status? Say:

time = strptime('XXX', '%Y-%m-%dT%H:%M:%SZ')
if (time%invalid) then
  ...
end if
scivision commented 3 years ago

Yes. I at least added a warning to strftime. Would be want datetime-fortran to "error stop" or just emit a stderr warning for strftime and strptime failures?