]> source.dussan.org Git - jackcess.git/commitdiff
handle am/pm suffix dependent on date/time config
authorJames Ahlborn <jtahlborn@yahoo.com>
Fri, 5 Oct 2018 19:10:29 +0000 (19:10 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Fri, 5 Oct 2018 19:10:29 +0000 (19:10 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1206 f203690c-595d-4dc9-a70b-905162fa7fd2

src/main/java/com/healthmarketscience/jackcess/impl/expr/ExpressionTokenizer.java

index 5b2864ad841fe214c92f9ce8a2562e5e42522b57..3dfa3617f36caf29e628bbb475b94d4f7fd97741 100644 (file)
@@ -53,9 +53,6 @@ class ExpressionTokenizer
   private static final char DATE_LIT_QUOTE_CHAR = '#';
   private static final char EQUALS_CHAR = '=';
 
-  private static final int AMPM_SUFFIX_LEN = 3;
-  private static final String AM_SUFFIX = " am";
-  private static final String PM_SUFFIX = " pm";
   // access times are based on this date (not the UTC base)
   private static final String BASE_DATE = "12/30/1899";
   private static final String BASE_DATE_FMT = "M/d/yyyy";
@@ -323,12 +320,10 @@ class ExpressionTokenizer
     boolean hasAmPm = false;
 
     if(hasTime) {
-      int strLen = dateStr.length();
-      hasAmPm = ((strLen >= AMPM_SUFFIX_LEN) &&
-                 (dateStr.regionMatches(true, strLen - AMPM_SUFFIX_LEN,
-                                        AM_SUFFIX, 0, AMPM_SUFFIX_LEN) ||
-                  dateStr.regionMatches(true, strLen - AMPM_SUFFIX_LEN,
-                                        PM_SUFFIX, 0, AMPM_SUFFIX_LEN)));
+      String[] amPmStrs = cfg.getDateFormatSymbols().getAmPmStrings();
+      String amStr = " " + amPmStrs[0];
+      String pmStr = " " + amPmStrs[1];
+      hasAmPm = (hasSuffix(dateStr, amStr) || hasSuffix(dateStr, pmStr));
     }
 
     if(hasDate) {
@@ -344,6 +339,14 @@ class ExpressionTokenizer
     return null;
   }
 
+  private static boolean hasSuffix(String str, String suffStr) {
+    int strLen = str.length();
+    int suffStrLen = suffStr.length();
+    return ((strLen >= suffStrLen) &&
+            str.regionMatches(true, strLen - suffStrLen,
+                              suffStr, 0, suffStrLen));
+  }
+
   static DateFormat createParseDateTimeFormat(TemporalConfig.Type type,
                                               LocaleContext ctx)
   {