From: Roland Häder Date: Thu, 6 Jul 2017 20:54:04 +0000 (+0200) Subject: Now all date fields (including last-locked) are now well-formatted and just a X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=10224924d201e708540f2d7a2f8c535a5042ac34;p=juser-core.git Now all date fields (including last-locked) are now well-formatted and just a Calendar.toString() which looks very ugly. The format only depends on the user's locale setting. Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jusercore/model/user/UserUtils.java b/src/org/mxchange/jusercore/model/user/UserUtils.java index 067e493..3562caa 100644 --- a/src/org/mxchange/jusercore/model/user/UserUtils.java +++ b/src/org/mxchange/jusercore/model/user/UserUtils.java @@ -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 + *

+ * @param user User instance + * @param calendar Calendar instance + *

+ * @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 *