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

OS.get_datetime_from_unix_time() does not return the same value as OS.get_datetime() #52951

Closed
ghost opened this issue Sep 22, 2021 · 5 comments · Fixed by #54256
Closed

OS.get_datetime_from_unix_time() does not return the same value as OS.get_datetime() #52951

ghost opened this issue Sep 22, 2021 · 5 comments · Fixed by #54256

Comments

@ghost
Copy link

ghost commented Sep 22, 2021

Godot version

3.4-beta4

System information

Windows 10

Issue description

The docs for OS.get_datetime_from_unix_time() say:

The returned Dictionary's values will be the same as get_datetime, with the exception of Daylight Savings Time as it cannot be determined from the epoch.

But that's not true. Unless the 7 hours difference is because of Daylight Savings? I don't really know if this is a bug or not or intended behavior.

Steps to reproduce

  1. Make a new project.
  2. Use this code:
     func _ready() -> void:
         print(OS.get_datetime())
         print(OS.get_datetime_from_unix_time(OS.get_unix_time()))

Minimal reproduction project

No response

@akien-mga
Copy link
Member

What results fo you get? And what's your timezone?

@gelvinp
Copy link
Contributor

gelvinp commented Sep 22, 2021

Windows stores its RTC time in local time (i.e. in your time zone) while Mac and most linux systems store time in UTC. If OS.get_unix_time() is reading from this RTC then it would be 7 hours off if you were in mountain standard time, for example.

It's possible to configure windows to store UTC instead through a registry modification, but you should be careful if you want to see if that "fixes" the bug. When I get home today I can try myself and I'll report back.

I take it back, on my Mac OS machine the output of the above is:

{day:22, dst:False, hour:16, minute:3, month:9, second:49, weekday:3, year:2021}
{day:22, hour:23, minute:3, month:9, second:49, weekday:3, year:2021}

These are definitely 7 hours off. For reference my timezone is MST (-7)

@ghost
Copy link
Author

ghost commented Sep 22, 2021

My output is

{day:22, dst:False, hour:16, minute:9, month:9, second:41, weekday:3, year:2021}
{day:22, hour:23, minute:9, month:9, second:41, weekday:3, year:2021}

My timezone is PDT (-7) also.

@akien-mga
Copy link
Member

Here's what I have on Linux in CEST / UTC+2 with DST on (Summer Time), with current time 10:10 CEST / 08:10 UTC:

{day:23, dst:True, hour:10, minute:10, month:9, second:6, weekday:4, year:2021}
{day:23, hour:8, minute:10, month:9, second:6, weekday:4, year:2021}

So the output seems consistent to me, it's just the documentation which is wrong:

  • OS.get_datetime() is local time. If local timezone has DST, dst should be true.
  • OS.get_datetime_from_unix_time() gives UTC time.

One apparent issue though is that @ShatReal should have dst:True if in PDT timezone - unless the OS is not actually configured to track PST / PDT but the current local time was just hardcoded manually.

@mhilbrunner
Copy link
Member

Note: Time stuff was moved out of OS to Time in the mean time (:P): #49123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants