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

Commit1c8a7f6

Browse files
committed
Remove internal uses of CTimeZone/HasCTZSet.
The only remaining places where we actually look at CTimeZone/HasCTZSetare abstime2tm() and timestamp2tm(). Now that session_timezone is alwaysvalid, we can remove these special cases. The caller-visible impact ofthis is that these functions now always return a valid zone abbreviationif requested, whereas before they'd return a NULL pointer if a brute-forcetimezone was in use. In the existing code, the only place I can find thatchanges behavior is to_char(), whose TZ format code will now printsomething useful rather than nothing for such zones. (In the places wherethe returned zone abbreviation is passed to EncodeDateTime, the lack ofvisible change is because we've chosen the abbreviation used for thesezones to match what EncodeTimezone would have printed.)It's likely that there is now a fair amount of removable dead code aroundthe call sites, namely anything that's meant to cope with getting a NULLtimezone abbreviation, but I've not made an effort to root that out.This could be back-patched if we decide we'd like to fix to_char()'sbehavior in the back branches, but there doesn't seem to be muchenthusiasm for that at present.
1 parent631dc39 commit1c8a7f6

File tree

3 files changed

+9
-60
lines changed

3 files changed

+9
-60
lines changed

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
100100
pg_time_ttime= (pg_time_t)_time;
101101
structpg_tm*tx;
102102

103-
/*
104-
* If HasCTZSet is true then we have a brute force time zone specified. Go
105-
* ahead and rotate to the local time zone since we will later bypass any
106-
* calls which adjust the tm fields.
107-
*/
108-
if (HasCTZSet&& (tzp!=NULL))
109-
time-=CTimeZone;
110-
111-
if (!HasCTZSet&&tzp!=NULL)
103+
if (tzp!=NULL)
112104
tx=pg_localtime(&time,session_timezone);
113105
else
114106
tx=pg_gmtime(&time);
@@ -126,21 +118,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
126118

127119
if (tzp!=NULL)
128120
{
129-
/*
130-
* We have a brute force time zone per SQL99? Then use it without
131-
* change since we have already rotated to the time zone.
132-
*/
133-
if (HasCTZSet)
134-
{
135-
*tzp=CTimeZone;
136-
tm->tm_gmtoff=CTimeZone;
137-
tm->tm_isdst=0;
138-
tm->tm_zone=NULL;
139-
if (tzn!=NULL)
140-
*tzn=NULL;
141-
}
142-
else
143-
{
144121
*tzp=-tm->tm_gmtoff;/* tm_gmtoff is Sun/DEC-ism */
145122

146123
/*
@@ -161,7 +138,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
161138
errmsg("invalid time zone name: \"%s\"",
162139
tm->tm_zone)));
163140
}
164-
}
165141
}
166142
else
167143
tm->tm_isdst=-1;

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

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,8 +1498,7 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
14981498
* 0 on success
14991499
*-1 on out of range
15001500
*
1501-
* If attimezone is NULL, the global timezone (including possibly brute forced
1502-
* timezone) will be used.
1501+
* If attimezone is NULL, the global timezone setting will be used.
15031502
*/
15041503
int
15051504
timestamp2tm(Timestampdt,int*tzp,structpg_tm*tm,fsec_t*fsec,constchar**tzn,pg_tz*attimezone)
@@ -1508,19 +1507,9 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, const char
15081507
Timestamptime;
15091508
pg_time_tutime;
15101509

1511-
/*
1512-
* If HasCTZSet is true then we have a brute force time zone specified. Go
1513-
* ahead and rotate to the local time zone since we will later bypass any
1514-
* calls which adjust the tm fields.
1515-
*/
1516-
if (attimezone==NULL&&HasCTZSet&&tzp!=NULL)
1517-
{
1518-
#ifdefHAVE_INT64_TIMESTAMP
1519-
dt-=CTimeZone*USECS_PER_SEC;
1520-
#else
1521-
dt-=CTimeZone;
1522-
#endif
1523-
}
1510+
/* Use session timezone if caller asks for default */
1511+
if (attimezone==NULL)
1512+
attimezone=session_timezone;
15241513

15251514
#ifdefHAVE_INT64_TIMESTAMP
15261515
time=dt;
@@ -1589,21 +1578,6 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, const char
15891578
return0;
15901579
}
15911580

1592-
/*
1593-
* We have a brute force time zone per SQL99? Then use it without change
1594-
* since we have already rotated to the time zone.
1595-
*/
1596-
if (attimezone==NULL&&HasCTZSet)
1597-
{
1598-
*tzp=CTimeZone;
1599-
tm->tm_isdst=0;
1600-
tm->tm_gmtoff=CTimeZone;
1601-
tm->tm_zone=NULL;
1602-
if (tzn!=NULL)
1603-
*tzn=NULL;
1604-
return0;
1605-
}
1606-
16071581
/*
16081582
* If the time falls within the range of pg_time_t, use pg_localtime() to
16091583
* rotate to the local time zone.
@@ -1624,8 +1598,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, const char
16241598
utime= (pg_time_t)dt;
16251599
if ((Timestamp)utime==dt)
16261600
{
1627-
structpg_tm*tx=pg_localtime(&utime,
1628-
attimezone ?attimezone :session_timezone);
1601+
structpg_tm*tx=pg_localtime(&utime,attimezone);
16291602

16301603
tm->tm_year=tx->tm_year+1900;
16311604
tm->tm_mon=tx->tm_mon+1;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,9 +2959,9 @@ SELECT '2012-12-12 12:00 America/New_York'::timestamptz;
29592959
(1 row)
29602960

29612961
SELECT to_char('2012-12-12 12:00'::timestamptz, 'YYYY-MM-DD HH:MI:SS TZ');
2962-
to_char
2963-
----------------------
2964-
2012-12-12 12:00:00
2962+
to_char
2963+
----------------------------
2964+
2012-12-12 12:00:00-01:30
29652965
(1 row)
29662966

29672967
RESET TIME ZONE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp