Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd4b50ca

Browse files
committed
Display only 9 subsecond digits instead of 10 for time values, for
consistency and to prevent rounding for days < 30. Also round off alltrailing zeros, rather than leaving an even number of digits.
1 parent5dafb69 commitd4b50ca

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.149 2005/05/2715:16:44 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.150 2005/05/2721:31:23 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3461,12 +3461,9 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
34613461
#ifdefHAVE_INT64_TIMESTAMP
34623462
sprintf(str+strlen(str),":%02d.%06d",tm->tm_sec,fsec);
34633463
#else
3464-
sprintf(str+strlen(str),":%013.10f",tm->tm_sec+fsec);
3464+
sprintf(str+strlen(str),":%012.9f",tm->tm_sec+fsec);
34653465
#endif
3466-
/* chop off trailing pairs of zeros... */
3467-
while (strcmp((str+strlen(str)-2),"00")==0&&
3468-
*(str+strlen(str)-3)!='.')
3469-
*(str+strlen(str)-2)='\0';
3466+
TrimTrailingZeros(str);
34703467
}
34713468
else
34723469
sprintf(str+strlen(str),":%02d",tm->tm_sec);
@@ -3804,7 +3801,7 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
38043801
sprintf(cp,".%06d",Abs(fsec));
38053802
#else
38063803
fsec+=tm->tm_sec;
3807-
sprintf(cp,":%013.10f",fabs(fsec));
3804+
sprintf(cp,":%012.9f",fabs(fsec));
38083805
#endif
38093806
TrimTrailingZeros(cp);
38103807
cp+=strlen(cp);

‎src/interfaces/ecpg/pgtypeslib/interval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ EncodeInterval(struct tm * tm, fsec_t fsec, int style, char *str)
511511
sprintf(cp,".%06d",Abs(fsec));
512512
#else
513513
fsec+=tm->tm_sec;
514-
sprintf(cp,":%013.10f",fabs(fsec));
514+
sprintf(cp,":%012.9f",fabs(fsec));
515515
#endif
516516
TrimTrailingZeros(cp);
517517
cp+=strlen(cp);

‎src/test/regress/expected/horology.out

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,62 +205,62 @@ SET DateStyle = 'ISO';
205205
-- As of 7.4, allow time without time zone having a time zone specified
206206
SELECT time without time zone '040506.789+08';
207207
time
208-
---------------
209-
04:05:06.7890
208+
--------------
209+
04:05:06.789
210210
(1 row)
211211

212212
SELECT time without time zone '040506.789-08';
213213
time
214-
---------------
215-
04:05:06.7890
214+
--------------
215+
04:05:06.789
216216
(1 row)
217217

218218
SELECT time without time zone 'T040506.789+08';
219219
time
220-
---------------
221-
04:05:06.7890
220+
--------------
221+
04:05:06.789
222222
(1 row)
223223

224224
SELECT time without time zone 'T040506.789-08';
225225
time
226-
---------------
227-
04:05:06.7890
226+
--------------
227+
04:05:06.789
228228
(1 row)
229229

230230
SELECT time with time zone '040506.789+08';
231231
timetz
232-
------------------
233-
04:05:06.7890+08
232+
-----------------
233+
04:05:06.789+08
234234
(1 row)
235235

236236
SELECT time with time zone '040506.789-08';
237237
timetz
238-
------------------
239-
04:05:06.7890-08
238+
-----------------
239+
04:05:06.789-08
240240
(1 row)
241241

242242
SELECT time with time zone 'T040506.789+08';
243243
timetz
244-
------------------
245-
04:05:06.7890+08
244+
-----------------
245+
04:05:06.789+08
246246
(1 row)
247247

248248
SELECT time with time zone 'T040506.789-08';
249249
timetz
250-
------------------
251-
04:05:06.7890-08
250+
-----------------
251+
04:05:06.789-08
252252
(1 row)
253253

254254
SELECT time with time zone 'T040506.789 +08';
255255
timetz
256-
------------------
257-
04:05:06.7890+08
256+
-----------------
257+
04:05:06.789+08
258258
(1 row)
259259

260260
SELECT time with time zone 'T040506.789 -08';
261261
timetz
262-
------------------
263-
04:05:06.7890-08
262+
-----------------
263+
04:05:06.789-08
264264
(1 row)
265265

266266
SET DateStyle = 'Postgres, MDY';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp