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

Commitd451a3b

Browse files
author
Thomas G. Lockhart
committed
Enable timespan_finite() and text_timespan() routines (was commented out).
Define an "ISO-style" timespan output format with "hh:mm:ss" fields. Enabled by DateStyle = USE_ISO_DATES.
1 parent5af05c0 commitd451a3b

File tree

1 file changed

+85
-50
lines changed
  • src/backend/utils/adt

1 file changed

+85
-50
lines changed

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

Lines changed: 85 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.45 1997/12/04 23:30:52 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.46 1997/12/17 23:22:17 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,26 +31,24 @@
3131
#endif
3232
#include"utils/builtins.h"
3333

34-
staticintDecodeDate(char*str,intfmask,int*tmask,structtm*tm);
34+
staticintDecodeDate(char*str,intfmask,int*tmask,structtm*tm);
3535
staticint
3636
DecodeNumber(intflen,char*field,
3737
intfmask,int*tmask,structtm*tm,double*fsec);
3838
staticint
3939
DecodeNumberField(intlen,char*str,
4040
intfmask,int*tmask,structtm*tm,double*fsec);
41-
staticintDecodeSpecial(intfield,char*lowtoken,int*val);
41+
staticintDecodeSpecial(intfield,char*lowtoken,int*val);
4242
staticint
4343
DecodeTime(char*str,intfmask,int*tmask,
4444
structtm*tm,double*fsec);
45-
staticintDecodeTimezone(char*str,int*tzp);
46-
staticintDecodeUnits(intfield,char*lowtoken,int*val);
47-
staticintEncodeSpecialDateTime(DateTimedt,char*str);
45+
staticintDecodeTimezone(char*str,int*tzp);
46+
staticintDecodeUnits(intfield,char*lowtoken,int*val);
47+
staticintEncodeSpecialDateTime(DateTimedt,char*str);
4848
staticdatetkn*datebsearch(char*key,datetkn*base,unsignedintnel);
4949
staticDateTimedt2local(DateTimedt,inttimezone);
5050
staticvoiddt2time(DateTimedt,int*hour,int*min,double*sec);
51-
staticintj2day(intjd);
52-
staticinttimespan2tm(TimeSpanspan,structtm*tm,float8*fsec);
53-
staticinttm2timespan(structtm*tm,doublefsec,TimeSpan*span);
51+
staticintj2day(intjd);
5452

5553
#defineUSE_DATE_CACHE 1
5654
#defineROUND_ALL 0
@@ -297,8 +295,6 @@ datetime_finite(DateTime *datetime)
297295
return (!DATETIME_NOT_FINITE(*datetime));
298296
}/* datetime_finite() */
299297

300-
301-
#ifdefNOT_USED
302298
bool
303299
timespan_finite(TimeSpan*timespan)
304300
{
@@ -308,7 +304,6 @@ timespan_finite(TimeSpan *timespan)
308304
return (!TIMESPAN_NOT_FINITE(*timespan));
309305
}/* timespan_finite() */
310306

311-
#endif
312307

313308
/*----------------------------------------------------------
314309
*Relational operators for datetime.
@@ -1368,8 +1363,7 @@ timespan_text(TimeSpan *timespan)
13681363
* Text type may not be null terminated, so copy to temporary string
13691364
*then call the standard input routine.
13701365
*/
1371-
#ifdefNOT_USED
1372-
TimeSpan*
1366+
TimeSpan*
13731367
text_timespan(text*str)
13741368
{
13751369
TimeSpan*result;
@@ -1392,8 +1386,6 @@ text_timespan(text *str)
13921386
return (result);
13931387
}/* text_timespan() */
13941388

1395-
#endif
1396-
13971389
/* datetime_trunc()
13981390
* Extract specified field from datetime.
13991391
*/
@@ -2573,7 +2565,7 @@ tm2datetime(struct tm * tm, double fsec, int *tzp, DateTime *result)
25732565
/* timespan2tm()
25742566
* Convert a timespan data type to a tm structure.
25752567
*/
2576-
staticint
2568+
int
25772569
timespan2tm(TimeSpanspan,structtm*tm,float8*fsec)
25782570
{
25792571
doubletime;
@@ -2610,7 +2602,7 @@ timespan2tm(TimeSpan span, struct tm * tm, float8 *fsec)
26102602
return0;
26112603
}/* timespan2tm() */
26122604

2613-
staticint
2605+
int
26142606
tm2timespan(structtm*tm,doublefsec,TimeSpan*span)
26152607
{
26162608
span->month= ((tm->tm_year*12)+tm->tm_mon);
@@ -4369,10 +4361,19 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
43694361
{
43704362
intis_before= FALSE;
43714363
intis_nonzero= FALSE;
4372-
char*cp;
4364+
char*cp=str;
43734365

4374-
strcpy(str,"@");
4375-
cp=str+strlen(str);
4366+
switch (style)
4367+
{
4368+
/* compatible with ISO date formats */
4369+
caseUSE_ISO_DATES:
4370+
break;
4371+
4372+
default:
4373+
strcpy(cp,"@");
4374+
cp+=strlen(cp);
4375+
break;
4376+
}
43764377

43774378
if (tm->tm_year!=0)
43784379
{
@@ -4398,39 +4399,73 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
43984399
cp+=strlen(cp);
43994400
}
44004401

4401-
if (tm->tm_hour!=0)
4402+
switch (style)
44024403
{
4403-
is_nonzero= TRUE;
4404-
is_before |= (tm->tm_hour<0);
4405-
sprintf(cp," %d hour%s",abs(tm->tm_hour), ((abs(tm->tm_hour)!=1) ?"s" :""));
4406-
cp+=strlen(cp);
4407-
}
4404+
/* compatible with ISO date formats */
4405+
caseUSE_ISO_DATES:
4406+
if ((tm->tm_hour!=0)|| (tm->tm_min!=0))
4407+
is_nonzero= TRUE;
4408+
is_before |= ((tm->tm_hour<0)|| (tm->tm_min<0));
4409+
sprintf(cp," %02d:%02d",abs(tm->tm_hour),abs(tm->tm_min));
4410+
cp+=strlen(cp);
4411+
4412+
/* fractional seconds? */
4413+
if (fsec!=0)
4414+
{
4415+
is_nonzero= TRUE;
4416+
fsec+=tm->tm_sec;
4417+
is_before |= (fsec<0);
4418+
sprintf(cp,":%05.2f",fabs(fsec));
4419+
cp+=strlen(cp);
44084420

4409-
if (tm->tm_min!=0)
4410-
{
4411-
is_nonzero= TRUE;
4412-
is_before |= (tm->tm_min<0);
4413-
sprintf(cp," %d min%s",abs(tm->tm_min), ((abs(tm->tm_min)!=1) ?"s" :""));
4414-
cp+=strlen(cp);
4415-
}
4421+
/* otherwise, integer seconds only? */
4422+
}
4423+
elseif (tm->tm_sec!=0)
4424+
{
4425+
is_nonzero= TRUE;
4426+
is_before |= (tm->tm_sec<0);
4427+
sprintf(cp,":%02d",abs(tm->tm_sec));
4428+
cp+=strlen(cp);
4429+
}
4430+
break;
44164431

4417-
/* fractional seconds? */
4418-
if (fsec!=0)
4419-
{
4420-
is_nonzero= TRUE;
4421-
fsec+=tm->tm_sec;
4422-
is_before |= (fsec<0);
4423-
sprintf(cp," %.2f secs",fabs(fsec));
4424-
cp+=strlen(cp);
4432+
caseUSE_POSTGRES_DATES:
4433+
default:
4434+
if (tm->tm_hour!=0)
4435+
{
4436+
is_nonzero= TRUE;
4437+
is_before |= (tm->tm_hour<0);
4438+
sprintf(cp," %d hour%s",abs(tm->tm_hour), ((abs(tm->tm_hour)!=1) ?"s" :""));
4439+
cp+=strlen(cp);
4440+
}
44254441

4426-
/* otherwise, integer seconds only? */
4427-
}
4428-
elseif (tm->tm_sec!=0)
4429-
{
4430-
is_nonzero= TRUE;
4431-
is_before |= (tm->tm_sec<0);
4432-
sprintf(cp," %d sec%s",abs(tm->tm_sec), ((abs(tm->tm_sec)!=1) ?"s" :""));
4433-
cp+=strlen(cp);
4442+
if (tm->tm_min!=0)
4443+
{
4444+
is_nonzero= TRUE;
4445+
is_before |= (tm->tm_min<0);
4446+
sprintf(cp," %d min%s",abs(tm->tm_min), ((abs(tm->tm_min)!=1) ?"s" :""));
4447+
cp+=strlen(cp);
4448+
}
4449+
4450+
/* fractional seconds? */
4451+
if (fsec!=0)
4452+
{
4453+
is_nonzero= TRUE;
4454+
fsec+=tm->tm_sec;
4455+
is_before |= (fsec<0);
4456+
sprintf(cp," %.2f secs",fabs(fsec));
4457+
cp+=strlen(cp);
4458+
4459+
/* otherwise, integer seconds only? */
4460+
}
4461+
elseif (tm->tm_sec!=0)
4462+
{
4463+
is_nonzero= TRUE;
4464+
is_before |= (tm->tm_sec<0);
4465+
sprintf(cp," %d sec%s",abs(tm->tm_sec), ((abs(tm->tm_sec)!=1) ?"s" :""));
4466+
cp+=strlen(cp);
4467+
}
4468+
break;
44344469
}
44354470

44364471
/* identically zero? then put in a unitless zero... */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp