From 5028818f22f4e31202503387f5e9accf4ec4889f Mon Sep 17 00:00:00 2001 From: hjp Date: Sun, 7 Oct 2012 17:52:20 +0000 Subject: [PATCH] switch to 3 month grid if graph spans more than 3 years. --- quotacheck/quotagraph | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/quotacheck/quotagraph b/quotacheck/quotagraph index 8d02ee0..0438a00 100755 --- a/quotacheck/quotagraph +++ b/quotacheck/quotagraph @@ -82,7 +82,31 @@ print CTL "set grid\n"; my $firsttime = ($data[0])->[0]; my $lasttime = ($data[$#data])->[0]; -if ($lasttime - $firsttime > 3 * 30 * 24 * 3600) { +if ($lasttime - $firsttime > 3 * 365 * 24 * 3600) { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); + $sec = $min = $hour = 0; + $mday = 1; + $mon = int($mon/3) * 3; + $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year); + print CTL "set xtics rotate ("; + my $comma = 0; + my $time; + for (;;) { + $time = timelocal($sec,$min,$hour,$mday,$mon,$year); + if ($comma) { + print CTL ", "; + } else { + $comma = 1; + } + printf CTL qq|"%04d-%02d-%02d" %d|, $year+1900, $mon+1, $mday, $time; + if (($mon += 3) >= 12) { + $mon = 0; $year++; + } + if ($time > $lasttime) {last} + } + $lasttime = $time; + print CTL ")\n"; +} elsif ($lasttime - $firsttime > 3 * 30 * 24 * 3600) { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $sec = $min = $hour = 0; $mday = 1;