datetime-fortran icon indicating copy to clipboard operation
datetime-fortran copied to clipboard

strptime does not handle errors

Open dongli opened this issue 6 years ago • 1 comments

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

dongli avatar Oct 04 '17 08:10 dongli

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?

scivision avatar Dec 17 '20 16:12 scivision