PointInTimeFormat { public static DateTimeFormatter forPrecision(Precision p) { switch (p) { case MILLISECOND: return dateTime(); case SECOND: return dateTime(); case MINUTE: return dateTime(); case HOUR: return date(); case DATE: return date(); case MONTH: return monthAndYear(); default: return year(); } } protected  PointInTimeFormat(); static DateTimeFormatter forPattern(String pattern); static DateTimeFormatter date(); static DateTimeFormatter dateTime(); static DateTimeFormatter time(); static DateTimeFormatter year(); static DateTimeFormatter monthAndYear(); static DateTimeFormatter forPointInTime(PointInTime t); static DateTimeFormatter forPrecision(Precision p);  }
@Test public void testDefaultFormatForPrecision() { PointInTime t = new PointInTime(1975, 7, 23, 10, 23, 55, 123); Assert.assertEquals("1975", PointInTimeFormat.forPrecision(Precision.YEAR).print(t)); Assert.assertEquals("Jul 1975", PointInTimeFormat.forPrecision(Precision.MONTH).print(t)); Assert.assertEquals("Jul 23,75", PointInTimeFormat.forPrecision(Precision.DATE).print(t)); Assert.assertEquals("Jul 23,75", PointInTimeFormat.forPrecision(Precision.HOUR).print(t)); Assert.assertEquals("Jul 23,75 10:23", PointInTimeFormat.forPrecision(Precision.MINUTE).print(t)); Assert.assertEquals("Jul 23,75 10:23", PointInTimeFormat.forPrecision(Precision.SECOND).print(t)); Assert.assertEquals("Jul 23,75 10:23", PointInTimeFormat.forPrecision(Precision.MILLISECOND).print(t)); }