-
Notifications
You must be signed in to change notification settings - Fork 208
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::iso8601 does not implement the ISO8601 standard protocol #193
Comments
ugh. that sucks. |
I guess we can take a look at ActiveSupport, since it does it? James Harton On Tuesday, 5 March 2013 at 2:19 PM, Marcus Gartner wrote:
|
It's actually part of stdlib -- you have to |
From time.rb: def xmlschema(fraction_digits=0)
fraction_digits = fraction_digits.to_i
s = strftime("%FT%T")
if fraction_digits > 0
s << strftime(".%#{fraction_digits}N")
end
s << (utc? ? 'Z' : strftime("%:z"))
end
alias iso8601 xmlschema |
Also, from Rubinius, which is more useful maybe: #
# Parses +date+ as dateTime defined by XML Schema and converts it to a Time
# object. The format is restricted version of the format defined by ISO
# 8601.
#
# ArgumentError is raised if +date+ is not compliant with the format or Time
# class cannot represent specified date.
#
# See #xmlschema for more information on this format.
#
# time library should be required to use this method as follows.
#
# require 'time'
#
def xmlschema(date)
if /\A\s*
(-?\d+)-(\d\d)-(\d\d)
T
(\d\d):(\d\d):(\d\d)
(\.\d+)?
(Z|[+-]\d\d:\d\d)?
\s*\z/ix =~ date
year = $1.to_i
mon = $2.to_i
day = $3.to_i
hour = $4.to_i
min = $5.to_i
sec = $6.to_i
usec = 0
if $7
usec = Rational($7) * 1000000
end
if $8
zone = $8
year, mon, day, hour, min, sec =
apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
self.utc(year, mon, day, hour, min, sec, usec)
else
self.local(year, mon, day, hour, min, sec, usec)
end
else
raise ArgumentError.new("invalid date: #{date.inspect}")
end
end
alias iso8601 xmlschema |
Odd, this is not parsing the following string, either: |
@joshsmith #255 added a method
|
@mgartner Whoops, I missed that! Saw the first spec and missed the second. Thanks! |
This still does not act as expected, though it's perhaps user error again. Right now when we use |
It doesn't support fractional digits. e.g.
BubbleWrap 1.4 returns
|
just look up the right date formats to use here: http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns |
decimal fraction is part of ISO8601 standard http://dotat.at/tmp/ISO_8601-2004_E.pdf It's supported in
I suggest Bubblewrap to implement Ruby 2.1's behavior |
Any update on this? I've just hit the same bug last week >< |
It only supports using "Z" as the timezone. It should support other timezone types. For example
The text was updated successfully, but these errors were encountered: