Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

format : 0 pm vs 12 pm (bug?)

2 views
Skip to first unread message

Jason

unread,
Jan 27, 2005, 1:02:27 PM1/27/05
to
Is this a gnuplot bug?

I'm using this on an x-axis with time:
set format x "%l %p"

And I get "0 AM" (or "0 PM") where it should read "12 AM". In other
words, the %l token returns 0-11 instead of 1-12.

Since the Gnuplot docs mention that your system's strftime affects what
tags available, I'll mention that I'm using FreeBSD (4.8 branch) and
using strftime through perl directly doesn't have this bug, e.g.:

# perl
use POSIX 'strftime';
$now = time;
$now = $now - ($now % 43200); # round off to 12 hr interval
$formatted = strftime "TIME: %l %p", gmtime($now);
print "$formatted\n";
^D
TIME: 12 PM
#
And of course: gnuplot-4.0.0_2 (i.e. 4.0.0, FreeBSD port patchlevel 2).

Hans-Bernhard Broeker

unread,
Jan 28, 2005, 4:15:14 AM1/28/05
to
Jason <tha...@gmail.com> wrote:
> Is this a gnuplot bug?

> I'm using this on an x-axis with time:
> set format x "%l %p"

> And I get "0 AM" (or "0 PM") where it should read "12 AM". In other
> words, the %l token returns 0-11 instead of 1-12.

I must admit I felt badly tempted to just reply "what person in their
right mind would use this silly AM/PM stuff anyway..." ;-)

But yes, that may be a bug. The documentation says that %l prints
something in the range 0--12, when it actually never outputs 12.

The system strftime() almost certainly won't have anything to do with
it (the switch USE_SYSTEM_TIME is not set by any current build). The
code that actually gets used is gstrftime() in src/time.c

--
Hans-Bernhard Broeker (bro...@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Jason

unread,
Jan 28, 2005, 9:55:37 PM1/28/05
to
I understand your temptation: I believe that summary executions should
be in order for failing to specify a time zone. But lots of non-geeks
and non-military, particularly in English-speaking lands, I find, are
unfamiliar with 24-hour time. And Linux strftime, for example, has %P
to specify am or pm in addition to %p for AM or PM (which sounds crazy
and probably is). I guess there are a lot of crazy people :)

Anyway, looking at time.c, it looks like a one-line patch that even I
could do. Since no one that I'm aware of uses zero in 12-hour time,
I'll offer a patch as suggested in the FAQ.

Grant Edwards

unread,
Jan 28, 2005, 11:06:56 PM1/28/05
to
On 2005-01-27, Jason <tha...@gmail.com> wrote:
> Is this a gnuplot bug?
>
> I'm using this on an x-axis with time:
> set format x "%l %p"
>
> And I get "0 AM" (or "0 PM") where it should read "12 AM".

There is no "12 AM" or "12 PM". There is 12 Noon, and 12
Midnight.

--
Grant Edwards grante Yow! I just heard the
at SEVENTIES were over!! And
visi.com I was just getting in touch
with my LEISURE SUIT!!

Jason

unread,
Jan 28, 2005, 11:58:49 PM1/28/05
to
Think: 12 AM is midnight, and 12 PM is noon. On the 12-hr clock, there
is no "zero" hour! "0 PM" is wrong: the output of "%l %p" (also "%I
%p") should be 12 PM instead. strftime on *BSD and Linux cites ISO 9899
conformance, where %l is 1-12, not 0-11.

That's my mouth: here's my money (less linewrap garbling by gmail):

--- gnuplot-4.0.0/src/time.c.orig Fri Jan 28 23:43:13 2005
+++ gnuplot-4.0.0/src/time.c Fri Jan 28 23:53:05 2005
@@ -525,7 +525,7 @@
break;

case 'I':
- FORMAT_STRING(1, 2, tm->tm_hour % 12); /* %02d */
+ FORMAT_STRING(0, 2, (tm->tm_hour ? tm->tm_hour % 12 :
12)); /* %2d */
break;

case 'j':
@@ -538,7 +538,7 @@
break;

case 'l':
- FORMAT_STRING(0, 2, tm->tm_hour % 12); /* %2d */
+ FORMAT_STRING(0, 2, (tm->tm_hour ? tm->tm_hour % 12 :
12)); /* %2d */
break;

case 'm':

Jason

unread,
Jan 29, 2005, 12:27:38 AM1/29/05
to
OK, sorry, the previous patch only works for midnight. This one works
for 12 pm as well (and yes, there is a 12 pm and no 0 pm).
-------------------

--- gnuplot-4.0.0/src/time.c.orig Fri Jan 28 23:43:13 2005
+++ gnuplot-4.0.0/src/time.c Sat Jan 29 00:17:19 2005

@@ -525,7 +525,7 @@
break;

case 'I':
- FORMAT_STRING(1, 2, tm->tm_hour % 12); /* %02d */

+ FORMAT_STRING(0, 2, (tm->tm_hour % 12 ? tm->tm_hour %


12 : 12));/* %2d */
break;

case 'j':
@@ -538,7 +538,7 @@
break;

case 'l':
- FORMAT_STRING(0, 2, tm->tm_hour % 12); /* %2d */

+ FORMAT_STRING(0, 2, (tm->tm_hour % 12 ? tm->tm_hour %


12 : 12)); /* %2d */
break;

case 'm':

---------------
And these gnuplot commands demonstrate the fix:
set xdata time


set format x "%l %p"

set timefmt "%s"
plot "-" using 1:2 with linespoints
1106953200 5
1106956800 1
1106960400 2
1106964000 3
1106967600 4
1106971200 3
1106974800 8
1106978400 4
1106982000 9
1106985600 1
1106989200 0
1106992800 3
1106996400 9
1107000000 5
1107003600 4

Jason

unread,
Jan 29, 2005, 1:42:56 AM1/29/05
to
So much for bug submission:
Mail deliver fails with:

gnupl...@lists.sourceforge.net
Unrouteable address

And spamassassin sez:

0.0 RCVD_BY_IP Received by mail server with no name

Boo. Well I hope my patch makes it in, because I don't like maintaining
patches.
Apparently sourceforge spam filters are on the side of paranoid?

0 new messages