Index: timestamp.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v
retrieving revision 1.141
diff -c -c -r1.141 timestamp.c
*** timestamp.c 22 Jul 2005 19:00:54 -0000 1.141
--- timestamp.c 23 Jul 2005 02:00:07 -0000
***************
*** 3922,3938 ****
}
! /* timestamp_zone()
! * Encode timestamp type with specified time zone.
! * Returns timestamp with time zone, with the input
* rotated from local time to the specified zone.
*/
Datum
timestamp_zone(PG_FUNCTION_ARGS)
{
text *zone = PG_GETARG_TEXT_P(0);
Timestamp timestamp = PG_GETARG_TIMESTAMP(1);
! Timestamp result;
int tz;
pg_tz *tzp;
char tzname[TZ_STRLEN_MAX+1];
--- 3922,3942 ----
}
! /* timestamp_zone()
! * Encode timestamp type with specified time zone.
! * Returns timestamp with time zone, with the input
* rotated from local time to the specified zone.
+ * This function is tricky because instead of shifting
+ * the time _to_ a new time zone, it sets the time to _be_
+ * the specified timezone. This requires trickery
+ * of double-subtracting the requested timezone offset.
*/
Datum
timestamp_zone(PG_FUNCTION_ARGS)
{
text *zone = PG_GETARG_TEXT_P(0);
Timestamp timestamp = PG_GETARG_TIMESTAMP(1);
! TimestampTz result;
int tz;
pg_tz *tzp;
char tzname[TZ_STRLEN_MAX+1];
***************
*** 3960,3966 ****
/* Apply the timezone change */
if (timestamp2tm(timestamp, &tz, &tm, &fsec, NULL, tzp) != 0 ||
! tm2timestamp(&tm, fsec, NULL, &result) != 0)
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
--- 3964,3970 ----
/* Apply the timezone change */
if (timestamp2tm(timestamp, &tz, &tm, &fsec, NULL, tzp) != 0 ||
! tm2timestamp(&tm, fsec, &tz, &result) != 0)
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
***************
*** 3968,3974 ****
tzname)));
PG_RETURN_NULL();
}
! PG_RETURN_TIMESTAMPTZ(timestamp2timestamptz(result));
}
/* timestamp_izone()
--- 3972,3981 ----
tzname)));
PG_RETURN_NULL();
}
! /* Must double-adjust for timezone */
! result = dt2local(result, -tz);
!
! PG_RETURN_TIMESTAMPTZ(result);
}
/* timestamp_izone()
Index: func.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.268
retrieving revision 1.269
diff -c -c -r1.268 -r1.269
*** func.sgml 20 Jul 2005 16:42:29 -0000 1.268
--- func.sgml 22 Jul 2005 21:16:14 -0000 1.269
***************
*** 5693,5699 ****
timestamp without time zone AT TIME ZONE zone>
timestamp with time zone
! Convert local time in given time zone to UTC
--- 5693,5699 ----
timestamp without time zone AT TIME ZONE zone>
timestamp with time zone
! Treat given timestamp without time zone> as located in the specified time zone
***************
*** 5701,5707 ****
timestamp with time zone AT TIME ZONE zone>
timestamp without time zone
! Convert UTC to local time in given time zone
--- 5701,5707 ----
timestamp with time zone AT TIME ZONE zone>
timestamp without time zone
! Convert given timestamp with time zone> to the new time zone
***************
*** 5709,5715 ****
time with time zone AT TIME ZONE zone>
time with time zone
! Convert local time across time zones
--- 5709,5715 ----
time with time zone AT TIME ZONE zone>
time with time zone
! Convert given time with time zone> to the new time zone
***************
*** 5720,5726 ****
specified either as a text string (e.g., 'PST')
or as an interval (e.g., INTERVAL '-08:00').
In the text case, the available zone names are those shown in
! .
--- 5720,5727 ----
specified either as a text string (e.g., 'PST')
or as an interval (e.g., INTERVAL '-08:00').
In the text case, the available zone names are those shown in
! . The time zone can
! also be implied using the default time zone for that session.
***************
*** 5732,5741 ****
SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
Result: 2001-02-16 18:38:40
! The first example takes a zone-less time stamp and interprets it as MST time
! (UTC-7) to produce a UTC time stamp, which is then rotated to PST (UTC-8)
! for display. The second example takes a time stamp specified in EST
! (UTC-5) and converts it to local time in MST (UTC-7).
--- 5733,5741 ----
SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
Result: 2001-02-16 18:38:40
! The first example takes a time stamp without time zone and interprets it as MST time
! (UTC-7), which is then converted to PST (UTC-8) for display. The second example takes
! a time stamp specified in EST (UTC-5) and converts it to local time in MST (UTC-7).