Skip to content

Commit

Permalink
MDEV-31684 post-review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvova authored and mariadb-RuchaDeodhar committed Oct 11, 2023
1 parent 94eb819 commit 6f55cb4
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 133 deletions.
16 changes: 5 additions & 11 deletions mysql-test/main/date_formats.result
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,10 @@ select time_format('2001-01-01 02:02:02', '%T');
time_format('2001-01-01 02:02:02', '%T')
02:02:02
#
# Beginning of 11.3 test
# End of 10.2 test
#
# MDEV-31684: Add timezone information to DATE_FORMAT
#
# MDEV-31684 Add timezone information to DATE_FORMAT
#
SET @old_timezone= @@time_zone;
# Using named timezones
Expand Down Expand Up @@ -590,14 +591,7 @@ SET TIME_ZONE='UTC';
SELECT DATE_FORMAT('2009-10-04 22:23:00', '%z %Z') AS current_timezone;
current_timezone
+0000 UTC
# using system time
#
# output depends on system time information. Hence replacing
# to avoid result diff test failures.
#
SET @@time_zone= default;
SELECT DATE_FORMAT('2009-10+|-HH:MM ABC22:23:00', '%z %Z') AS current_timezone;
current_timezone
+|-HH:MM ABC
SET @@time_zone= @old_timezone;
#
# End of 11.3 test
#
19 changes: 6 additions & 13 deletions mysql-test/main/date_formats.test
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ select time_format('01 02:02:02', '%T');
select time_format('2001-01-01 02:02:02', '%T');

--echo #
--echo # Beginning of 11.3 test
--echo # End of 10.2 test
--echo #
--echo # MDEV-31684: Add timezone information to DATE_FORMAT

--echo #
--echo # MDEV-31684 Add timezone information to DATE_FORMAT
--echo #

SET @old_timezone= @@time_zone;
Expand Down Expand Up @@ -290,17 +292,8 @@ SELECT DATE_FORMAT('2009-10-04 22:23:00', '%z %Z') AS current_timezone;
SET TIME_ZONE='UTC';
SELECT DATE_FORMAT('2009-10-04 22:23:00', '%z %Z') AS current_timezone;

--echo # using system time
--echo #
--echo # output depends on system time information. Hence replacing
--echo # to avoid result diff test failures.
--echo #

SET @@time_zone= default;

--replace_regex /[+-][0-9]* [A-Z]*/+|-HH:MM ABC/
SELECT DATE_FORMAT('2009-10-04 22:23:00', '%z %Z') AS current_timezone;

SET @@time_zone= @old_timezone;

--echo #
--echo # End of 11.3 test
--echo #
11 changes: 11 additions & 0 deletions mysql-test/main/timezone.result
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,14 @@ alter table mysql.time_zone_transition_type add primary key (time_zone_id,transi
#
# End of 10.8 tests
#
#
# MDEV-31684 Add timezone information to DATE_FORMAT
#
# using system time
SET @@time_zone= default;
SELECT DATE_FORMAT('2009-11-01 22:23:00', '%z %Z') AS current_timezone;
current_timezone
+0100 MET
SELECT DATE_FORMAT('2008-06-04 02:23:00', '%z %Z') AS current_timezone;
current_timezone
+0200 MEST
9 changes: 9 additions & 0 deletions mysql-test/main/timezone.test
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ alter table mysql.time_zone_transition_type add primary key (time_zone_id,transi
--echo #
--echo # End of 10.8 tests
--echo #

--echo #
--echo # MDEV-31684 Add timezone information to DATE_FORMAT
--echo #

--echo # using system time
SET @@time_zone= default;
SELECT DATE_FORMAT('2009-11-01 22:23:00', '%z %Z') AS current_timezone;
SELECT DATE_FORMAT('2008-06-04 02:23:00', '%z %Z') AS current_timezone;
61 changes: 23 additions & 38 deletions sql/item_timefunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,8 @@ static bool make_date_time(THD *thd, const String *format,
uint weekday;
ulong length;
const char *ptr, *end;
int diff_hr=0, diff_min=0;
char abbrevation[8];
struct tz tmp;
tmp.is_inited= false;

Time_zone* curr_timezone= my_tz_find(thd,
thd->variables.time_zone->get_name());
memset(abbrevation, 0, sizeof(abbrevation));

struct tz curr_tz;
Time_zone* curr_timezone= 0;

str->length(0);

Expand Down Expand Up @@ -710,41 +703,29 @@ static bool make_date_time(THD *thd, const String *format,

case 'z':
{
if (!tmp.is_inited)
if (!curr_timezone)
{
curr_timezone->get_timezone_information(&tmp, l_time);
tmp.is_inited= true;
curr_timezone= thd->variables.time_zone;
curr_timezone->get_timezone_information(&curr_tz, l_time);
}
ulonglong seconds= abs(tmp.seconds_offset);
diff_hr= (int)(seconds/3600L);
int temp= (int)(seconds%3600L);
diff_min= temp/60L;

if (tmp.is_behind)
str->append("-", 1);
else
str->append("+", 1);

if (diff_hr/10 == 0)
str->append("0", 1);
length= (uint) (int10_to_str(diff_hr, intbuff, 10) - intbuff);
str->append(intbuff, length);
if (diff_min/10 == 0)
str->append("0", 1);
length= (uint) (int10_to_str(diff_min, intbuff, 10) - intbuff);
str->append(intbuff, length);
}
long minutes= labs(curr_tz.seconds_offset)/60, diff_hr, diff_min;
diff_hr= minutes/60;
diff_min= minutes%60;

str->append(curr_tz.seconds_offset < 0 ? '-' : '+');
str->append(static_cast<char>('0' + diff_hr/10));
str->append(static_cast<char>('0' + diff_hr%10));
str->append(static_cast<char>('0' + diff_min/10));
str->append(static_cast<char>('0' + diff_min%10));
break;

}
case 'Z':
{
if (!tmp.is_inited)
if (!curr_timezone)
{
curr_timezone->get_timezone_information(&tmp, l_time);
tmp.is_inited= true;
curr_timezone= thd->variables.time_zone;
curr_timezone->get_timezone_information(&curr_tz, l_time);
}
str->append(tmp.abbrevation, strlen(tmp.abbrevation));
}
str->append(curr_tz.abbrevation, strlen(curr_tz.abbrevation));
break;
default:
str->append(*ptr);
Expand Down Expand Up @@ -1874,6 +1855,7 @@ uint Item_func_date_format::format_length(const String *format)
case 'X': /* Year, used with 'v, where week starts with Monday' */
size += 4;
break;
case 'Z': /* time zone abbreviation */
case 'a': /* locale's abbreviated weekday name (Sun..Sat) */
case 'b': /* locale's abbreviated month name (Jan.Dec) */
size += 32; /* large for UTF8 locale data */
Expand Down Expand Up @@ -1912,6 +1894,9 @@ uint Item_func_date_format::format_length(const String *format)
case 'f': /* microseconds */
size += 6;
break;
case 'z': /* time zone offset */
size += 5;
break;
case 'w': /* day (of the week), numeric */
case '%':
default:
Expand Down

0 comments on commit 6f55cb4

Please sign in to comment.