Skip to content
Snippets Groups Projects
Commit 1c8487ac authored by Piotr Gawron's avatar Piotr Gawron
Browse files

fix on strange lih date format

parent 026b13a3
No related branches found
No related tags found
1 merge request!1Appointments dev
......@@ -193,11 +193,15 @@ public abstract class SubjectParser {
if (result == null || result.trim().isEmpty()) {
result = defaultDateString;
}
result = fixDate(result);
result = fixDate(result, defaultDateString);
return result;
}
protected String fixDate(String result) {
return fixDate(result, null);
}
protected String fixDate(String result, String defaultDateString) {
result = result.replaceAll("\\?", "");
result = result.replaceAll("jan", "01");
result = result.replaceAll("fev", "02");
......@@ -212,6 +216,13 @@ public abstract class SubjectParser {
String tmp[] = result.split("/");
result = tmp[2] + "-" + tmp[1] + "-" + tmp[0];
}
if (result.charAt(2) == '-') {
String tmp[] = result.split("-");
result = tmp[2] + "-" + tmp[1] + "-" + tmp[0];
}
if (result.length() < 10) {
result = defaultDateString;
}
return result;
}
......
package smash.appointment.parse;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
......@@ -65,7 +67,8 @@ public class LihControlMappingParserTest extends TestBase {
@Test
public void testFixDate() throws Exception {
DATE_FORMATTER.parse(processor.fixDate("2016-cot-31"));
DATE_FORMATTER.parse(processor.fixDate("25-11-1951"));
Date d = DATE_FORMATTER.parse(processor.fixDate("25-11-1951"));
assertEquals("1951-11-25",DATE_FORMATTER.format(d));
DATE_FORMATTER.parse(processor.fixDate("1957??-10-25"));
DATE_FORMATTER.parse(processor.fixDate("2016?-sep-12"));
DATE_FORMATTER.parse(processor.fixDate("2016-aou-26"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment