You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2018/04/26 11:30:54 UTC

[4/4] syncope git commit: [SYNCOPE-1306] fixing date value without conversion pattern - This closes #73

[SYNCOPE-1306] fixing date value without conversion pattern - This closes #73


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/c0e2aede
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/c0e2aede
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/c0e2aede

Branch: refs/heads/master
Commit: c0e2aedef5360101a78fb0932c7ea16fc2ae3c8b
Parents: c596627
Author: dayash <di...@tirasa.net>
Authored: Thu Apr 26 12:35:05 2018 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Thu Apr 26 13:30:28 2018 +0200

----------------------------------------------------------------------
 .../jpa/entity/AbstractPlainAttrValue.java      |  3 +-
 .../provisioning/api/utils/FormatUtils.java     | 29 ++++++++++++++++----
 2 files changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/c0e2aede/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java
index bd19107..f259eb6 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java
@@ -256,8 +256,7 @@ public abstract class AbstractPlainAttrValue extends AbstractGeneratedKeyEntity
                 result = getAttr() == null || getAttr().getSchema() == null
                         || getAttr().getSchema().getConversionPattern() == null
                         ? FormatUtils.format(getDateValue())
-                        : FormatUtils.format(
-                                getDateValue(), false, getAttr().getSchema().getConversionPattern());
+                        : FormatUtils.format(getDateValue(), false, getAttr().getSchema().getConversionPattern());
                 break;
 
             case Binary:

http://git-wip-us.apache.org/repos/asf/syncope/blob/c0e2aede/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/utils/FormatUtils.java
----------------------------------------------------------------------
diff --git a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/utils/FormatUtils.java b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/utils/FormatUtils.java
index e1c7ce5..2f262f2 100644
--- a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/utils/FormatUtils.java
+++ b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/utils/FormatUtils.java
@@ -36,9 +36,7 @@ public final class FormatUtils {
 
         @Override
         protected SimpleDateFormat initialValue() {
-            SimpleDateFormat sdf = new SimpleDateFormat();
-            sdf.applyPattern(SyncopeConstants.DEFAULT_DATE_PATTERN);
-            return sdf;
+            return new SimpleDateFormat();
         }
     };
 
@@ -62,10 +60,15 @@ public final class FormatUtils {
 
     public static String format(final Date date, final boolean lenient, final String conversionPattern) {
         SimpleDateFormat sdf = DATE_FORMAT.get();
-        if (conversionPattern != null) {
+
+        if (conversionPattern == null) {
+            sdf.applyPattern(SyncopeConstants.DEFAULT_DATE_PATTERN);
+        } else {
             sdf.applyPattern(conversionPattern);
         }
+
         sdf.setLenient(lenient);
+
         return sdf.format(date);
     }
 
@@ -75,10 +78,17 @@ public final class FormatUtils {
 
     public static String format(final long number, final String conversionPattern) {
         DecimalFormat df = DECIMAL_FORMAT.get();
+
+        String previous = df.toPattern();
         if (conversionPattern != null) {
             df.applyPattern(conversionPattern);
         }
-        return df.format(number);
+
+        String formatted = df.format(number);
+
+        df.applyPattern(previous);
+
+        return formatted;
     }
 
     public static String format(final double number) {
@@ -87,10 +97,17 @@ public final class FormatUtils {
 
     public static String format(final double number, final String conversionPattern) {
         DecimalFormat df = DECIMAL_FORMAT.get();
+
+        String previous = df.toPattern();
         if (conversionPattern != null) {
             df.applyPattern(conversionPattern);
         }
-        return df.format(number);
+
+        String formatted = df.format(number);
+
+        df.applyPattern(previous);
+
+        return formatted;
     }
 
     public static Date parseDate(final String source) throws ParseException {