ClimFileFactory implements TemporalFileFactory { public TemporalFile createTemporalFile(final File file) { final String filename = file.getName(); if (filename.length() < 21) { return null; } if (!filename.startsWith(FILENAME_PREFIX)) { return null; } if (!filename.endsWith(FILENAME_SUFFIX)) { return null; } int year1; int month1; int year2; int month2; try { year1 = Integer.parseInt(filename.substring(TIME1_OFFSET, TIME1_OFFSET + 4)); month1 = Integer.parseInt(filename.substring(TIME1_OFFSET + 4, TIME1_OFFSET + 6)); year2 = Integer.parseInt(filename.substring(TIME2_OFFSET, TIME2_OFFSET + 4)); month2 = Integer.parseInt(filename.substring(TIME2_OFFSET + 4, TIME2_OFFSET + 6)); } catch (NumberFormatException e) { return null; } final long startTime = computeTime(year1, month1); final long endTime = computeTime(year2, month2 + 1) - 1; return new TemporalFile(file, new Date(startTime), new Date(endTime)); }  TemporalFile createTemporalFile(final File file);  }
@Test public void testCreateTemporalFile() { final DateFormat dateFormat = UTCTest.getDateTimeFormat(); final ClimFileFactory ff = new ClimFileFactory(); File f; TemporalFile tf; f = new File("CLIM_GADS_200310_200403_FUB.hdf"); tf = ff.createTemporalFile(f); assertNotNull(tf); assertEquals("01.10.2003 00:00:00", dateFormat.format(tf.getStartDate())); assertEquals("31.03.2004 23:59:59", dateFormat.format(tf.getEndDate())); f = new File("CLIM_GADS_200304_200309_FUB.hdf"); tf = ff.createTemporalFile(f); assertNotNull(tf); assertEquals("01.04.2003 00:00:00", dateFormat.format(tf.getStartDate())); assertEquals("30.09.2003 23:59:59", dateFormat.format(tf.getEndDate())); }