arnau / ISO8601

Ruby parser to work with ISO8601 dateTimes and durations — http://en.wikipedia.org/wiki/ISO_8601
MIT License
75 stars 15 forks source link

Error working with durations #26

Closed pabramowitsch closed 9 years ago

pabramowitsch commented 9 years ago

This should work... right? I tried various permutations but they all yield this missing #round error

a = ISO8601::DateTime.new('2014-05-06T10:11:12.5')
dur = ISO8601::Duration.new('P2M')
offset = a + dur
NoMethodError: undefined method `round' for #<ISO8601::Duration:0x007ffa65502cd0>
        from /Users/peterabramowitsch/.rvm/gems/ruby-2.1.1/gems/iso8601-0.8.5/lib/iso8601/date_time.rb:33:in `+'
        from (irb):20
        from /Users/peterabramowitsch/.rvm/rubies/ruby-2.1.1/bin/irb:11:in `<main>'
arnau commented 9 years ago

I'll look into it, thanks!

pabramowitsch commented 9 years ago

Thanks Arnau. I found a work around by mixing DateTime.to_time() with ISO8601.to_seconds()  to create the offset back in a DateTime object rather than using ISO8601::Date.  But it will be less messy when your fix is in. 

By the way, on another matter,  I'm curious which is the official way to tag a negative duration - which is a bit of an anomaly even in english.  I couldn't find it in the iso8601 spec, but I've noticed this In your 8601 class  -P1M  represents a negative duration of one month and P-1M results in an error The sutime parser of the Stanford NLP engine (Based on the JodaTime library tags negative intervals like this:   P-1M, when it sees a construction like "one month ago" On the other hand, the SAS documentation agrees with you that -P1M would be correct.  So I'm curious as to what authority you used to decide on your syntax.  If it's solid, I might suggest to the author of sutime that she use your format rather than her current choice.. Peter

  From: Arnau Siches <notifications@github.com>

To: arnau/ISO8601 ISO8601@noreply.github.com Cc: Peter Abramowitsch pabramowitsch@yahoo.com Sent: Saturday, April 18, 2015 2:55 AM Subject: Re: [ISO8601] Error working with durations (#26)

I'll look into it, thanks!— Reply to this email directly or view it on GitHub.

arnau commented 9 years ago

Hi, about negative durations, as far as I know negative durations is not part of the spec. I implemented it for convenience when operating with it.

My rationale is that an absolute duration is represented as PnYnMnDTnHnMnS or PnW so a sign applied to it should be a prefix to the whole thing not to a particular atom. Actually, adding sign to a particular atom could lead to weird situations like P-1M-2D unless you add a rule that the only atom with sign is the first. Feels awkward.

Sadly I don't have any authoritative source in the matter. Let me know if you find one!

arnau commented 9 years ago

@pabramowitsch The issue is fixed in master. Will be released in the next release 0.8.6 around this week.

pabramowitsch commented 9 years ago

Thats great. Thanks. From: Arnau Siches notifications@github.com To: arnau/ISO8601 ISO8601@noreply.github.com Cc: Peter Abramowitsch pabramowitsch@yahoo.com Sent: Tuesday, April 21, 2015 11:45 AM Subject: Re: [ISO8601] Error working with durations (#26)

Closed #26 via 8d64982.— Reply to this email directly or view it on GitHub.

pabramowitsch commented 9 years ago

Yes, that sounds reasonable to me.  I will notify the Stanford NLP folks that their timex annotater may have this "hole" in its attempt to follow the iso standard. 

The problem is that we (the greater "we", that is) conflate the concept of duration and offset.   A duration can't be negative except perhaps in another universe, but offsets can.  ISO8601 also does not draw this distinction. Thanks for your help.

Peter

  From: Arnau Siches <notifications@github.com>

To: arnau/ISO8601 ISO8601@noreply.github.com Cc: Peter Abramowitsch pabramowitsch@yahoo.com Sent: Tuesday, April 21, 2015 10:37 AM Subject: Re: [ISO8601] Error working with durations (#26)

Hi, about negative durations, as far as I know negative durations is not part of the spec. I implemented it for convenience when operating with it.My rationale is that an absolute duration is represented as PnYnMnDTnHnMnS or PnW so a sign applied to it should be a prefix to the whole thing not to a particular atom. Actually, adding sign to a particular atom could lead to weird situations like P-1M-2D unless you add a rule that the only atom with sign is the first. Feels awkward.Sadly I don't have any authoritative source in the matter. Let me know if you find one!— Reply to this email directly or view it on GitHub.