Re: strptime() fails to recognize negative hours

Hans-Bernhard Bröker <[email protected]>
Newsgroups gmane.comp.graphics.gnuplot.user
Message-ID <[email protected]>
Am 02.04.2020 um 17:33 schrieb Sergei Naumov via gnuplot-info:

> gnuplot> myTimeFmt = "%tH:%tM:%tS"
> gnuplot> print strptime(myTimeFmt,"-00:24:25.3")
> 1465.3
> gnuplot> print strptime(myTimeFmt,"00:-24:25.3")
> -1465.3
> gnuplot>
> 
> Is there a bug or it should work like this? 

A little bit of both, I'd say: %tH does work, but not for a value of 
minus _zero_ hours.

 From a user point-of-view that's a bug, but I see how it might be 
tricky to get the implementation to do what this wants to achieve, given 
that plus zero and minus zero are somewhat hard to distinguish.

> gnuplot> print strptime(myTimeFmt,"01:02:03.4")  
> 3723.4
> gnuplot> print strptime(myTimeFmt,"-01:02:03.4")  
> -3723.4

So the sign of the hours field extends over to the minutes and seconds.

I'll assume (although the documentation doesn't say so) that this was 
meant to work like that.

> gnuplot> print strptime(myTimeFmt,"-01:-02:03.4")  
> -3723.4
> gnuplot> print strptime(myTimeFmt,"-01:+02:03.4")  
> -3723.4

Hmm, so there's no way to flip the minutes back to positive once the 
hours are negative.  That IMHO casts doubt on the whole idea of 
inheriting the sign from one field to the other (not to mention what 
might happen if some devious mind decided to use these fields in reverse 
order, i.e. "%tS:%tM:%tH").

> gnuplot> print strptime(myTimeFmt,"01:-02:03.4")  
> 3483.4

But if you start with positive hours, the minutes alone can be negative, 
while the seconds still default to positive.  The seconds can be 
negative all by themselves, though:

> gnuplot> print strptime(myTimeFmt,"01:02:-03.4")  
> 3716.6



_______________________________________________
gnuplot-info mailing list
[email protected]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.