7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -693,7 +693,7 @@ printf( "datetime_add_span- add %f to %d %f\n", *datetime, span->month, span->ti
693
693
#ifdef ROUND_ALL
694
694
dt = JROUND (dt + span -> time );
695
695
#else
696
- dt = span -> time ;
696
+ dt + = span -> time ;
697
697
#endif
698
698
699
699
if (span -> month != 0 ) {
@@ -702,12 +702,13 @@ printf( "datetime_add_span- add %f to %d %f\n", *datetime, span->month, span->ti
702
702
703
703
if (datetime2tm ( dt , & tz , tm , & fsec , & tzn ) == 0 ) {
704
704
#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 );
706
707
#endif
707
708
tm -> tm_mon += span -> month ;
708
709
if (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 );
711
712
} else if (tm -> tm_mon < 1 ) {
712
713
tm -> tm_year += ((tm -> tm_mon / 12 ) - 1 );
713
714
tm -> 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
721
722
tm -> tm_mday = mdays [ tm -> tm_mon - 1 ];
722
723
};
723
724
};
724
-
725
725
#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 );
727
728
#endif
728
729
if (tm2datetime ( tm , fsec , & tz , & dt ) != 0 )
729
730
elog (WARN ,"Unable to add datetime and timespan" ,NULL );
730
731
731
732
} else {
732
- DATETIME_INVALID (* result );
733
+ DATETIME_INVALID (dt );
733
734
};
734
735
};
735
736
@@ -1312,7 +1313,11 @@ static datetkn datetktbl[] = {
1312
1313
{ "eet" , TZ , 12 }, /* East. Europe, USSR Zone 1 */
1313
1314
{ "eetdst" , DTZ , 18 }, /* Eastern Europe */
1314
1315
{ 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
1315
1319
{ "est" , TZ , NEG (30 )}, /* Eastern Standard Time */
1320
+ #endif
1316
1321
{ "feb" , MONTH , 2 },
1317
1322
{ "february" , MONTH , 2 },
1318
1323
{ "fri" , DOW , 5 },
@@ -1410,6 +1415,7 @@ static datetkn datetktbl[] = {
1410
1415
{ "zp4" , TZ , NEG (24 )}, /* GMT +4 hours. */
1411
1416
{ "zp5" , TZ , NEG (30 )}, /* GMT +5 hours. */
1412
1417
{ "zp6" , TZ , NEG (36 )}, /* GMT +6 hours. */
1418
+ { "z" , RESERV , DTK_ZULU }, /* 00:00:00 */
1413
1419
{ ZULU , RESERV , DTK_ZULU }, /* 00:00:00 */
1414
1420
};
1415
1421
@@ -1585,7 +1591,6 @@ datetime2tm( DateTime dt, int *tzp, struct tm *tm, double *fsec, char **tzn)
1585
1591
struct tm * tx ;
1586
1592
#endif
1587
1593
1588
-
1589
1594
date0 = date2j (2000 ,1 ,1 );
1590
1595
1591
1596
time = dt ;
@@ -1625,6 +1630,9 @@ printf( "datetime2tm- time is %02d:%02d:%02d %.7f\n", tm->tm_hour, tm->tm_min, t
1625
1630
if (tzp != NULL ) {
1626
1631
if (IS_VALID_UTIME ( tm -> tm_year , tm -> tm_mon , tm -> tm_mday )) {
1627
1632
utime = (dt + (date0 - date2j (1970 ,1 ,1 ))* 86400 );
1633
+ #if FALSE
1634
+ if (utime < -1 ) utime ++ ;
1635
+ #endif
1628
1636
1629
1637
#ifdef USE_POSIX_TIME
1630
1638
tx = localtime (& utime );
@@ -1645,7 +1653,16 @@ printf( "datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s dst=%d\n",
1645
1653
tm -> tm_mday = tx -> tm_mday ;
1646
1654
tm -> tm_hour = tx -> tm_hour ;
1647
1655
tm -> 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
+ */
1648
1664
tm -> tm_sec = tx -> tm_sec ;
1665
+ #endif
1649
1666
tm -> tm_isdst = tx -> tm_isdst ;
1650
1667
1651
1668
#ifdef HAVE_INT_TIMEZONE
@@ -3071,12 +3088,19 @@ printf( "EncodeDateTime- day is %d\n", day);
3071
3088
sprintf ( (str + 4 ), "%3s %02d" , mabbrev , tm -> tm_mday );
3072
3089
};
3073
3090
if (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
+ };
3080
3104
};
3081
3105
3082
3106
} else {
@@ -3107,43 +3131,59 @@ int EncodeTimeSpan(struct tm *tm, double fsec, int style, char *str)
3107
3131
3108
3132
strcpy ( str , "@" );
3109
3133
cp = str + strlen (str );
3134
+
3110
3135
if (tm -> tm_year != 0 ) {
3111
3136
is_nonzero = TRUE;
3112
3137
is_before |= (tm -> tm_year < 0 );
3113
3138
sprintf ( cp , " %d year%s" , abs (tm -> tm_year ), ((abs (tm -> tm_year ) != 1 )? "s" : "" ));
3114
3139
cp += strlen (cp );
3115
3140
};
3141
+
3116
3142
if (tm -> tm_mon != 0 ) {
3117
3143
is_nonzero = TRUE;
3118
3144
is_before |= (tm -> tm_mon < 0 );
3119
3145
sprintf ( cp , " %d mon%s" , abs (tm -> tm_mon ), ((abs (tm -> tm_mon ) != 1 )? "s" : "" ));
3120
3146
cp += strlen (cp );
3121
3147
};
3148
+
3122
3149
if (tm -> tm_mday != 0 ) {
3123
3150
is_nonzero = TRUE;
3124
3151
is_before |= (tm -> tm_mday < 0 );
3125
3152
sprintf ( cp , " %d day%s" , abs (tm -> tm_mday ), ((abs (tm -> tm_mday ) != 1 )? "s" : "" ));
3126
3153
cp += strlen (cp );
3127
3154
};
3155
+
3128
3156
if (tm -> tm_hour != 0 ) {
3129
3157
is_nonzero = TRUE;
3130
3158
is_before |= (tm -> tm_hour < 0 );
3131
3159
sprintf ( cp , " %d hour%s" , abs (tm -> tm_hour ), ((abs (tm -> tm_hour ) != 1 )? "s" : "" ));
3132
3160
cp += strlen (cp );
3133
3161
};
3162
+
3134
3163
if (tm -> tm_min != 0 ) {
3135
3164
is_nonzero = TRUE;
3136
3165
is_before |= (tm -> tm_min < 0 );
3137
3166
sprintf ( cp , " %d min%s" , abs (tm -> tm_min ), ((abs (tm -> tm_min ) != 1 )? "s" : "" ));
3138
3167
cp += strlen (cp );
3139
3168
};
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 ) {
3141
3180
is_nonzero = TRUE;
3142
3181
is_before |= (tm -> tm_sec < 0 );
3143
3182
sprintf ( cp , " %d sec%s" , abs (tm -> tm_sec ), ((abs (tm -> tm_sec ) != 1 )? "s" : "" ));
3144
3183
cp += strlen (cp );
3145
3184
};
3146
3185
3186
+ /* identically zero? then put in a unitless zero... */
3147
3187
if (! is_nonzero ) {
3148
3188
strcat ( cp , " 0" );
3149
3189
cp += strlen (cp );
0 commit comments