|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.70 2002/08/04 06:44:47 thomas Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.71 2002/09/03 19:41:28 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -337,45 +337,32 @@ date_timestamptz(PG_FUNCTION_ARGS)
|
337 | 337 | TimestampTz result;
|
338 | 338 | struct tm tt,
|
339 | 339 | *tm = &tt;
|
340 |
| - time_t utime; |
341 | 340 |
|
342 |
| - j2date((dateVal + date2j(2000, 1, 1)), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday)); |
| 341 | + j2date((dateVal + date2j(2000, 1, 1)), |
| 342 | + &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday)); |
343 | 343 |
|
344 | 344 | if (IS_VALID_UTIME(tm->tm_year, tm->tm_mon, tm->tm_mday))
|
345 | 345 | {
|
346 |
| -#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE) |
| 346 | + int tz; |
| 347 | + |
347 | 348 | tm->tm_hour = 0;
|
348 | 349 | tm->tm_min = 0;
|
349 | 350 | tm->tm_sec = 0;
|
350 |
| - tm->tm_isdst = -1; |
351 |
| - |
352 |
| - tm->tm_year -= 1900; |
353 |
| - tm->tm_mon -= 1; |
354 |
| - utime = mktime(tm); |
355 |
| - if (utime == -1) |
356 |
| - elog(ERROR, "Unable to convert date to tm"); |
| 351 | + tz = DetermineLocalTimeZone(tm); |
357 | 352 |
|
358 | 353 | #ifdef HAVE_INT64_TIMESTAMP
|
359 |
| - result = ((utime * INT64CONST(1000000)) |
360 |
| - + ((date2j(1970, 1, 1) - date2j(2000, 1, 1)) * INT64CONST(86400000000))); |
361 |
| -#else |
362 |
| - result = utime + ((date2j(1970, 1, 1) - date2j(2000, 1, 1)) * 86400.0); |
363 |
| -#endif |
364 |
| -#else |
365 |
| -#ifdef HAVE_INT64_TIMESTAMP |
366 |
| - result = ((dateVal * INT64CONST(86400000000)) |
367 |
| - + (CTimeZone * INT64CONST(1000000))); |
| 354 | + result = (dateVal * INT64CONST(86400000000)) |
| 355 | + + (tz * INT64CONST(1000000)); |
368 | 356 | #else
|
369 |
| - result = dateVal * 86400.0 + CTimeZone; |
370 |
| -#endif |
| 357 | + result = dateVal * 86400.0 + tz; |
371 | 358 | #endif
|
372 | 359 | }
|
373 | 360 | else
|
374 | 361 | {
|
| 362 | + /* Outside of range for timezone support, so assume UTC */ |
375 | 363 | #ifdef HAVE_INT64_TIMESTAMP
|
376 | 364 | result = (dateVal * INT64CONST(86400000000));
|
377 | 365 | #else
|
378 |
| - /* Outside of range for timezone support, so assume UTC */ |
379 | 366 | result = dateVal * 86400.0;
|
380 | 367 | #endif
|
381 | 368 | }
|
|
0 commit comments