Skip to content
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

ISO8601 strangeness in Interval.parse() #114

Open
gsson opened this issue Jan 23, 2014 · 2 comments
Open

ISO8601 strangeness in Interval.parse() #114

gsson opened this issue Jan 23, 2014 · 2 comments
Labels

Comments

@gsson
Copy link

gsson commented Jan 23, 2014

See comment in test for details.

import static org.junit.Assert.assertTrue;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Interval;
import org.junit.Test;

public class TestInterval {
    /* I don't  have access to ISO 8601, but various sources on the
     * Internet (Wikipedia [1] and others) claim that when defining
     * intervals from two instants, unspecified fields in the second
     * instant of the interval should be copied from the first,
     * including timezones.
     *
     * As far as I can tell, unspecified timezones will always be
     * replaced with the local timezone.
     *
     * The strange timezone used in test was selected to minimize the
     * risk that it is the same as the local timezone.
     *
     * [1]: http://en.wikipedia.org/wiki/ISO_8601#Time_intervals
     */
    @Test
    public void testInterval() {
        String intervalString = "2007-03-10T00:00+12:34/2007-03-11";
        Interval actual = Interval.parse(intervalString);

        DateTimeZone offset = DateTimeZone.forOffsetHoursMinutes(12, 34);
        DateTime start = new DateTime(2007, 03, 10, 00, 00, offset);
        DateTime end = new DateTime(2007, 03, 11, 00, 00, offset);
        Interval expected = new Interval(start, end);

        assertTrue(expected.isEqual(actual));
    }
}
@jodastephen
Copy link
Member

That would be a reasonable format to parse, although I don't know if it is an ISO-8601 format or not.

@gsson
Copy link
Author

gsson commented Jan 27, 2014

I have it on good authority that at least one version of ISO 8601 says this about the interval notation:

  • representations for time-zones and Coordinated Universal Time included with the component preceding the solidus shall be assumed to apply to the component following the solidus, unless a corresponding alternative is included

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants