]> git.mxchange.org Git - juser-login-core.git/commitdiff
Now all date fields (including last-locked) are now well-formatted and just a
authorRoland Häder <roland@mxchange.org>
Thu, 6 Jul 2017 20:54:04 +0000 (22:54 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 6 Jul 2017 20:54:04 +0000 (22:54 +0200)
Calendar.toString() which looks very ugly. The format only depends on the
user's locale setting.

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jusercore/model/user/UserUtils.java

index 067e4933b53d0ab500a16c540234e739d63466f2..3562caa776412e4213d1d6ee0b760aadef34b8cf 100644 (file)
@@ -18,7 +18,9 @@ package org.mxchange.jusercore.model.user;
 
 import java.io.Serializable;
 import java.security.SecureRandom;
+import java.text.DateFormat;
 import java.text.MessageFormat;
+import java.util.Calendar;
 import java.util.Properties;
 import java.util.Random;
 import java.util.regex.Matcher;
@@ -413,9 +415,9 @@ public class UserUtils implements Serializable {
                // - User data
                properties.setProperty("userId", Long.toString(user.getUserId())); //NOI18N
                properties.setProperty("userName", user.getUserName()); //NOI18N
-               properties.setProperty("userCreated", user.getUserCreated().toString()); //NOI18N
+               properties.setProperty("userCreated", getFormattedTimestampFromUser(user, user.getUserCreated())); //NOI18N
                if (user.getUserUpdated() != null) {
-                       properties.setProperty("contactUpdated", user.getUserUpdated().toString()); //NOI18N
+                       properties.setProperty("userUpdated", getFormattedTimestampFromUser(user, user.getUserUpdated())); //NOI18N
                }
                if (user.getUserConfirmKey() != null) {
                        properties.setProperty("userConfirmKey", user.getUserConfirmKey()); //NOI18N
@@ -423,6 +425,9 @@ public class UserUtils implements Serializable {
                if (user.getUserLastLockedReason() != null) {
                        properties.setProperty("userLastLockedReason", user.getUserLastLockedReason()); //NOI18N
                }
+               if (user.getUserLastLocked() != null) {
+                       properties.setProperty("userLastLocked", getFormattedTimestampFromUser(user, user.getUserLastLocked())); //NOI18N
+               }
                properties.setProperty("userAccountStatus", user.getUserAccountStatus().toString()); //NOI18N
 
                // - Contact data
@@ -459,6 +464,25 @@ public class UserUtils implements Serializable {
                return properties;
        }
 
+       /**
+        * Returns a formatted string from given user's locale and Calendar instance
+        * <p>
+        * @param user     User instance
+        * @param calendar Calendar instance
+        * <p>
+        * @return A formatted string from Calendar instance
+        */
+       public static String getFormattedTimestampFromUser (final User user, final Calendar calendar) {
+               // Get formatter
+               DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, user.getUserLocale());
+
+               // Now simply format the calendar's Time (not just time) field
+               String dateTime = format.format(calendar.getTime());
+
+               // Return it
+               return dateTime;
+       }
+
        /**
         * Checks if password from container matches the updatedUser's password
         * <p>