diff options
author | unknown <pem@mysql.com> | 2003-12-19 18:03:27 +0100 |
---|---|---|
committer | unknown <pem@mysql.com> | 2003-12-19 18:03:27 +0100 |
commit | 4cd90227696cdc8dced6efec7aad9836bf93dd7c (patch) | |
tree | 00894c28662192eed25fdacc555298265a2880ac /sql/item_timefunc.cc | |
parent | 58a52a2a84eafe535317a533af56a81d81a8fd56 (diff) | |
parent | bfe77e3398944bed4c919ba0c7477a4318d9f2cc (diff) | |
download | mariadb-git-4cd90227696cdc8dced6efec7aad9836bf93dd7c.tar.gz |
Merge 4.1 to 5.0.
BitKeeper/etc/logging_ok:
auto-union
client/mysql.cc:
Auto merged
configure.in:
Auto merged
client/mysqltest.c:
Auto merged
include/my_global.h:
Auto merged
include/my_pthread.h:
Auto merged
include/mysql_com.h:
Auto merged
libmysql/libmysql.c:
Auto merged
libmysqld/lib_sql.cc:
Auto merged
myisam/mi_check.c:
Auto merged
mysql-test/r/insert.result:
Auto merged
mysql-test/r/join_outer.result:
Auto merged
mysql-test/r/multi_update.result:
Auto merged
mysql-test/r/query_cache.result:
Auto merged
mysql-test/r/symlink.result:
Auto merged
mysql-test/t/func_time.test:
Auto merged
mysql-test/t/insert.test:
Auto merged
mysql-test/t/multi_update.test:
Auto merged
mysql-test/t/query_cache.test:
Auto merged
sql/ha_innodb.cc:
Auto merged
sql/item.cc:
Auto merged
sql/item.h:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_func.cc:
Auto merged
sql/item_func.h:
Auto merged
sql/item_subselect.cc:
Auto merged
sql/item_sum.cc:
Auto merged
sql/item_sum.h:
Auto merged
sql/item_timefunc.cc:
Auto merged
sql/lex.h:
Auto merged
sql/log.cc:
Auto merged
sql/log_event.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/mysqld.cc:
Auto merged
sql/opt_range.cc:
Auto merged
sql/records.cc:
Auto merged
sql/repl_failsafe.cc:
Auto merged
sql/set_var.cc:
Auto merged
sql/slave.cc:
Auto merged
sql/sql_acl.h:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_cache.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_db.cc:
Auto merged
sql/sql_delete.cc:
Auto merged
sql/sql_insert.cc:
Auto merged
sql/sql_load.cc:
Auto merged
sql/sql_prepare.cc:
Auto merged
sql/sql_rename.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_show.cc:
Auto merged
sql/sql_update.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
sql/table.h:
Auto merged
sql/share/czech/errmsg.txt:
Auto merged
sql/share/romanian/errmsg.txt:
Auto merged
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r-- | sql/item_timefunc.cc | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 7936006acc4..ae9d2be80f6 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -526,8 +526,11 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, uint year; if (type == TIMESTAMP_TIME) return 1; - length= int10_to_str(calc_week(l_time, 0, (*ptr) == 'U', &year), - intbuff, 10) - intbuff; + length= int10_to_str(calc_week(l_time, + (*ptr) == 'U' ? + WEEK_FIRST_WEEKDAY : WEEK_MONDAY_FIRST, + &year), + intbuff, 10) - intbuff; str->append_with_prefill(intbuff, length, 2, '0'); } break; @@ -537,8 +540,12 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, uint year; if (type == TIMESTAMP_TIME) return 1; - length= int10_to_str(calc_week(l_time, 1, (*ptr) == 'V', &year), - intbuff, 10) - intbuff; + length= int10_to_str(calc_week(l_time, + ((*ptr) == 'V' ? + (WEEK_YEAR | WEEK_FIRST_WEEKDAY) : + (WEEK_YEAR | WEEK_MONDAY_FIRST)), + &year), + intbuff, 10) - intbuff; str->append_with_prefill(intbuff, length, 2, '0'); } break; @@ -548,7 +555,11 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, uint year; if (type == TIMESTAMP_TIME) return 1; - (void) calc_week(l_time, 1, (*ptr) == 'X', &year); + (void) calc_week(l_time, + ((*ptr) == 'X' ? + WEEK_YEAR | WEEK_FIRST_WEEKDAY : + WEEK_YEAR | WEEK_MONDAY_FIRST), + &year); length= int10_to_str(year, intbuff, 10) - intbuff; str->append_with_prefill(intbuff, length, 4, '0'); } @@ -718,27 +729,51 @@ longlong Item_func_second::val_int() } -/* - Returns the week of year. +uint week_mode(uint mode) +{ + uint week_format= (mode & 7); + if (!(week_format & WEEK_MONDAY_FIRST)) + week_format^= WEEK_FIRST_WEEKDAY; + return week_format; +} - 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. +/* + The bits in week_format(for calc_week() function) has the following meaning: + WEEK_MONDAY_FIRST (0) If not set Sunday is first day of week + If set Monday is first day of week + WEEK_YEAR (1) If not set Week is in range 0-53 + + Week 0 is returned for the the last week of the previous year (for + a date at start of january) In this case one can get 53 for the + first week of next year. This flag ensures that the week is + relevant for the given year. Note that this flag is only + releveant if WEEK_JANUARY is not set. + + If set Week is in range 1-53. + + In this case one may get week 53 for a date in January (when + the week is that last week of previous year) and week 1 for a + date in December. + + WEEK_FIRST_WEEKDAY (2) If not set Weeks are numbered according + to ISO 8601:1988 + If set The week that contains the first + 'first-day-of-week' is week 1. + + ISO 8601:1988 means that if the week containing January 1 has + four or more days in the new year, then it is week 1; + Otherwise it is the last week of the previous year, and the + next week is week 1. */ longlong Item_func_week::val_int() { uint year; - uint week_format; TIME ltime; if (get_arg0_date(<ime,0)) return 0; - week_format= (uint) args[1]->val_int(); - return (longlong) calc_week(<ime, - (week_format & 2) != 0, - (week_format & 1) == 0, + return (longlong) calc_week(<ime, + week_mode((uint) args[1]->val_int()), &year); } @@ -749,7 +784,9 @@ longlong Item_func_yearweek::val_int() TIME ltime; if (get_arg0_date(<ime,0)) return 0; - week=calc_week(<ime, 1, (args[1]->val_int() & 1) == 0, &year); + week= calc_week(<ime, + (week_mode((uint) args[1]->val_int()) | WEEK_YEAR), + &year); return week+year*100; } |