From 10224924d201e708540f2d7a2f8c535a5042ac34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 6 Jul 2017 22:54:04 +0200 Subject: [PATCH] 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. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jusercore/model/user/UserUtils.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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 *

-- 2.39.5