Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-40359

FROM_UNIXTIME() outputs wrong time around DST changeover

    XMLWordPrintable

Details

    • Can result in unexpected behaviour

    Description

      `FROM_UNIXTIME` is documented to use the system's formatter in certain cases, but it somehow manages to produce wrong results where other programs using the system's formatter do not.

      If your session time zone is set to SYSTEM (the default), FROM_UNIXTIME() will call the OS function to convert the data using the system time zone. At least on Linux, the corresponding function (localtime_r)...

      {{
      MariaDB [test]> SELECT @@system_time_zone, @@global.time_zone, @@session.time_zone, FROM_UNIXTIME(1603584000, '%Y-%m-%d %H:%i:%s %z'), FROM_UNIXTIME(1603587600, '%Y-%m-%d %H:%i:%s %z');
      -----------------------------------------------------------------------------------------------------------------------------------------------------------

      @@system_time_zone @@global.time_zone @@session.time_zone FROM_UNIXTIME(1603584000, '%Y-%m-%d %H:%i:%s %z') FROM_UNIXTIME(1603587600, '%Y-%m-%d %H:%i:%s %z')

      -----------------------------------------------------------------------------------------------------------------------------------------------------------

      CEST SYSTEM SYSTEM 2020-10-25 02:00:00 +0100 2020-10-25 02:00:00 +0100

      -----------------------------------------------------------------------------------------------------------------------------------------------------------
      1 row in set (0,000 sec)
      }}

      Notice the 4th column show the wrong time for 1603584000.

      The system produces the correct representations for the same epochs:
      {{
      $ date d @1603584000 '+%Y%m-%d %H:%M:%S %z'
      2020-10-25 02:00:00 +0200
      $ date d @1603587600 '+%Y%m-%d %H:%M:%S %z'
      2020-10-25 02:00:00 +0100
      }}

      Attachments

        Activity

          People

            raghunandan.bhat Raghunandan Bhat
            alexh Alex
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 0d
                0d
                Remaining:
                Remaining Estimate - 2d
                2d
                Logged:
                Time Spent - Not Specified
                Not Specified

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.