Skip to content

Commit

Permalink
SAK-33331 : java.time.zone.ZoneRulesException: Unknown time-zone ID f…
Browse files Browse the repository at this point in the history
…rom DecoratedChatMessage (sakaiproject#4784)
  • Loading branch information
frasese authored and ottenhoff committed Sep 19, 2017
1 parent 37df506 commit b93494a
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -1250,7 +1249,7 @@ public MessageDateString getMessageDateString(ChatMessage msg){
*/
public String getUserTimeZone() {
String userId = sessionManager.getCurrentSessionUserId();
if (userId == null) { return TimeZone.getDefault().getID(); }
if (userId == null) { return ZoneId.systemDefault().getId(); }

String elementCacheId = "TZ_"+userId;
String element = timezoneCache.getIfPresent(elementCacheId);
Expand All @@ -1262,8 +1261,19 @@ public String getUserTimeZone() {
ResourceProperties tzProps = prefs.getProperties(TimeService.APPLICATION_ID);
String timeZone = tzProps.getProperty(TimeService.TIMEZONE_KEY);

try {
ZoneId.of(timeZone);
} catch(java.time.zone.ZoneRulesException e){
try {
//maybe the given zoneId was a shortId (like 'CST')
timeZone = ZoneId.SHORT_IDS.get(timeZone);
}catch(Exception ex){
timeZone = null;
}
}

if(StringUtils.isBlank(timeZone)) {
timeZone = TimeZone.getDefault().getID();
timeZone = ZoneId.systemDefault().getId();
}

timezoneCache.put(elementCacheId, timeZone);
Expand Down

0 comments on commit b93494a

Please sign in to comment.