Index: lams_common/src/java/org/lamsfoundation/lams/util/DateUtil.java =================================================================== diff -u -reeaec5d1e9dedb2349cabff878dfae20be73c585 -rbe4bdf7fe656c78e4e5de1565dbd7344192e96fe --- lams_common/src/java/org/lamsfoundation/lams/util/DateUtil.java (.../DateUtil.java) (revision eeaec5d1e9dedb2349cabff878dfae20be73c585) +++ lams_common/src/java/org/lamsfoundation/lams/util/DateUtil.java (.../DateUtil.java) (revision be4bdf7fe656c78e4e5de1565dbd7344192e96fe) @@ -54,9 +54,10 @@ public static final String SCHEDULE_LESSON_FORMAT = "dd/M/yyyy h:mm a"; public static final String ISO8601_FORMAT = "yyyy-MM-dd'T'HH:mmZ"; public static final String PRETTY_FORMAT = "d MMMM yyyy h:mm:ss a"; - - private static final FastDateFormat dateFormatterTimeAgo = FastDateFormat.getInstance(DateUtil.ISO8601_FORMAT, TimeZone.getTimeZone("GMT"), null); + private static final FastDateFormat dateFormatterTimeAgo = FastDateFormat.getInstance(DateUtil.ISO8601_FORMAT, + TimeZone.getTimeZone("GMT"), null); + /** * Convert your local time to Universal Time Coordinator. TODO conversion is not working properly. The returned Date * object still contain server local timezone rather than GMT time zone. @@ -105,7 +106,7 @@ */ public static Date convertToTimeZoneFromDefault(TimeZone targetTimeZone, Date date) { TimeZone defaultTz = TimeZone.getDefault(); - Integer rawOffset = defaultTz.getOffset(date.getTime()) - targetTimeZone.getOffset(date.getTime()); + int rawOffset = defaultTz.getOffset(date.getTime()) - targetTimeZone.getOffset(date.getTime()); return new Date(date.getTime() - rawOffset); } @@ -121,7 +122,7 @@ */ public static Date convertFromTimeZoneToDefault(TimeZone targetTimeZone, Date date) { TimeZone defaultTz = TimeZone.getDefault(); - Integer rawOffset = defaultTz.getOffset(date.getTime()) - targetTimeZone.getOffset(date.getTime()); + int rawOffset = defaultTz.getOffset(date.getTime()) - targetTimeZone.getOffset(date.getTime()); return new Date(date.getTime() + rawOffset); } @@ -223,11 +224,6 @@ * @return */ public static String convertToStringForJSON(Date value, Integer style, Integer type, Locale locale) { - - HttpSession ss = SessionManager.getSession(); - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - TimeZone tz = user.getTimeZone(); - int dateStyle, timeStyle; switch (style) { case DateFormat.SHORT: @@ -255,6 +251,9 @@ df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale); } + HttpSession ss = SessionManager.getSession(); + UserDTO user = ss == null ? null : (UserDTO) ss.getAttribute(AttributeNames.USER); + TimeZone tz = user == null ? null : user.getTimeZone(); if (tz != null) { df.setTimeZone(tz); } @@ -267,7 +266,7 @@ */ public static String convertToStringForTimeagoJSON(Date value) { return dateFormatterTimeAgo.format(value); - + } }