Menu

#504 Need to respect local timezone in formatting time data

None
closed-rejected
nobody
None
5
2020-12-25
2020-07-02
No

Gnuplot always formats time and date data in UTC, but this is seriously limiting in some cases, especially regarding DST. For example, when you're in TZ=America/Los_Angeles and run the following snippet:

set xdata time
set timefmt "%s"
set format x "%H:%M %z"
plot "-" using (1583654400+$1):1
3600
5400
7200
9000
10800
e

you should be able to get as the X labels:

01:00 -0800
01:30 -0800
03:00 -0700
03:30 -0700
04:00 -0700

but there's no way you can get this now. (There are some hacks on the Internet that read the current timezone offset, using the date command, and adjust the timestamp values to emulate the desired behavior, but it works only if all the data points have the same timezone offset as the current time.)

Gnuplot should at least respect the TZ environment variable in formatting time/date data. Maybe it would be nice to allow the script to specify the timezone, but I expect just respecting TZ would cover the vast majority of cases, since the user can set it to whatever they want outside Gnuplot.

Discussion

  • Ethan Merritt

    Ethan Merritt - 2020-12-14

    It would make no sense to query the local environment for timezone when processing input data, because whatever time corrections have already been applied or would need still to be applied are a property of the data, not a property of the computer session currently running gnuplot.
    If the data you are reading does contain a local correction field (e.g. -0700) gnuplot does accept the %z format to apply it.

    It does make sense to report the local time when generating timestamps or labeling a plot with the current time, but that can already be done by incorporating a call to system("date") into the command that produces the label or title.

    set title sprintf( "Current stats\n%s", system("date") )
    
     
  • Ethan Merritt

    Ethan Merritt - 2020-12-25
    • status: open --> closed-rejected
    • Group: -->
     

Log in to post a comment.