X-Git-Url: https://git.tokkee.org/?p=postrr.git;a=blobdiff_plain;f=src%2Frrtimeslice.c;fp=src%2Frrtimeslice.c;h=1e8283c30235a0cced110368739c1cbb1b410407;hp=7de9ed742244b8c30b7ec2e7266e3fb9ae3ed552;hb=204a47a5eef2694c4e8105ad68e667446bbf36a0;hpb=3d39f72435c8664ea9ffce084b1cc8297b6070fd diff --git a/src/rrtimeslice.c b/src/rrtimeslice.c index 7de9ed7..1e8283c 100644 --- a/src/rrtimeslice.c +++ b/src/rrtimeslice.c @@ -244,6 +244,7 @@ PG_FUNCTION_INFO_V1(rrtimeslice_typmodin); PG_FUNCTION_INFO_V1(rrtimeslice_typmodout); PG_FUNCTION_INFO_V1(rrtimeslice_to_rrtimeslice); +PG_FUNCTION_INFO_V1(timestamptz_to_rrtimeslice); PG_FUNCTION_INFO_V1(rrtimeslice_to_timestamptz); PG_FUNCTION_INFO_V1(rrtimeslice_cmp); @@ -511,6 +512,34 @@ rrtimeslice_to_rrtimeslice(PG_FUNCTION_ARGS) PG_RETURN_RRTIMESLICE_P(tslice); } /* rrtimeslice_to_rrtimeslice */ +Datum +timestamptz_to_rrtimeslice(PG_FUNCTION_ARGS) +{ + TimestampTz tstamp; + int32 typmod; + + rrtimeslice_t *tslice; + + if (PG_NARGS() != 3) + ereport(ERROR, ( + errmsg("timestamptz_to_rrtimeslice() " + "expects three arguments"), + errhint("Usage: timestamptz_to_rrtimeslice" + "(timestamptz, typmod, is_explicit)") + )); + + tstamp = PG_GETARG_TIMESTAMPTZ(0); + typmod = PG_GETARG_INT32(1); + + tslice = (rrtimeslice_t *)palloc0(sizeof(*tslice)); + + tslice->tstamp = tstamp; + if (typmod >= 0) + rrtimeslice_apply_typmod(tslice, typmod); + + PG_RETURN_RRTIMESLICE_P(tslice); +} /* timestamptz_to_rrtimeslice */ + Datum rrtimeslice_to_timestamptz(PG_FUNCTION_ARGS) {