From 7249977f0252487c88bb139475abe5895091b8f2 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Tue, 25 Sep 2012 13:25:24 -0700 Subject: [PATCH] Regexp dates in numeric format removed when in paretheses --- .../todoroo/astrid/utility/TitleParser.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/utility/TitleParser.java b/astrid/src/com/todoroo/astrid/utility/TitleParser.java index aee8bd074..4ca81f1f9 100644 --- a/astrid/src/com/todoroo/astrid/utility/TitleParser.java +++ b/astrid/src/com/todoroo/astrid/utility/TitleParser.java @@ -231,43 +231,42 @@ public class TitleParser { } // for dates in the format MM/DD - Pattern p = Pattern.compile("(?i)\\b(1[0-2]|0?[1-9])(\\/|-)(3[0-1]|[0-2]?[0-9])(\\/|-)?(\\d{4}|\\d{2})?"); + Pattern p = Pattern.compile("(?i)(\\(|\\b)(1[0-2]|0?[1-9])(\\/|-)(3[0-1]|[0-2]?[0-9])(\\/|-)?(\\d{4}|\\d{2})?(\\)|\\b)"); Matcher match = p.matcher(inputText); if (match.find()){ Calendar dCal = Calendar.getInstance(); setCalendarToDefaultTime(dCal); - dCal.set(Calendar.MONTH, Integer.parseInt(match.group(1).trim())-1); - dCal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(match.group(3))); - if (match.group(5) != null && !(match.group(5).trim()).equals("")) - { - String yearString = match.group(5); - if(match.group(5).length()==2) - yearString = "20" + match.group(5); + dCal.set(Calendar.MONTH, Integer.parseInt(match.group(2).trim()) - 1); + dCal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(match.group(4))); + if (match.group(6) != null && !(match.group(6).trim()).equals("")) { + String yearString = match.group(6); + if(match.group(6).length() == 2) + yearString = "20" + match.group(6); dCal.set(Calendar.YEAR, Integer.parseInt(yearString)); } - if (cal==null){ + if (cal == null) { cal = dCal; - } - else{ + } else{ cal.set(Calendar.DAY_OF_MONTH, dCal.get(Calendar.DAY_OF_MONTH)); cal.set(Calendar.MONTH,dCal.get(Calendar.MONTH)); cal.set(Calendar.YEAR, dCal.get(Calendar.YEAR)); } + inputText = removeIfParenthetical(match, inputText); } HashMap dayTimes = new HashMap(); dayTimes.put("(?i)\\bbreakfast\\b", 8); dayTimes.put("(?i)\\blunch\\b", 12); - dayTimes.put("(?i)\\bsupper\\b" ,18); - dayTimes.put("(?i)\\bdinner\\b",18); + dayTimes.put("(?i)\\bsupper\\b", 18); + dayTimes.put("(?i)\\bdinner\\b", 18); dayTimes.put("(?i)\\bbrunch\\b", 10); dayTimes.put("(?i)\\bmorning\\b", 8); dayTimes.put("(?i)\\bafternoon\\b", 15); - dayTimes.put("(?i)\\bevening\\b" , 19); - dayTimes.put("(?i)\\bnight\\b" , 19); - dayTimes.put("(?i)\\bmidnight\\b" , 0); - dayTimes.put("(?i)\\bnoon\\b" , 12); + dayTimes.put("(?i)\\bevening\\b", 19); + dayTimes.put("(?i)\\bnight\\b", 19); + dayTimes.put("(?i)\\bmidnight\\b", 0); + dayTimes.put("(?i)\\bnoon\\b", 12); for (String dayTime: dayTimes.keySet()){ Pattern pattern = Pattern.compile(dayTime);