Skip to content

Commit 6f55cb4

Browse files
vuvovamariadb-RuchaDeodhar
authored andcommitted
MDEV-31684 post-review changes
1 parent 94eb819 commit 6f55cb4

File tree

7 files changed

+104
-133
lines changed

7 files changed

+104
-133
lines changed

mysql-test/main/date_formats.result

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,10 @@ select time_format('2001-01-01 02:02:02', '%T');
556556
time_format('2001-01-01 02:02:02', '%T')
557557
02:02:02
558558
#
559-
# Beginning of 11.3 test
559+
# End of 10.2 test
560560
#
561-
# MDEV-31684: Add timezone information to DATE_FORMAT
561+
#
562+
# MDEV-31684 Add timezone information to DATE_FORMAT
562563
#
563564
SET @old_timezone= @@time_zone;
564565
# Using named timezones
@@ -590,14 +591,7 @@ SET TIME_ZONE='UTC';
590591
SELECT DATE_FORMAT('2009-10-04 22:23:00', '%z %Z') AS current_timezone;
591592
current_timezone
592593
+0000 UTC
593-
# using system time
594-
#
595-
# output depends on system time information. Hence replacing
596-
# to avoid result diff test failures.
597-
#
598-
SET @@time_zone= default;
599-
SELECT DATE_FORMAT('2009-10+|-HH:MM ABC22:23:00', '%z %Z') AS current_timezone;
600-
current_timezone
601-
+|-HH:MM ABC
602594
SET @@time_zone= @old_timezone;
595+
#
603596
# End of 11.3 test
597+
#

mysql-test/main/date_formats.test

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,11 @@ select time_format('01 02:02:02', '%T');
258258
select time_format('2001-01-01 02:02:02', '%T');
259259

260260
--echo #
261-
--echo # Beginning of 11.3 test
261+
--echo # End of 10.2 test
262262
--echo #
263-
--echo # MDEV-31684: Add timezone information to DATE_FORMAT
263+
264+
--echo #
265+
--echo # MDEV-31684 Add timezone information to DATE_FORMAT
264266
--echo #
265267

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

293-
--echo # using system time
294-
--echo #
295-
--echo # output depends on system time information. Hence replacing
296-
--echo # to avoid result diff test failures.
297-
--echo #
298-
299-
SET @@time_zone= default;
300-
301-
--replace_regex /[+-][0-9]* [A-Z]*/+|-HH:MM ABC/
302-
SELECT DATE_FORMAT('2009-10-04 22:23:00', '%z %Z') AS current_timezone;
303-
304295
SET @@time_zone= @old_timezone;
305296

297+
--echo #
306298
--echo # End of 11.3 test
299+
--echo #

mysql-test/main/timezone.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@ alter table mysql.time_zone_transition_type add primary key (time_zone_id,transi
7575
#
7676
# End of 10.8 tests
7777
#
78+
#
79+
# MDEV-31684 Add timezone information to DATE_FORMAT
80+
#
81+
# using system time
82+
SET @@time_zone= default;
83+
SELECT DATE_FORMAT('2009-11-01 22:23:00', '%z %Z') AS current_timezone;
84+
current_timezone
85+
+0100 MET
86+
SELECT DATE_FORMAT('2008-06-04 02:23:00', '%z %Z') AS current_timezone;
87+
current_timezone
88+
+0200 MEST

mysql-test/main/timezone.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,12 @@ alter table mysql.time_zone_transition_type add primary key (time_zone_id,transi
7474
--echo #
7575
--echo # End of 10.8 tests
7676
--echo #
77+
78+
--echo #
79+
--echo # MDEV-31684 Add timezone information to DATE_FORMAT
80+
--echo #
81+
82+
--echo # using system time
83+
SET @@time_zone= default;
84+
SELECT DATE_FORMAT('2009-11-01 22:23:00', '%z %Z') AS current_timezone;
85+
SELECT DATE_FORMAT('2008-06-04 02:23:00', '%z %Z') AS current_timezone;

sql/item_timefunc.cc

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -482,15 +482,8 @@ static bool make_date_time(THD *thd, const String *format,
482482
uint weekday;
483483
ulong length;
484484
const char *ptr, *end;
485-
int diff_hr=0, diff_min=0;
486-
char abbrevation[8];
487-
struct tz tmp;
488-
tmp.is_inited= false;
489-
490-
Time_zone* curr_timezone= my_tz_find(thd,
491-
thd->variables.time_zone->get_name());
492-
memset(abbrevation, 0, sizeof(abbrevation));
493-
485+
struct tz curr_tz;
486+
Time_zone* curr_timezone= 0;
494487

495488
str->length(0);
496489

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

711704
case 'z':
712705
{
713-
if (!tmp.is_inited)
706+
if (!curr_timezone)
714707
{
715-
curr_timezone->get_timezone_information(&tmp, l_time);
716-
tmp.is_inited= true;
708+
curr_timezone= thd->variables.time_zone;
709+
curr_timezone->get_timezone_information(&curr_tz, l_time);
717710
}
718-
ulonglong seconds= abs(tmp.seconds_offset);
719-
diff_hr= (int)(seconds/3600L);
720-
int temp= (int)(seconds%3600L);
721-
diff_min= temp/60L;
722-
723-
if (tmp.is_behind)
724-
str->append("-", 1);
725-
else
726-
str->append("+", 1);
727-
728-
if (diff_hr/10 == 0)
729-
str->append("0", 1);
730-
length= (uint) (int10_to_str(diff_hr, intbuff, 10) - intbuff);
731-
str->append(intbuff, length);
732-
if (diff_min/10 == 0)
733-
str->append("0", 1);
734-
length= (uint) (int10_to_str(diff_min, intbuff, 10) - intbuff);
735-
str->append(intbuff, length);
736-
}
711+
long minutes= labs(curr_tz.seconds_offset)/60, diff_hr, diff_min;
712+
diff_hr= minutes/60;
713+
diff_min= minutes%60;
714+
715+
str->append(curr_tz.seconds_offset < 0 ? '-' : '+');
716+
str->append(static_cast<char>('0' + diff_hr/10));
717+
str->append(static_cast<char>('0' + diff_hr%10));
718+
str->append(static_cast<char>('0' + diff_min/10));
719+
str->append(static_cast<char>('0' + diff_min%10));
737720
break;
738-
721+
}
739722
case 'Z':
740-
{
741-
if (!tmp.is_inited)
723+
if (!curr_timezone)
742724
{
743-
curr_timezone->get_timezone_information(&tmp, l_time);
744-
tmp.is_inited= true;
725+
curr_timezone= thd->variables.time_zone;
726+
curr_timezone->get_timezone_information(&curr_tz, l_time);
745727
}
746-
str->append(tmp.abbrevation, strlen(tmp.abbrevation));
747-
}
728+
str->append(curr_tz.abbrevation, strlen(curr_tz.abbrevation));
748729
break;
749730
default:
750731
str->append(*ptr);
@@ -1874,6 +1855,7 @@ uint Item_func_date_format::format_length(const String *format)
18741855
case 'X': /* Year, used with 'v, where week starts with Monday' */
18751856
size += 4;
18761857
break;
1858+
case 'Z': /* time zone abbreviation */
18771859
case 'a': /* locale's abbreviated weekday name (Sun..Sat) */
18781860
case 'b': /* locale's abbreviated month name (Jan.Dec) */
18791861
size += 32; /* large for UTF8 locale data */
@@ -1912,6 +1894,9 @@ uint Item_func_date_format::format_length(const String *format)
19121894
case 'f': /* microseconds */
19131895
size += 6;
19141896
break;
1897+
case 'z': /* time zone offset */
1898+
size += 5;
1899+
break;
19151900
case 'w': /* day (of the week), numeric */
19161901
case '%':
19171902
default:

0 commit comments

Comments
 (0)