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

Time object returned by File#mtime doesn't honor TZ environment variable on Windows #6659

Closed
mojavelinux opened this issue Apr 16, 2021 · 4 comments

Comments

@mojavelinux
Copy link

Environment Information

  • JRuby version: 9.2.17.0
  • JRUBY_OPTS: none
  • Operating system and platform: Windows
  • Installed gems: n/a
  • Environment variables: TZ=UTC

Expected Behavior

To match CRuby, File#mtime (and related methods) should honor the TZ environment variable, just like Time.now. This works correctly on Linux. The behavior differs on Windows. Time.now honors the TZ environment variable, whereas File#mtime does not.

Here's an example script to demonstrate the issue:

puts File.open('test.rb') {|f| f.mtime }.utc_offset
puts Time.now.utc_offset
puts Time.at(0).utc_offset

Actual Behavior

If you run the script without setting the TZ environment variable, you will get your local utc offset (assuming, of course, your system time is not already set to UTC).

set TZ=
jruby test.rb
#=> -21600
#=> -21600
#=> -25200

If you run the script with TZ=UTC, you should see 0 for all three values. However, on JRuby for Windows, the first value is not 0.

set TZ=UTC
jruby test.rb
#=> -21600
#=> 0
#=> 0

Here's the result you get on JRuby for Linux, consistent with CRuby.

TZ=UTC jruby test.rb
#=> 0
#=> 0
#=> 0
@mojavelinux
Copy link
Author

There is a workaround. You can retrieve the timestamp from the Time object and run it through Time.at:

Time.at(File.open('test.rb') {|f| f.mtime }.to_i).utc_offset

@ladybando
Copy link

I am a beginner and would like to work on this. To be clear, are you looking to implement the workaround or find a solution to why it is not returning what is expected on a Windows machine?

@headius headius added this to the JRuby 9.2.19.0 milestone Jun 15, 2021
@headius
Copy link
Member

headius commented Jun 15, 2021

Fixed in #6720.

@headius headius closed this as completed Jun 15, 2021
@headius
Copy link
Member

headius commented Jun 15, 2021

@ladybando Sorry we never saw your comment! I encourage you to look at other issues or stop by our chat (http://jruby.org/chat) if you are still interested in helping out.

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

No branches or pull requests

4 participants