FHIR Chat · DateType issue · hapi

Stream: hapi

Topic: DateType issue


view this post on Zulip Bryn Rhodes (Jan 04 2017 at 16:04):

I'm having a strange problem with the DateType. It's so wrong I think I must be doing something wrong, but I can't see it. Here's the test:

view this post on Zulip Bryn Rhodes (Jan 04 2017 at 16:04):

@Test
public void testDateType() {
    DateType birthDate = new DateType(1974, 12, 25);
    assertThat(birthDate.getYear(), is(1974));
    assertThat(birthDate.getMonth(), is(12));
    assertThat(birthDate.getDay(), is(25));
}

view this post on Zulip Bryn Rhodes (Jan 04 2017 at 16:04):

What I get is a failure on that first assertion that the year component is actually 1975?

view this post on Zulip Bryn Rhodes (Jan 04 2017 at 16:04):

Anyone else have problems with the DateType?

view this post on Zulip Bryn Rhodes (Jan 13 2017 at 17:34):

FYI, this did turn out to be something simple, apparently the DateType month component is zero-based. Not sure why, but that was certainly a surprising behavior (especially since year and day aren't).

view this post on Zulip Bryn Rhodes (Jan 13 2017 at 17:34):

Well, I suppose year is, but it didn't exhibit the same off-by-one behavior.

view this post on Zulip James Agnew (Jan 18 2017 at 19:55):

@Bryn Rhodes FWIW this oddness is because that's how the underlying Java Calendar object does it (0-indexed for years, 1-indexed for months, 0-indexed for days). I agree that's atrocious behaviour... sigh.

That's brutal though that giving a month that is effectively "month 13" just makes it roll to the next January. I'm going to put a check in for it to throw an exception in that case.

view this post on Zulip Bryn Rhodes (Jan 18 2017 at 21:34):

@James Agnew Thanks, that will definitely help with the surprising behavior.


Last updated: Apr 12 2022 at 19:14 UTC