Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix timezone offset in case of non-default timezone (#3186)
1. Issue When the default timezone is not UTC then the result shows incorrect timezone offset value with AT TIME ZONE property. This is due to the fact that the timezone offset which is calculated using input_expr_tmz which is text explicitly converted to TIMESTAMPTZ which takes into account the current session timezone setting which produces this timezone difference in the output. 2. Changes made to fix the issue We will now calculate the timezone offset with absolute value of timezone that is by subtracting the datetime value in current timezone with the value in UTC timezone. # Previous output (incorrect) 1> Select convert(datetimeoffset,'2002-01-01 02:01:00.000 +00:00') AT TIME ZONE 'eastern standard time'; 2> go timezone --------------------------------------------- 2001-12-31 21:01:00.0000000 -05:00 (1 rows affected) 1> select set_config('timezone', 'Asia/Kolkata', false) 2> go set_config ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Asia/Kolkata (1 rows affected) 1> Select convert(datetimeoffset,'2002-01-01 02:01:00.000 +00:00') AT TIME ZONE 'eastern standard time'; 2> go timezone --------------------------------------------- 2001-12-31 21:01:00.0000000 -10:30 # Current output (Correct) 1> Select convert(datetimeoffset,'2002-01-01 02:01:00.000 +00:00') AT TIME ZONE 'eastern standard time'; 2> go timezone --------------------------------------------- 2001-12-31 21:01:00.0000000 -05:00 (1 rows affected) 1> select set_config('timezone', 'Asia/Kolkata', false) 2> go set_config ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Asia/Kolkata (1 rows affected) 1> Select convert(datetimeoffset,'2002-01-01 02:01:00.000 +00:00') AT TIME ZONE 'eastern standard time'; 2> go timezone --------------------------------------------- 2001-12-31 21:01:00.0000000 -05:00 Added test cases for the issue. cherry-picked: #3174 Task: BABEL- 5316 Signed-off-by: Anikait Agrawal [email protected]
- Loading branch information