From 1973971821672447d30bda6f12736a7e5987569f Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 5 Mar 2004 02:41:14 +0000 Subject: Per a brief conversation with Tom, I've created a patch for adding support for 'week' within the date_trunc function. Within the patch I added a couple of test cases and associated target output, and changed the documentation to add 'week' appropriately. Robert Creager --- src/backend/utils/adt/timestamp.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/timestamp.c') diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index ad79025ebc0..4fb5f743b03 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.99 2004/02/14 20:16:17 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.100 2004/03/05 02:41:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -2564,6 +2564,13 @@ timestamp_trunc(PG_FUNCTION_ARGS) switch (val) { + case DTK_WEEK: + isoweek2date( date2isoweek( tm->tm_year, tm->tm_mon, tm->tm_mday ), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday) ); + tm->tm_hour = 0; + tm->tm_min = 0; + tm->tm_sec = 0; + fsec = 0; + break; case DTK_MILLENNIUM: tm->tm_year = (tm->tm_year / 1000) * 1000; case DTK_CENTURY: @@ -2672,6 +2679,13 @@ timestamptz_trunc(PG_FUNCTION_ARGS) switch (val) { + case DTK_WEEK: + isoweek2date( date2isoweek( tm->tm_year, tm->tm_mon, tm->tm_mday ), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday) ); + tm->tm_hour = 0; + tm->tm_min = 0; + tm->tm_sec = 0; + fsec = 0; + break; case DTK_MILLENNIUM: tm->tm_year = (tm->tm_year / 1000) * 1000; case DTK_CENTURY: -- cgit v1.2.3