Live data from Hacker News

Ruby 1.9 doesn't implement ISO 8601 properly

tommorris.org

21–30 of 50 posts

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#21

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…

Maybe a Date should be a Range of Time? Even a specific date is a 24h interval.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#22
post #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.

There are different ways to overlap, too, so I don't think it's correct to say that there are only 4 states.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#24
post #21

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…

Maybe a Date should be a Range of Time? Even a specific date is a 24h interval.

The problem with making all dates into ranges is that there would be no total order. To effectively have a total order, you would need to say "give me the range of time at the smallest possible granularity", which is really just asking for a point in time. If the granularity becomes smaller later, it might break the application if you aren't careful. So, I don't think it's a good idea to give up on points in time.

However, I strongly agree that ranges of time are a very useful concept, and I spent a lot of time implementing Range Types[1] in postgresql for that reason. I think Ruby should have both ranges of time and points of time (and ideally work with the SQL counterparts seamlessly).

[1] http://www.postgresql.org/docs/9.2/static/rangetypes.html

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#25
post #3
post #2

I think it would make the point much clearer if the author of that article would actually explain a use case for this (apparently incorrectly handled) syntax which I have never ever come in contact with :).

Well the point is that they shouldn't call the method iso8601 if it doesn't implement the whole iso8601 standard

Ever seen a method called "validateEmailAddress" or something similar? Take any given implementation of that and you can predict with almost certainty that it does not validate all possible valid email addresses (which also has a spec that even came along after the internet was conceived).

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#26
post #8

So do tons of other libraries and PL standard libraries. jodatime in Java, moment.js, JS' Date object, python's datetime stdlib module, python-dateutil etc. ISO-8601 is actually quite a difficult standard to program for. 9 out of 10 times, these libraries either don't support just year, year-month, or both. 9 out of 10 times, when a datetime object is formatted to a string, you see inconsistencies about that dangling…

I wonder how Perl's DateTime::Format::ISO8601 [1] holds up...

[1] https://metacpan.org/module/DateTime::Format::ISO8601

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#27
Was it just me or was the wording in the article slightly confusing? The second paragraph changes from talking about the standard to talking about the ruby implementation with out saying so in either case and no transition.

If I understand correctly, the complaint is that: ISO 8601 defines ####-## to be a year and month only, and it should have the granularity of a month; but Ruby treats it as an ordinal date.

It seems like it could be said much more clearly with an example:

    irb(main):011:0> Date.iso8601("2012-12")
    => #
It's treating ####-## as an ordinal date, when the standard says that it's a month-granularity date.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#28

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…

If you support only a subset of the standard, or if you extend the standard, that may still be OK (not without problems, but still OK in some situations).

This case seems like an outright violation, however. If the standard says that ####-## is a year-month date with month granularity, and you interpret it as an ordinal date, then that's a clear violation. It means that others communicating with you won't just get an error, they will get the wrong answer, which is much worse.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#29

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.

It may well be lacking in completeness, but I bet it covers over 99% of actual real-world ISO8601 dates. When was the last time you ran across a "week date"?

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#30
post #3
post #2

I think it would make the point much clearer if the author of that article would actually explain a use case for this (apparently incorrectly handled) syntax which I have never ever come in contact with :).

Well the point is that they shouldn't call the method iso8601 if it doesn't implement the whole iso8601 standard

I think it's OK to be missing a few aspects of the standard. But in that case, it should still parse correctly and throw a "not supported" exception for unsupported features.

Parsing it incorrectly is bad news.

Post reply on HN