summaryrefslogtreecommitdiff
path: root/sql/time.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/time.cc')
-rw-r--r--sql/time.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/sql/time.cc b/sql/time.cc
index 1d7e055f682..e4565bdeea7 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -24,7 +24,7 @@ static ulong const days_at_timestart=719528; /* daynr at 1970.01.01 */
uchar *days_in_month= (uchar*) "\037\034\037\036\037\036\037\037\036\037\036\037";
- /* Init some variabels neaded when using my_local_time */
+ /* Init some variabels needed when using my_local_time */
/* Currently only my_time_zone is inited */
static long my_time_zone=0;
@@ -176,7 +176,9 @@ uint calc_week(TIME *l_time, bool with_year, bool sunday_first_day_of_week,
ulong first_daynr=calc_daynr(l_time->year,1,1);
uint weekday=calc_weekday(first_daynr,sunday_first_day_of_week);
*year=l_time->year;
- if (l_time->month == 1 && weekday >= 4 && l_time->day <= 7-weekday)
+ if (l_time->month == 1 && l_time->day <= 7-weekday &&
+ ((!sunday_first_day_of_week && weekday >= 4) ||
+ (sunday_first_day_of_week && weekday != 0)))
{
/* Last week of the previous year */
if (!with_year)
@@ -186,7 +188,8 @@ uint calc_week(TIME *l_time, bool with_year, bool sunday_first_day_of_week,
first_daynr-= (days=calc_days_in_year(*year));
weekday= (weekday + 53*7- days) % 7;
}
- if (weekday >= 4)
+ if ((sunday_first_day_of_week && weekday != 0) ||
+ (!sunday_first_day_of_week && weekday >= 4))
days= daynr - (first_daynr+ (7-weekday));
else
days= daynr - (first_daynr - weekday);