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

DateTime to_time does not preserve UTC-ness #4784

Closed
headius opened this issue Sep 7, 2017 · 3 comments
Closed

DateTime to_time does not preserve UTC-ness #4784

headius opened this issue Sep 7, 2017 · 3 comments

Comments

@headius
Copy link
Member

@headius headius commented Sep 7, 2017

I am excluding some Psych tests from 2.2.4 that have not been updated for Ruby 2.4 changes to DateTime#to_time. These tests are fixed on Psych master but we can't update them until there's a non-beta Psych release.

  1) Failure:
Psych::JSON::TestStream#test_datetime [/home/travis/build/jruby/jruby/test/mri/psych/json/test_stream.rb:106]:
Expected /\{"a":\ "2010\-10\-10\ 00:00:00\.000000000\ \+00:00"\}\n/ to match "--- {\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n...\n".

  2) Failure:
Psych::TestJSONTree#test_datetime [/home/travis/build/jruby/jruby/test/mri/psych/test_json_tree.rb:63]:
--- expected
+++ actual
@@ -1,2 +1,2 @@
-"{\"a\": \"2010-10-10 00:00:00.000000000 +00:00\"}
+"{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}
 "
@headius
Copy link
Member Author

@headius headius commented May 16, 2018

Psych 3.0.2 will ship with JRuby 9.2.

@headius headius closed this May 16, 2018
@kares
Copy link
Member

@kares kares commented Feb 1, 2019

still an issue when run on a UTC system (Travis CI) :

     [exec]   1) Failure:
     [exec] Psych::TestJSONTree#test_datetime [/home/travis/build/kares/jruby/test/mri/psych/test_json_tree.rb:63]:
     [exec] --- expected
     [exec] +++ actual
     [exec] @@ -1,2 +1,2 @@
     [exec] -"{\"a\": \"2010-10-10 00:00:00.000000000 +00:00\"}
     [exec] +"{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}

.. the problem seems to be Psych JRuby incompatibility, to be handled at the psych repository.

here's a reproducer, under MRI 2.5.3 :

$ ruby -e 'require "psych"; require "date"; time = Time.utc(2010, 10, 10).to_datetime; p time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z"); p Psych.to_json({"a" => time })'
"2010-10-10 00:00:00.000000000 +00:00"
"{\"a\": \"2010-10-10 00:00:00.000000000 +00:00\"}\n"

JRuby 9.2.5 (and current master - 9.2.6 target) :

bin/jruby -e 'require "psych"; require "date"; time = Time.utc(2010, 10, 10).to_datetime; p time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z"); p Psych.to_json({"a" => time })'
"2010-10-10 00:00:00.000000000 +00:00"
"{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n"
@kares kares reopened this Feb 1, 2019
@kares kares removed this from the JRuby 9.2.0.0 milestone Feb 1, 2019
@kares kares changed the title Psych needs update once 3.0.0 is released Psych UTC DateTime formatting incompatibility Feb 1, 2019
@dr-itz
Copy link
Contributor

@dr-itz dr-itz commented Feb 1, 2019

I think Psych is innocent here. Run this on JRuby and MRI to see the difference:

ruby -e "require 'time'; p Time.utc(2010, 10, 10).to_datetime.to_time.utc?"

JRuby gives true, MRI false...and this triggers the different formatting in Psych

@kares kares changed the title Psych UTC DateTime formatting incompatibility DateTime to_time does not preserve UTC-ness Feb 2, 2019
dr-itz added a commit to dr-itz/jruby that referenced this issue Feb 3, 2019
Keep/adjust value of isTzRelative where required.

In Time:
* op_plus, op_minus
* clone
* localtime, gmtime/utc
* succ

In DateTime:
* to_time is always relative in MRI

Fixes jruby#4784
@enebo enebo closed this in #5589 Feb 4, 2019
@enebo enebo added this to the JRuby 9.2.6.0 milestone Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.