summaryrefslogtreecommitdiff
path: root/sql/item_timefunc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r--sql/item_timefunc.cc19
1 files changed, 16 insertions, 3 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index cec83428e24..7c085a1b25a 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -198,15 +198,28 @@ longlong Item_func_second::val_int()
}
-// Returns the week of year in the range of 0 - 53
+/*
+ Returns the week of year.
+
+ The bits in week_format has the following meaning:
+ 0 If not set: USA format: Sunday is first day of week
+ If set: ISO format: Monday is first day of week
+ 1 If not set: Week is in range 0-53
+ If set Week is in range 1-53.
+*/
longlong Item_func_week::val_int()
{
uint year;
+ uint week_format;
TIME ltime;
if (get_arg0_date(&ltime,0))
return 0;
- return (longlong) calc_week(&ltime, 0, args[1]->val_int() == 0, &year);
+ week_format= (uint) args[1]->val_int();
+ return (longlong) calc_week(&ltime,
+ (week_format & 2) != 0,
+ (week_format & 1) == 0,
+ &year);
}
@@ -216,7 +229,7 @@ longlong Item_func_yearweek::val_int()
TIME ltime;
if (get_arg0_date(&ltime,0))
return 0;
- week=calc_week(&ltime, 1, args[1]->val_int() == 0, &year);
+ week=calc_week(&ltime, 1, (args[1]->val_int() & 1) == 0, &year);
return week+year*100;
}