Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect unix_timestamp result when utc time can be mapped to multi time in one zone #59340

Open
xzhangxian1008 opened this issue Feb 8, 2025 · 1 comment
Labels
type/bug The issue is confirmed as a bug.

Comments

@xzhangxian1008
Copy link
Contributor

xzhangxian1008 commented Feb 8, 2025

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

set time_zone="Europe/Vilnius";
select unix_timestamp("2020-10-25 3:45");

2. What did you expect to see? (Required)

mysql> select unix_timestamp("2020-10-25 3:45"); 
+-----------------------------------+
| unix_timestamp("2020-10-25 3:45") |
+-----------------------------------+
|                        1603586700 |
+-----------------------------------+

3. What did you see instead (Required)

mysql> select unix_timestamp("2020-10-25 3:45");
+-----------------------------------+
| unix_timestamp("2020-10-25 3:45") |
+-----------------------------------+
|                        1603590300 |
+-----------------------------------+

Returned time should be another mapped time.

4. What is your TiDB version? (Required)

nightly(fc8bdb5)

@xzhangxian1008 xzhangxian1008 added the type/bug The issue is confirmed as a bug. label Feb 8, 2025
@Defined2014
Copy link
Contributor

Defined2014 commented Feb 10, 2025

I asked ChatGPT seems the result in TiDB is correct.


What is the Unix timestamp corresponding to 2020-10-25 03:45 in Vilnius, Lithuania?

On October 25, 2020, Lithuania (Vilnius) switched from Daylight Saving Time (EEST, UTC+3) to Standard Time (EET, UTC+2). The time change occurred at 03:00 local time, meaning the clock was set back from 03:00 to 02:00.

Key Question:

At 03:45 local time, was it still in Daylight Saving Time (UTC+3) or had it already switched to Standard Time (UTC+2)?

  • If it was still in DST (EEST, UTC+3) → The corresponding UTC time would be 2020-10-25 00:45.
  • If it was already in Standard Time (EET, UTC+2) → The corresponding UTC time would be 2020-10-25 01:45.

Now, calculating the Unix timestamps:

  • Unix timestamp 1 (UTC 00:45) → 1603586700
  • Unix timestamp 2 (UTC 01:45) → 1603590300

Since the time change occurred at 03:00, by 03:45, the region was already in Standard Time (EET, UTC+2).
Thus, the most likely Unix timestamp for 2020-10-25 03:45 (Vilnius time) is 1603590300.


What were the times before and after the time change?

On October 25, 2020, at 03:00 local time, Lithuania (Vilnius) switched from Daylight Saving Time (EEST, UTC+3) to Standard Time (EET, UTC+2). This meant that the clock was set back from 03:00 to 02:00. Below is the corresponding Unix timestamp information before and after the transition:


Before the transition (Daylight Saving Time, UTC+3)

Lithuania Time (EEST) UTC Time Unix Timestamp
2020-10-25 01:59:59 2020-10-24 22:59:59 UTC 1603576799
2020-10-25 02:00:00 2020-10-24 23:00:00 UTC 1603576800
2020-10-25 02:59:59 2020-10-24 23:59:59 UTC 1603580399
2020-10-25 03:00:00 2020-10-25 00:00:00 UTC 1603580400
(At this point, the clock is set back to 02:00:00 EET.)    

Summary

  • Before 03:00 (EEST, UTC+3), the time followed UTC+3.
  • After 03:00 (EET, UTC+2), the time followed UTC+2.
  • The local time 02:00 - 02:59 appeared twice (once in DST and once in standard time).
  • Unix timestamps remained continuous and did not repeat, but local time between 02:00 - 02:59 had two different meanings, depending on whether it was before or after the transition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

2 participants