summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bd4264e)
raw | patch | inline | side by side (parent: bd4264e)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 30 Oct 2012 06:55:42 +0000 (07:55 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 30 Oct 2012 06:55:42 +0000 (07:55 +0100) |
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.
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.
src/rrtimeslice.c | patch | blob | history |
diff --git a/src/rrtimeslice.c b/src/rrtimeslice.c
index 4f151d27b1b3f93b60164bc9759ddfb718396b46..6c135ec893ec865a6a18313d491e088c708dab71 100644 (file)
--- a/src/rrtimeslice.c
+++ b/src/rrtimeslice.c
#include <utils/array.h>
#include <utils/datetime.h>
#include <utils/timestamp.h>
-#include <miscadmin.h> /* DateStyle, IntervalStyle */
+#include <miscadmin.h> /* DateStyle */
#ifdef HAVE_INT64_TIMESTAMP
# define TSTAMP_TO_INT64(t) (t)
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;
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);