Live data from Hacker News

Ruby 1.9 doesn't implement ISO 8601 properly

tommorris.org

11–20 of 50 posts

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#12

Not only that, but ISO 8601 also allows you to just specify the year, but Date.iso8601("2012") raises an ArgumentError "invalid date". Nor does it support "week dates", Date.iso8601("2012-W01") raises an ArgumentError too. I don't know the standard, but either Wikipedia is wrong or the Date implementation is sorely lacking.

Yep. There's a lot more problems than that.

I've been reading the source code of one ISO 8601 implementation in JavaScript and writing my own in Java. Looks like I'll have to fix the Ruby one too.

Given that it's used by, oh, HTML and XML, not properly implementing ISO 8601 is really no big deal.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#13
Actually the article seems to be a bit confused:

> If you aren’t doing ordinal dates, you aren’t doing ISO 8601.

It seems ruby1.9 does implement ordinal dates just fine:

    irb(main):002:0> Date.iso8601("2012-012")
    => #
    irb(main):005:0> Date.iso8601("2012-366")
    => #
What it does not implement is the "YYYY-MM" format:

    irb(main):010:0> Date.iso8601("2012-12")
    => #

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#14

Actually the article seems to be a bit confused: > If you aren’t doing ordinal dates, you aren’t doing ISO 8601. It seems ruby1.9 does implement ordinal dates just fine: irb(main):002:0> Date.iso8601("2012-012") => # irb(main):005:0> Date.iso8601("2012-366") => # What it does not implement is the "YYYY-MM" format: irb(main):010:0> Date.iso8601("2012-12") => #

Yeah, I wrote it in a bit of a hurry on the train. Will fix.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#15
The article is making two somewhat unrelated complaints:

1. Date.iso8601 does not correctly parse some ISO 8601 formats like ordinal dates or month-only dates.

2. The Date class does not support year-only or year/month granularity.

In response to the first, the documentation for Date.iso8601 (http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#...) says:

"Creates a new Date object by parsing from a string according to some typical ISO 8601 formats."

Not "all ISO 8601 formats," "some typical ISO 8601 formats." While supporting more formats is obviously desirable, the method never claimed to be a complete ISO 8601 implementation. It would be nicer if it were, but would also take more work and it appears that 100% spec support was neither prioritized nor promised.

I believe the second complaint is less justified. Asking a single class (Date) to support multiple granularities opens up a lot of semantic conundrums that have no obvious resolution. What should this return?

   Date.iso8601("2012-01") 
If one is truly month granularity and one is day granularity, then the two aren't directly comparable. It would make more sense to me to have the month granularity representation be a separate class altogether (YearMonth?) with easy and well-defined conversions between the two.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#16

The article is making two somewhat unrelated complaints: 1. Date.iso8601 does not correctly parse some ISO 8601 formats like ordinal dates or month-only dates. 2. The Date class does not support year-only or year/month granularity. In response to the first, the documentation for Date.iso8601 ( http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#... ) says: "Creates a new Date object by parsing from a string a…

Sure, it's a tough problem. The resolution to my complaint is a proper ISO 8601 implementation for Ruby.

Which I'll probably have to write. ;)

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#18

The article is making two somewhat unrelated complaints: 1. Date.iso8601 does not correctly parse some ISO 8601 formats like ordinal dates or month-only dates. 2. The Date class does not support year-only or year/month granularity. In response to the first, the documentation for Date.iso8601 ( http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#... ) says: "Creates a new Date object by parsing from a string a…

Sure, it's a tough problem. The resolution to my complaint is a proper ISO 8601 implementation for Ruby. Which I'll probably have to write. ;)

ISO 8601 is large standard and predates the internet (as we know it) and seems like an attempt of formalizing all the many different ways people expressed dates (on physical papers in addition to computer systems), and also some ways no-one would ever use.

I think you’ll find a lot of APIs (or formats) claiming to support an “ISO 8601 date” when in fact they mean a date of the form “YYYY-MM-DD” — it’s a common misunderstanding, but I think better that, than actually allowing the full range of dates allowed by the actual ISO 8601 standard :)

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#19

The article is making two somewhat unrelated complaints: 1. Date.iso8601 does not correctly parse some ISO 8601 formats like ordinal dates or month-only dates. 2. The Date class does not support year-only or year/month granularity. In response to the first, the documentation for Date.iso8601 ( http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#... ) says: "Creates a new Date object by parsing from a string a…

of course you can compare them (4 states: before, after, same, overlapping). you cannot put them into an order. that's something different.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#20
post #18

Earlier quoted context omitted.

Sure, it's a tough problem. The resolution to my complaint is a proper ISO 8601 implementation for Ruby. Which I'll probably have to write. ;)

ISO 8601 is large standard and predates the internet (as we know it) and seems like an attempt of formalizing all the many different ways people expressed dates (on physical papers in addition to computer systems), and also some ways no-one would ever use. I think you’ll find a lot of APIs (or formats) claiming to support an “ISO 8601 date” when in fact they mean a date of the form “YYYY-MM-DD” — it’s a common misund…

Oh sure, I know the full extent of the madness. At a previous job I was working with XML Schema durations to represent energy emissions data. It gives me bad memories.
Post reply on HN