magic number super fun happy time

umm…..

int Field_timestamp::store(double nr)
{
  int error= 0;
  if (nr < 0 || nr > 99991231235959.0)
  {
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
                         ER_WARN_DATA_OUT_OF_RANGE,
                         nr, DRIZZLE_TIMESTAMP_DATETIME);
    nr= 0;					// Avoid overflow on buff
    error= 1;
  }
  error|= Field_timestamp::store((int64_t) rint(nr), false);
  return error;
}

(likely the same in mysql as well… haven’t checked though). these date and time things scare me.

4 thoughts on “magic number super fun happy time

  1. No such happy ‘magic number’ in mysql… sql/field.cc

    int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs)
    {

    MYSQL_TIME l_time;
    my_time_t tmp= 0;
    int error;
    bool have_smth_to_conv;
    my_bool in_dst_time_gap;
    THD *thd= table ? table->in_use : current_thd;

    /* We don’t want to store invalid or fuzzy datetime values in TIMESTAMP */
    have_smth_to_conv= (str_to_datetime(from, len, &l_time,
    (thd->variables.sql_mode &
    MODE_NO_ZERO_DATE) |
    MODE_NO_ZERO_IN_DATE, &error) >
    MYSQL_TIMESTAMP_ERROR);

    if (error || !have_smth_to_conv)
    {
    error= 1;
    set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
    from, len, MYSQL_TIMESTAMP_DATETIME, 1);
    }

    /* Only convert a correct date (not a zero date) */
    if (have_smth_to_conv && l_time.month)
    {
    if (!(tmp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap)))
    {
    set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
    ER_WARN_DATA_OUT_OF_RANGE,
    from, len, MYSQL_TIMESTAMP_DATETIME, !error);
    error= 1;
    }

  2. What’s magic about it ?
    It’s 9999-12-31 23:59:59, pretty reasonable limit for a date.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.