@Test
public void testDecodeTemporal() {

  Temporal.Match<Integer> match = new Temporal.Match<Integer>() {
    @Override
    public Integer period(DCMIPeriod period) {
      return 1;
}
    @Override
    public Integer instant(Date instant) {
      return 2;
    }
    @Override
    public Integer duration(long duration) {
      return 3;
    }
  };
  Temporal.Match<Long> durationMatch = new Temporal.Match<Long>() {
    @Override
    public Long period(DCMIPeriod period) {
      throw new RuntimeException();
    }
    @Override
    public Long instant(Date instant) {
      throw new RuntimeException();
    }
    @Override
    public Long duration(long duration) {
      return duration;
    }
  };
  assertSame(1, decodeTemporal(DublinCoreValue.mk("start=2008-10-01; end=2009-01-01;")).fold(match));
  assertSame(2, decodeTemporal(DublinCoreValue.mk("2008-10-01")).fold(match));
  assertSame(2, decodeTemporal(DublinCoreValue.mk("2008-10-01T10:30:05Z")).fold(match));
  assertSame(1, decodeTemporal(DublinCoreValue.mk("start=2008-10-01T10:20Z; end=2009-01-01; scheme=W3C-DTF")).fold(match));
  assertSame(3, decodeTemporal(DublinCoreValue.mk("PT10H5M")).fold(match));
  assertEquals(10L * 60 * 60 * 1000 + 5 * 60 * 1000,
          (long) decodeTemporal(DublinCoreValue.mk("PT10H5M")).fold(durationMatch));
  assertEquals(10L * 60 * 60 * 1000 + 5 * 60 * 1000 + 28 * 1000,
          (long) decodeTemporal(DublinCoreValue.mk("PT10H5M28S")).fold(durationMatch));
}