Re: strptime() fails to recognize negative hours

theozh <[email protected]>
Newsgroups gmane.comp.graphics.gnuplot.user
Message-ID <[email protected]>
a suggestion for a possible workaround (still to be optimized for all possible cases):

### handling negative times
$Data <<EOD
1   00:01:00
2  -00:01:00
EOD

myTimeFmt = "%tH:%tM:%tS"

myTimeSigned(fmt,s) = s[1:1] eq '-' && strptime("%tH",s)==0 && strptime(fmt,s)>0 ? \
                      -strptime(fmt,s[2:]) : strptime(fmt,s)

myTime(n,fmt) = myTimeSigned(fmt,strcol(n))

set table $Test
    plot $Data u 1:(myTime(2,myTimeFmt)) w table
unset table
print $Test
### end of code

Result:
1   60
2  -60

see more details:     https://stackoverflow.com/a/61005915/7295599

Theo.


_______________________________________________
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.