Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9dde828

Browse files
committed
Support "of", "tzh", and "tzm" format codes.
The upper case versions "OF", "TZH", and "TZM" are already supported, and all other format codes that are supported in upper case are also supported in lower case, so we should support these as well for consistency. Nitin Jadhav, with a tiny cosmetic change by me. Reviewed by Suraj Kharage and David Zhang. Discussion: http://postgr.es/m/CAMm1aWZ-oZyKd75+8D=VJ0sAoSwtdXWLP-MAWD4D8R1Dgandzw@mail.gmail.com
1 parent 705e20f commit 9dde828

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

src/backend/utils/adt/formatting.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,16 @@ typedef enum
702702
DCH_month,
703703
DCH_mon,
704704
DCH_ms,
705+
DCH_of,
705706
DCH_p_m,
706707
DCH_pm,
707708
DCH_q,
708709
DCH_rm,
709710
DCH_sssss,
710711
DCH_ssss,
711712
DCH_ss,
713+
DCH_tzh,
714+
DCH_tzm,
712715
DCH_tz,
713716
DCH_us,
714717
DCH_ww,
@@ -865,14 +868,17 @@ static const KeyWord DCH_keywords[] = {
865868
{"month", 5, DCH_month, false, FROM_CHAR_DATE_GREGORIAN},
866869
{"mon", 3, DCH_mon, false, FROM_CHAR_DATE_GREGORIAN},
867870
{"ms", 2, DCH_MS, true, FROM_CHAR_DATE_NONE},
871+
{"of", 2, DCH_OF, false, FROM_CHAR_DATE_NONE}, /* o */
868872
{"p.m.", 4, DCH_p_m, false, FROM_CHAR_DATE_NONE}, /* p */
869873
{"pm", 2, DCH_pm, false, FROM_CHAR_DATE_NONE},
870874
{"q", 1, DCH_Q, true, FROM_CHAR_DATE_NONE}, /* q */
871875
{"rm", 2, DCH_rm, false, FROM_CHAR_DATE_GREGORIAN}, /* r */
872876
{"sssss", 5, DCH_SSSS, true, FROM_CHAR_DATE_NONE}, /* s */
873877
{"ssss", 4, DCH_SSSS, true, FROM_CHAR_DATE_NONE},
874878
{"ss", 2, DCH_SS, true, FROM_CHAR_DATE_NONE},
875-
{"tz", 2, DCH_tz, false, FROM_CHAR_DATE_NONE}, /* t */
879+
{"tzh", 3, DCH_TZH, false, FROM_CHAR_DATE_NONE}, /* t */
880+
{"tzm", 3, DCH_TZM, true, FROM_CHAR_DATE_NONE},
881+
{"tz", 2, DCH_tz, false, FROM_CHAR_DATE_NONE},
876882
{"us", 2, DCH_US, true, FROM_CHAR_DATE_NONE}, /* u */
877883
{"ww", 2, DCH_WW, true, FROM_CHAR_DATE_GREGORIAN}, /* w */
878884
{"w", 1, DCH_W, true, FROM_CHAR_DATE_GREGORIAN},
@@ -954,7 +960,7 @@ static const int DCH_index[KeyWord_INDEX_SIZE] = {
954960
DCH_P_M, DCH_Q, DCH_RM, DCH_SSSSS, DCH_TZH, DCH_US, -1, DCH_WW, -1, DCH_Y_YYY,
955961
-1, -1, -1, -1, -1, -1, -1, DCH_a_d, DCH_b_c, DCH_cc,
956962
DCH_day, -1, DCH_ff1, -1, DCH_hh24, DCH_iddd, DCH_j, -1, -1, DCH_mi,
957-
-1, -1, DCH_p_m, DCH_q, DCH_rm, DCH_sssss, DCH_tz, DCH_us, -1, DCH_ww,
963+
-1, DCH_of, DCH_p_m, DCH_q, DCH_rm, DCH_sssss, DCH_tzh, DCH_us, -1, DCH_ww,
958964
-1, DCH_y_yyy, -1, -1, -1, -1
959965

960966
/*---- chars over 126 are skipped ----*/

src/test/regress/expected/timestamptz.out

+65
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,71 @@ SELECT to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM";
21662166
-04:15 | -04:15
21672167
(1 row)
21682168

2169+
RESET timezone;
2170+
-- Check of, tzh, tzm with various zone offsets.
2171+
SET timezone = '00:00';
2172+
SELECT to_char(now(), 'of') as "Of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
2173+
Of | tzh:tzm
2174+
-----+---------
2175+
+00 | +00:00
2176+
(1 row)
2177+
2178+
SET timezone = '+02:00';
2179+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
2180+
of | tzh:tzm
2181+
-----+---------
2182+
-02 | -02:00
2183+
(1 row)
2184+
2185+
SET timezone = '-13:00';
2186+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
2187+
of | tzh:tzm
2188+
-----+---------
2189+
+13 | +13:00
2190+
(1 row)
2191+
2192+
SET timezone = '-00:30';
2193+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
2194+
of | tzh:tzm
2195+
--------+---------
2196+
+00:30 | +00:30
2197+
(1 row)
2198+
2199+
SET timezone = '00:30';
2200+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
2201+
of | tzh:tzm
2202+
--------+---------
2203+
-00:30 | -00:30
2204+
(1 row)
2205+
2206+
SET timezone = '-04:30';
2207+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
2208+
of | tzh:tzm
2209+
--------+---------
2210+
+04:30 | +04:30
2211+
(1 row)
2212+
2213+
SET timezone = '04:30';
2214+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
2215+
of | tzh:tzm
2216+
--------+---------
2217+
-04:30 | -04:30
2218+
(1 row)
2219+
2220+
SET timezone = '-04:15';
2221+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
2222+
of | tzh:tzm
2223+
--------+---------
2224+
+04:15 | +04:15
2225+
(1 row)
2226+
2227+
SET timezone = '04:15';
2228+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
2229+
of | tzh:tzm
2230+
--------+---------
2231+
-04:15 | -04:15
2232+
(1 row)
2233+
21692234
RESET timezone;
21702235
CREATE TABLE TIMESTAMPTZ_TST (a int , b timestamptz);
21712236
-- Test year field value with len > 4

src/test/regress/sql/timestamptz.sql

+22
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,28 @@ SET timezone = '04:15';
360360
SELECT to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM";
361361
RESET timezone;
362362

363+
-- Check of, tzh, tzm with various zone offsets.
364+
SET timezone = '00:00';
365+
SELECT to_char(now(), 'of') as "Of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
366+
SET timezone = '+02:00';
367+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
368+
SET timezone = '-13:00';
369+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
370+
SET timezone = '-00:30';
371+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
372+
SET timezone = '00:30';
373+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
374+
SET timezone = '-04:30';
375+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
376+
SET timezone = '04:30';
377+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
378+
SET timezone = '-04:15';
379+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
380+
SET timezone = '04:15';
381+
SELECT to_char(now(), 'of') as "of", to_char(now(), 'tzh:tzm') as "tzh:tzm";
382+
RESET timezone;
383+
384+
363385
CREATE TABLE TIMESTAMPTZ_TST (a int , b timestamptz);
364386

365387
-- Test year field value with len > 4

0 commit comments

Comments
 (0)