Harvester implements IHarvester<HarvestResult> { protected Date parseDate(String pubDate) throws ParseException { Locale wellKnownLocales[] = {Locale.ENGLISH, Locale.FRENCH, Locale.GERMAN, Locale.ITALIAN}; for (Locale locale : wellKnownLocales) { SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", locale); try { return sdf.parse(pubDate); } catch (ParseException e) { if(locale == Locale.GERMAN && pubDate.toLowerCase(Locale.GERMAN).contains("mrz")) { try { log.info("Applying MRZ workaround to '"+pubDate+"'"); return sdf.parse(pubDate.toLowerCase(Locale.GERMAN).replace("mrz", "mär")); } catch (ParseException ex) { } } log.debug("Date '"+pubDate+"' is not parsable according to " + locale); } } throw new ParseException("Can't parse date '"+pubDate+"'", 0); } Harvester(AtomicBoolean cancelMonitor, Logger log, ServiceContext context, GeoPRESTParams params); HarvestResult harvest(Logger log); List<HarvestError> getErrors();  }
@Test public void testParseDate() throws Exception { Harvester h = new Harvester(null, Log.createLogger("TEST"), null, null); h.parseDate("Mon, 04 Feb 2013 10:19:00 +1000"); h.parseDate("Fr, 24 Mär 2017 10:58:59 +0100"); }
@Test public void testJDK8136539Workaround() throws Exception { Harvester h = new Harvester(null, Log.createLogger("TEST"), null, null); Date p0 = h.parseDate("Fr, 24 Mär 2017 10:58:59 +0100"); Date p1 = h.parseDate("Fr, 24 Mrz 2017 10:58:59 +0100"); Assert.assertEquals(p1,p0); }
@Test public void testUnparsableDate() throws Exception { Harvester h = new Harvester(null, Log.createLogger("TEST"), null, null); try { h.parseDate("Xyz, 04 Feb 2013 10:19:00 +1000"); Assert.fail("Undetected bad input"); } catch (ParseException ex) { } }