Live data from Hacker News

Ruby 1.9 doesn't implement ISO 8601 properly

tommorris.org

31–40 of 50 posts

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#31
post #21

Earlier quoted context omitted.

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. Ho…

Does a point in time ever really exist? I think it's all ranges, just with smaller granularities, until you get into quantum mechanics. So, your point-in-time type is actually a range-with-granularity-X type, which should be able to inter-operate with range types of different granularities in a well-defined way.

I've recently done a lot of work using time ranges (a scheduling app) in C#, using the TimePeriod library available via NuGet. Very helpful library, but it would have been even better if DB2 (which I have to use quite often) supported a range type like you've implemented for PostgreSQL.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#32
post #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"?

Very common in Europe, where businesses often operate relative to weeks; we frequently use week numbers for that reason (an abomination in my opinion). Ruby has decent but not great support for ISO week numbers.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#34
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…

Perhaps a useful compromise would be to implement W3C's ISO-8601 profile http://www.w3.org/TR/NOTE-datetime

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#35
post #6
post #3

Earlier quoted context omitted.

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

That's a bold statement. I don't think I've ever seen a program / library which implements any standard completely and without issues. It's not uncommon to see a list of things that are not done, incomplete, or just called out as wrong and rejected from the implementation. It's not perfect, but no implementation will ever be imho.

Not implementing part of a standard is different from implementing it differently than the standard specifies.

YYYY-MM is year-month, not year-day365. It's not very reasonable to interpret yyyy-mm as year-day365 in a function called iso8601 when the standard says that's not how to interpret it.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#37
post #18

Earlier quoted context omitted.

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…

Perhaps a useful compromise would be to implement W3C's ISO-8601 profile http://www.w3.org/TR/NOTE-datetime

My God. The W3C actually made something simpler. Drastically simpler; simple enough to write down on one page. Mind you, it's just a note that someone else submitted, and the W3C hasn't formally discussed it, let alone blessed it -- but even so, it's heartening.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#39

Earlier quoted context omitted.

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. Ho…

Does a point in time ever really exist? I think it's all ranges, just with smaller granularities, until you get into quantum mechanics. So, your point-in-time type is actually a range-with-granularity-X type, which should be able to inter-operate with range types of different granularities in a well-defined way. I've recently done a lot of work using time ranges (a scheduling app) in C#, using the TimePeriod library…

"Does a point in time ever really exist?"

I agree, but that gets a little too philosophical. Does an integer exist? What about characters: is my "a" really the same as your "a"?

The way I see it, there are a lot of practical reasons to look at time as a total order for some things, even if ranges are available. Programming languages and databases should model reality, but only in the sense that it's relevant to what you are trying to do. If you are writing a scheduling app, then ranges of time are very important, and should be their own data type. If you just want to tell your customers when they bought some widget, a point in time makes more sense.

Re: Ruby 1.9 doesn't implement ISO 8601 properly

#40

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…

So it's not even a subset of ISO 8601, it's just the umpteenth ad-hoc date parsing method with semantics defined as "portion of a 3k line C file with no comments": https://github.com/ruby/ruby/blob/7ea675732ac1dac72f07756498...

PS I did my undergrad thesis on Ruby; I love the language. But now that I have a job where people read my code more often than it's written, I understand why things like clear semantics matter.

And why method names should be precise since they lead developers to assume behavior. Didn't your english teacher tell you a poem's title means something? So do method names. "iso8601" implies some meaningful relationship to ISO 8601, but the only relationship here is that the coders of this method were thinking hard about ISO 8601 when they wrote it.

Post reply on HN