Comments (11)
Closed the pull request as it does not fix the problem.
from nori.
it does not?
from nori.
I'm still seeing this problem too.
Im using v 1.1.3
In my XML trace I see:
2012-09-11T17:30:00
In the hash:
:date_begin=>Tue, 11 Sep 2012 17:30:00 +0000
from nori.
For any folks struggling with this, I put the following hack in my code:
def tz_fix(datetime)
offset=(Time.now.utc_offset/3600).to_s
dt=datetime.change( :offset => (offset))
end
Then on any objects I get back I do
e[:date_start]=tz_fix(e[:date_start]
messy but it works
from nori.
Any update on this? I think the code in robuye/nori@505e68f look pretty solid. Is/was it working for you @robuye?
from nori.
This hack worked for me in a Rails application. You can substitute with any other implementation.
I'd prefer to have this a lot easier right out of the box (default_to_utc: false
option, perhaps?).
config/initializers/nori_overrides.rb
# Make Nori (the XML parser used by wash_out for SOAP API) use Rails' TZ support
module NoriAdvancedTypecastingWithTimeZone
def advanced_typecasting(value)
if value.strip =~ Nori::XMLUtilityNode::XS_DATE_TIME
try_to_convert(value) { |x| Time.zone.parse(x) }
else
super
end
end
end
class Nori::XMLUtilityNode
typecasts["dateTime"] = ->(value) { Time.zone.parse(value) if value.present? }
typecasts["datetime"] = typecasts["dateTime"]
prepend NoriAdvancedTypecastingWithTimeZone
end
And tests, to make sure my monkey patch does not break / actually works:
# Nori is used by wash_out to parse SOAP XML into Ruby hashes.
# We have to patch in Rails' timezone support in an initializer.
describe "parsing XML using Nori" do
let(:nori) { Nori.new(advanced_typecasting: true) }
describe "with type attributes" do
it "parses dateTimes in the given zone" do
Time.use_zone("Europe/Helsinki") do # +03:00 in the summer
result = nori.parse('<time type="datetime">2016-07-07T12:00:10+02:00</time>')
result["time"].should == Time.zone.parse("2016-07-07T12:00:10+02:00")
end
end
it "defaults dateTimes to Time.zone if no TZ is given" do
Time.use_zone("Europe/Helsinki") do # +03:00 in the summer
result = nori.parse('<time type="datetime">2016-07-07T12:00:10</time>')
result["time"].should == Time.zone.parse("2016-07-07T12:00:10+03:00")
end
end
end
describe "without type attribute" do
it "parses time-like strings in the given zone" do
Time.use_zone("Europe/Helsinki") do # +03:00 in the summer
result = nori.parse("<time> 2016-07-07T12:00:10+02:00 </time>")
result["time"].should == Time.zone.parse("2016-07-07T12:00:10+02:00")
end
end
it "defaults time-like strings to Time.zone if no TZ is given" do
Time.use_zone("Europe/Helsinki") do # +03:00 in the summer
result = nori.parse("<time> 2016-07-07T12:00:10 </time>")
result["time"].should == Time.zone.parse("2016-07-07T12:00:10+03:00")
end
end
end
end
from nori.
Hi @Mange
I never had this problem myself, simply made a commit to address an existing issue, but I can't confirm if and how it behaves in production environment. I'm also long gone from the project we used Nori (tho afaik it's solid and still in use). I'm not sure I can be of any help here, sorry.
from nori.
Thank you for the update, @robuye.
from nori.
Thanks for the monkeypatch, @Mange, it works fine! I'm experiencing the same issues with an API that yields timestamps like '2014-01-03T01:00:00'.
I will be using this in production. Is there any chance this will be fixed, or should I create a swanky-nori fork instead?
from nori.
We've been using this in production since this PR was opened and it's worked well for us. You should fork your own copy since we're going to remove our fork shortly as we've been deprecating the SOAP API and are now ready to remove it.
from nori.
Alright, thanks!
from nori.
Related Issues (20)
- Use schema HOT 5
- It ignores attributes when a child is a text node. HOT 11
- Strings as Nori::StringWithAttributes HOT 8
- xsi:nil="true" nodes not nil when additional attributes present HOT 2
- Why add Hash#to_params HOT 1
- Make advanced type casting actually advanced HOT 2
- strip error HOT 3
- advance_type_casting regex fails to parse time like fields HOT 3
- XML Parsing fails with unescaped ampersand in content (not tag) HOT 1
- Breaking change between 2.4.0 and 2.6.0 HOT 1
- Nori dynamic require breaks in Jruby HOT 3
- does not work with plain tags and whitespace
- Selective disabling of advanced_typcasting for certain attributes
- Strange error when passing malformed xml
- empty_tag_value not obeying xsi:nil ?
- Raise on error?
- REXML parsing error HOT 3
- strip_namespaces doesn't work for attributes HOT 1
- Inconsistent types when parsing empty tags HOT 2
- Nori::StringWithAttributes should implement `#as_json` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nori.