• unknown's avatar
    Bug#18997: DATE_ADD and DATE_SUB perform year2K autoconversion magic on 4-digit year value · b41b0fd6
    unknown authored
    if input year for date_add() / date_sub() with INTERVAL is low enough for
    calc_daynr() to possibly return incorrect results (calc_daynr() has no information
    on whether the year is low because it was a two-digit year ('77) or because it
    was a really low four-digit year (0077) and will indiscriminately try to turn the
    value into a four-digit year by adding 1900 or 2000 respectively), the functions
    will now throw NULL.
    
    
    include/my_time.h:
      new define YY_MAGIC_BELOW: if year is below this threshold, magic kicks in in
      calc_daynr(). the idea is to convert two-digit years to four-digit ones, adding
      1900 to values >= YY_PART_YEAR or adding 2000 otherwise.
      current value of YY_MAGIC_BELOW derived from original code in calc_daynr()
    mysql-test/r/func_time.result:
      test where 2 digit -> 4 digit year magic kicks in, and whether we throw NULL when
      it happens
    mysql-test/t/func_time.test:
      test where 2 digit -> 4 digit year magic kicks in, and whether we throw NULL when
      it happens
    sql-common/my_time.c:
      use new const YY_MAGIC_BELOW, apply 2-digit -> 4-digit magic only to years
      below this threshold.
    sql/item_timefunc.cc:
      throw NULL when year in date_add() / date_sub() would be affected by
      2 digit -> 4 digit magic.
    b41b0fd6
func_time.test 23.2 KB