77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.25 1997/06/20 17:12:54 thomas Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.26 1997/06/23 14:50:56 thomas Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -693,7 +693,7 @@ printf( "datetime_add_span- add %f to %d %f\n", *datetime, span->month, span->ti
693693#ifdef ROUND_ALL
694694dt = JROUND (dt + span -> time );
695695#else
696- dt = span -> time ;
696+ dt + =span -> time ;
697697#endif
698698
699699if (span -> month != 0 ) {
@@ -702,12 +702,13 @@ printf( "datetime_add_span- add %f to %d %f\n", *datetime, span->month, span->ti
702702
703703if (datetime2tm (dt ,& tz ,tm ,& fsec ,& tzn )== 0 ) {
704704#ifdef DATEDEBUG
705- printf ("datetime_add_span- date was %d.%02d.%02d\n" ,tm -> tm_year ,tm -> tm_mon ,tm -> tm_mday );
705+ printf ("datetime_add_span- date was %04d-%02d-%02d %02d:%02d:%02d\n" ,
706+ tm -> tm_year ,tm -> tm_mon ,tm -> tm_mday ,tm -> tm_hour ,tm -> tm_min ,tm -> tm_sec );
706707#endif
707708tm -> tm_mon += span -> month ;
708709if (tm -> tm_mon > 12 ) {
709- tm -> tm_year += (tm -> tm_mon /12 );
710- tm -> tm_mon = (tm -> tm_mon %12 );
710+ tm -> tm_year += (( tm -> tm_mon - 1 ) /12 );
711+ tm -> tm_mon = ((( tm -> tm_mon - 1 ) %12 ) + 1 );
711712}else if (tm -> tm_mon < 1 ) {
712713tm -> tm_year += ((tm -> tm_mon /12 )- 1 );
713714tm -> tm_mon = ((tm -> tm_mon %12 )+ 12 );
@@ -721,15 +722,15 @@ printf( "datetime_add_span- date was %d.%02d.%02d\n", tm->tm_year, tm->tm_mon, t
721722tm -> tm_mday = mdays [tm -> tm_mon - 1 ];
722723 };
723724};
724-
725725#ifdef DATEDEBUG
726- printf ("datetime_add_span- date becomes %d.%02d.%02d\n" ,tm -> tm_year ,tm -> tm_mon ,tm -> tm_mday );
726+ printf ("datetime_add_span- date becomes %04d-%02d-%02d %02d:%02d:%02d\n" ,
727+ tm -> tm_year ,tm -> tm_mon ,tm -> tm_mday ,tm -> tm_hour ,tm -> tm_min ,tm -> tm_sec );
727728#endif
728729if (tm2datetime (tm ,fsec ,& tz ,& dt )!= 0 )
729730elog (WARN ,"Unable to add datetime and timespan" ,NULL );
730731
731732 }else {
732- DATETIME_INVALID (* result );
733+ DATETIME_INVALID (dt );
733734 };
734735};
735736
@@ -1312,7 +1313,11 @@ static datetkn datetktbl[] = {
13121313{"eet" ,TZ ,12 },/* East. Europe, USSR Zone 1 */
13131314{"eetdst" ,DTZ ,18 },/* Eastern Europe */
13141315{EPOCH ,RESERV ,DTK_EPOCH },/* "epoch" reserved for system epoch time */
1316+ #if USE_AUSTRALIAN_RULES
1317+ {"est" ,TZ ,60 },/* Australia Eastern Std Time */
1318+ #else
13151319{"est" ,TZ ,NEG (30 )},/* Eastern Standard Time */
1320+ #endif
13161321{"feb" ,MONTH ,2 },
13171322{"february" ,MONTH ,2 },
13181323{"fri" ,DOW ,5 },
@@ -1410,6 +1415,7 @@ static datetkn datetktbl[] = {
14101415{"zp4" ,TZ ,NEG (24 )},/* GMT +4 hours. */
14111416{"zp5" ,TZ ,NEG (30 )},/* GMT +5 hours. */
14121417{"zp6" ,TZ ,NEG (36 )},/* GMT +6 hours. */
1418+ {"z" ,RESERV ,DTK_ZULU },/* 00:00:00 */
14131419{ZULU ,RESERV ,DTK_ZULU },/* 00:00:00 */
14141420};
14151421
@@ -1585,7 +1591,6 @@ datetime2tm( DateTime dt, int *tzp, struct tm *tm, double *fsec, char **tzn)
15851591struct tm * tx ;
15861592#endif
15871593
1588-
15891594date0 = date2j (2000 ,1 ,1 );
15901595
15911596time = dt ;
@@ -1625,6 +1630,9 @@ printf( "datetime2tm- time is %02d:%02d:%02d %.7f\n", tm->tm_hour, tm->tm_min, t
16251630if (tzp != NULL ) {
16261631if (IS_VALID_UTIME (tm -> tm_year ,tm -> tm_mon ,tm -> tm_mday )) {
16271632utime = (dt + (date0 - date2j (1970 ,1 ,1 ))* 86400 );
1633+ #if FALSE
1634+ if (utime < -1 )utime ++ ;
1635+ #endif
16281636
16291637#ifdef USE_POSIX_TIME
16301638tx = localtime (& utime );
@@ -1645,7 +1653,16 @@ printf( "datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s dst=%d\n",
16451653tm -> tm_mday = tx -> tm_mday ;
16461654tm -> tm_hour = tx -> tm_hour ;
16471655tm -> tm_min = tx -> tm_min ;
1656+ #if FALSE
1657+ /* XXX HACK
1658+ * Argh! My Linux box puts in a 1 second offset for dates less than 1970
1659+ * but only if the seconds field was non-zero. So, don't copy the seconds
1660+ * field and instead carry forward from the original - tgl 97/06/18
1661+ * Note that GNU/Linux uses the standard freeware zic package as do
1662+ * many other platforms so this may not be GNU/Linux/ix86-specific.
1663+ */
16481664tm -> tm_sec = tx -> tm_sec ;
1665+ #endif
16491666tm -> tm_isdst = tx -> tm_isdst ;
16501667
16511668#ifdef HAVE_INT_TIMEZONE
@@ -3071,12 +3088,19 @@ printf( "EncodeDateTime- day is %d\n", day);
30713088sprintf ( (str + 4 ),"%3s %02d" ,mabbrev ,tm -> tm_mday );
30723089};
30733090if (tm -> tm_year > 0 ) {
3074- sprintf ( (str + 10 )," %02d:%02d:%05.2f %04d" ,
3075- tm -> tm_hour ,tm -> tm_min ,sec ,tm -> tm_year );
3076-
3077- if ((* tzn != NULL )&& (tm -> tm_isdst >=0 )) {
3078- strcpy ( (str + 27 )," " );
3079- strcpy ( (str + 28 ),* tzn );
3091+ sprintf ( (str + 10 )," %02d:%02d" ,tm -> tm_hour ,tm -> tm_min );
3092+ if (fsec != 0 ) {
3093+ sprintf ( (str + 16 ),":%05.2f %04d" ,sec ,tm -> tm_year );
3094+ if ((* tzn != NULL )&& (tm -> tm_isdst >=0 )) {
3095+ strcpy ( (str + 27 )," " );
3096+ strcpy ( (str + 28 ),* tzn );
3097+ };
3098+ }else {
3099+ sprintf ( (str + 16 ),":%02.0f %04d" ,sec ,tm -> tm_year );
3100+ if ((* tzn != NULL )&& (tm -> tm_isdst >=0 )) {
3101+ strcpy ( (str + 24 )," " );
3102+ strcpy ( (str + 25 ),* tzn );
3103+ };
30803104 };
30813105
30823106}else {
@@ -3107,43 +3131,59 @@ int EncodeTimeSpan(struct tm *tm, double fsec, int style, char *str)
31073131
31083132strcpy (str ,"@" );
31093133cp = str + strlen (str );
3134+
31103135if (tm -> tm_year != 0 ) {
31113136is_nonzero = TRUE;
31123137is_before |= (tm -> tm_year < 0 );
31133138sprintf (cp ," %d year%s" ,abs (tm -> tm_year ), ((abs (tm -> tm_year )!= 1 )?"s" :"" ));
31143139cp += strlen (cp );
31153140 };
3141+
31163142if (tm -> tm_mon != 0 ) {
31173143is_nonzero = TRUE;
31183144is_before |= (tm -> tm_mon < 0 );
31193145sprintf (cp ," %d mon%s" ,abs (tm -> tm_mon ), ((abs (tm -> tm_mon )!= 1 )?"s" :"" ));
31203146cp += strlen (cp );
31213147 };
3148+
31223149if (tm -> tm_mday != 0 ) {
31233150is_nonzero = TRUE;
31243151is_before |= (tm -> tm_mday < 0 );
31253152sprintf (cp ," %d day%s" ,abs (tm -> tm_mday ), ((abs (tm -> tm_mday )!= 1 )?"s" :"" ));
31263153cp += strlen (cp );
31273154 };
3155+
31283156if (tm -> tm_hour != 0 ) {
31293157is_nonzero = TRUE;
31303158is_before |= (tm -> tm_hour < 0 );
31313159sprintf (cp ," %d hour%s" ,abs (tm -> tm_hour ), ((abs (tm -> tm_hour )!= 1 )?"s" :"" ));
31323160cp += strlen (cp );
31333161 };
3162+
31343163if (tm -> tm_min != 0 ) {
31353164is_nonzero = TRUE;
31363165is_before |= (tm -> tm_min < 0 );
31373166sprintf (cp ," %d min%s" ,abs (tm -> tm_min ), ((abs (tm -> tm_min )!= 1 )?"s" :"" ));
31383167cp += strlen (cp );
31393168 };
3140- if (tm -> tm_sec != 0 ) {
3169+
3170+ /* fractional seconds? */
3171+ if (fsec != 0 ) {
3172+ is_nonzero = TRUE;
3173+ fsec += tm -> tm_sec ;
3174+ is_before |= (fsec < 0 );
3175+ sprintf (cp ," %.2f secs" ,fabs (fsec ));
3176+ cp += strlen (cp );
3177+
3178+ /* otherwise, integer seconds only? */
3179+ }else if (tm -> tm_sec != 0 ) {
31413180is_nonzero = TRUE;
31423181is_before |= (tm -> tm_sec < 0 );
31433182sprintf (cp ," %d sec%s" ,abs (tm -> tm_sec ), ((abs (tm -> tm_sec )!= 1 )?"s" :"" ));
31443183cp += strlen (cp );
31453184 };
31463185
3186+ /* identically zero? then put in a unitless zero... */
31473187if (!is_nonzero ) {
31483188strcat (cp ," 0" );
31493189cp += strlen (cp );