From: Sebastian Harl Date: Tue, 30 Oct 2012 06:55:42 +0000 (+0100) Subject: RRTimeslice: Updated output format to #/. X-Git-Url: https://git.tokkee.org/?p=postrr.git;a=commitdiff_plain;h=a83ee3c21752ab1247e1f2dbf5ec46ded323c538 RRTimeslice: Updated output format to #/. That is, format the timeslice in a range format (cf. tstzrange in PostgreSQL 9.2). I suppose this is easier to read for humans, even though it's a bit longer. Also, include the number of timeslices in addition to the sequence number as well. This way, we're able to unambiguously parse the output. --- diff --git a/src/rrtimeslice.c b/src/rrtimeslice.c index 4f151d2..6c135ec 100644 --- a/src/rrtimeslice.c +++ b/src/rrtimeslice.c @@ -44,7 +44,7 @@ #include #include #include -#include /* DateStyle, IntervalStyle */ +#include /* DateStyle */ #ifdef HAVE_INT64_TIMESTAMP # define TSTAMP_TO_INT64(t) (t) @@ -337,8 +337,8 @@ rrtimeslice_out(PG_FUNCTION_ARGS) char *tz_str = NULL; char ts_str[MAXDATELEN + 1]; - char buf_ts[MAXDATELEN + 1]; char buf_l[MAXDATELEN + 1]; + char buf_u[MAXDATELEN + 1]; char *result; int32 len = 0; @@ -353,35 +353,32 @@ rrtimeslice_out(PG_FUNCTION_ARGS) tslice = PG_GETARG_RRTIMESLICE_P(0); if (TIMESTAMP_NOT_FINITE(tslice->tstamp) - || (timestamp2tm(tslice->tstamp, &tz, &tm, &fsec, &tz_str, NULL) != 0)) + || timestamp2tm(tslice->tstamp, &tz, &tm, &fsec, &tz_str, NULL)) ereport(ERROR, ( errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("invalid (non-finite) timestamp") )); - else - EncodeDateTime(&tm, fsec, &tz, &tz_str, DateStyle, buf_ts); - if (! rrtimeslice_get_spec(tslice->tsid, &len, &num)) { - Interval interval; + EncodeDateTime(&tm, fsec, &tz, &tz_str, DateStyle, buf_u); - memset(&interval, 0, sizeof(interval)); - interval.time = len * USECS_PER_SEC; - fsec = 0; + if (! rrtimeslice_get_spec(tslice->tsid, &len, &num)) { + TimestampTz lower = tslice->tstamp - (len * USECS_PER_SEC); - if (interval2tm(interval, &tm, &fsec)) + if (timestamp2tm(lower, &tz, &tm, &fsec, &tz_str, NULL)) ereport(ERROR, ( - errmsg("could not convert interval to tm") + errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("invalid (non-finite) lower timestamp") )); - EncodeInterval(&tm, fsec, IntervalStyle, buf_l); + EncodeDateTime(&tm, fsec, &tz, &tz_str, DateStyle, buf_l); } else { strncpy(buf_l, "ERR", sizeof(buf_l)); buf_l[sizeof(buf_l) - 1] = '\0'; } - snprintf(ts_str, sizeof(ts_str), "%s -%s (#%i)", - buf_ts, buf_l, tslice->seq); + snprintf(ts_str, sizeof(ts_str), "(%s, %s] #%i/%i", + buf_l, buf_u, tslice->seq, num); result = pstrdup(ts_str); PG_RETURN_CSTRING(result);