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

Commit31174f1

Browse files
author
Thomas G. Lockhart
committed
Remove difftime() calls.
Still uses time_t declarations, but most code will be changed for next release.
1 parent43163cf commit31174f1

File tree

1 file changed

+28
-126
lines changed

1 file changed

+28
-126
lines changed

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

Lines changed: 28 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -5,128 +5,19 @@
55
#include"postgres.h"
66
#include"miscadmin.h"
77
#include"utils/builtins.h"
8+
#include"access/xact.h"
89

9-
/* sunos doesn't have this function */
10-
#if defined(sunos4)
11-
#definedifftime(time1,time0) ((time1) - (time0))
12-
#endif
13-
14-
#ifFALSE
15-
/* copy the next part of the string into a buffer */
16-
staticconstchar*
17-
cpstr(constchar*s,char*buf)
18-
{
19-
charin=0;
20-
21-
while (isspace(*s))
22-
s++;
23-
24-
for (;*s&& !isspace(*s);s++)
25-
{
26-
if (strchr("-,:/",*s))
27-
{
28-
buf[in]=0;
29-
return (s+1);
30-
}
31-
32-
if (in<16)
33-
buf[in++]=tolower(*s);
34-
}
35-
36-
buf[in]=0;
37-
returns;
38-
}
39-
40-
#endif
41-
42-
/* assumes dd/mm/yyyy unless first item is month in word form */
4310
time_t
4411
timestamp_in(constchar*timestamp_str)
4512
{
4613
int4result;
4714

48-
#ifFALSE
49-
structtminput_time;
50-
charbuf[18];
51-
constchar*p;
52-
staticconstchar*mstr[]= {
53-
"january","february","march","april","may","june",
54-
"july","august","september","october","november","december"
55-
};
56-
57-
memset(&input_time,0,sizeof(input_time));
58-
p=cpstr(timestamp_str,buf);
59-
if (isdigit(buf[0]))/* must be dd/mm/yyyy */
60-
{
61-
input_time.tm_mday=atoi(buf);
62-
p=cpstr(p,buf);
63-
if (!buf[0])
64-
elog(WARN,"timestamp_in: timestamp \"%s\" not a proper date",
65-
timestamp_str);
66-
if (isdigit(buf[0]))
67-
{
68-
input_time.tm_mon=atoi(buf)-1;
69-
if (input_time.tm_mon<0||input_time.tm_mon>11)
70-
elog(WARN,"timestamp_in: timestamp \"%s\" invalid month",
71-
timestamp_str);
72-
}
73-
else
74-
{
75-
inti;
76-
77-
for (i=0;i<12;i++)
78-
if (strncmp(mstr[i],buf,strlen(buf))==0)
79-
break;
80-
if (1>11)
81-
elog(WARN,"timestamp_in: timestamp \"%s\" invalid month",
82-
timestamp_str);
83-
input_time.tm_mon=i;
84-
}
85-
}
86-
else
87-
/* must be month/dd/yyyy */
88-
{
89-
inti;
90-
91-
for (i=0;i<12;i++)
92-
if (strncmp(mstr[i],buf,strlen(buf))==0)
93-
break;
94-
if (1>11)
95-
elog(WARN,"timestamp_in: timestamp \"%s\" invalid month",
96-
timestamp_str);
97-
input_time.tm_mon=i;
98-
p=cpstr(p,buf);
99-
input_time.tm_mday=atoi(buf);
100-
if (!input_time.tm_mday||input_time.tm_mday>31)
101-
elog(WARN,"timestamp_in: timestamp \"%s\" not a proper date",
102-
timestamp_str);
103-
}
104-
105-
p=cpstr(p,buf);
106-
if (!buf[0]|| !isdigit(buf[0]))
107-
elog(WARN,"timestamp_in: timestamp \"%s\" not a proper date",
108-
timestamp_str);
109-
if ((input_time.tm_year=atoi(buf))<1900)
110-
input_time.tm_year+=1900;
111-
112-
/* now get the time */
113-
p=cpstr(p,buf);
114-
input_time.tm_hour=atoi(buf);
115-
p=cpstr(p,buf);
116-
input_time.tm_min=atoi(buf);
117-
p=cpstr(p,buf);
118-
input_time.tm_sec=atoi(buf);
119-
120-
/* use mktime(), but make this GMT, not local time */
121-
result=mktime(&input_time);
122-
#endif
123-
12415
result=nabstimein((char*)timestamp_str);
12516

12617
returnresult;
12718
}
12819

129-
char*
20+
char*
13021
timestamp_out(time_ttimestamp)
13122
{
13223
char*result;
@@ -138,13 +29,6 @@ timestamp_out(time_t timestamp)
13829
charzone[MAXDATELEN+1],
13930
*tzn=zone;
14031

141-
#ifFALSE
142-
time=localtime(&timestamp);
143-
144-
sprintf(result,"%04d-%02d-%02d %02d:%02d:%02d",
145-
time->tm_year+1900,time->tm_mon+1,time->tm_mday,
146-
time->tm_hour,time->tm_min,time->tm_sec);
147-
#endif
14832
abstime2tm(timestamp,&tz,tm,tzn);
14933
EncodeDateTime(tm,fsec,&tz,&tzn,USE_ISO_DATES,buf);
15034

@@ -158,44 +42,62 @@ now(void)
15842
{
15943
time_tsec;
16044

161-
time(&sec);
45+
sec=GetCurrentTransactionStartTime();
16246
return (sec);
16347
}
16448

16549
bool
16650
timestampeq(time_tt1,time_tt2)
16751
{
168-
returndifftime(t1,t2)==0;
52+
#ifFALSE
53+
return(t1==t2);
54+
#endif
55+
return(abstimeeq(t1,t2));
16956
}
17057

17158
bool
17259
timestampne(time_tt1,time_tt2)
17360
{
174-
returndifftime(t1,t2)!=0;
61+
#ifFALSE
62+
return(t1!=t2);
63+
#endif
64+
return(abstimene(t1,t2));
17565
}
17666

17767
bool
17868
timestamplt(time_tt1,time_tt2)
17969
{
180-
returndifftime(t1,t2)>0;
70+
#ifFALSE
71+
return(t1>t2);
72+
#endif
73+
return(abstimelt(t1,t2));
18174
}
18275

18376
bool
18477
timestampgt(time_tt1,time_tt2)
18578
{
186-
returndifftime(t1,t2)<0;
79+
#ifFALSE
80+
return(t1<t2);
81+
#endif
82+
return(abstimegt(t1,t2));
18783
}
18884

18985
bool
19086
timestample(time_tt1,time_tt2)
19187
{
192-
returndifftime(t1,t2) >=0;
88+
#ifFALSE
89+
return(t1 >=t2);
90+
#endif
91+
return(abstimele(t1,t2));
19392
}
19493

19594
bool
19695
timestampge(time_tt1,time_tt2)
19796
{
198-
returndifftime(t1,t2) <=0;
97+
#ifFALSE
98+
return(t1 <=t2);
99+
#endif
100+
return(abstimege(t1,t2));
199101
}
200102

201103
DateTime*
@@ -217,4 +119,4 @@ timestamp_datetime(time_t timestamp)
217119
elog(WARN,"Unable to convert timestamp to datetime",timestamp_out(timestamp));
218120

219121
return (result);
220-
}/* timestamp_datetime() */
122+
}/* timestamp_datetime() */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp