Skip to content

Commit

Permalink
MGR-100 fix timezones
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Feb 14, 2020
1 parent f3a9813 commit e5cca4b
Show file tree
Hide file tree
Showing 6 changed files with 2,364 additions and 2,369 deletions.
Expand Up @@ -20,6 +20,8 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -1221,14 +1223,10 @@ private Selection getTimezoneSelection(Locale locale, String timeZone) {
value.setId(MessageConstants.TIMEZONE);
timezoneSelection.setTitle(value);
timezoneSelection.setType(SelectionType.SELECT);
List<String> ids = Arrays.asList(TimeZone.getAvailableIDs());
Collections.sort(ids);
List<TimeZone> timeZones = new ArrayList<>();
for (String id : ids) {
if (id.matches("(Africa|America|Antarctica|Asia|Atlantic|Australia|Europe|Indian|Pacific).*")) {
timeZones.add(TimeZone.getTimeZone(id));
}
}
String allowedTimeZones = "(Africa|America|Antarctica|Asia|Atlantic|Australia|Europe|Indian|Pacific).*";
List<TimeZone> timeZones = Arrays.asList(TimeZone.getAvailableIDs()).stream()
.filter(id -> id.matches(allowedTimeZones)).sorted().map(id -> TimeZone.getTimeZone(id))
.collect(Collectors.toList());

String groupName = "";
for (TimeZone tz : timeZones) {
Expand All @@ -1253,12 +1251,9 @@ private Selection getTimezoneSelection(Locale locale, String timeZone) {
groupName = area;
Option opt = new Option();
String locationName = timezoneMessages.getMessage(areaKey + "." + location, new Object[0], locale);
double offset = (double) tz.getRawOffset() / 1000 / 60 / 60;
int hours = (int) offset;
int minutes = Math.abs((int) (60 * (double) (offset - hours)));
String gmtTimezone = "GMT" + (offset >= 0 ? "+" : "") + StringUtils.leftPad(String.valueOf(hours), 2, "0")
+ ":" + StringUtils.leftPad(String.valueOf(minutes), 2, "0");
opt.setName(locationName + " (" + gmtTimezone + ")");
ZoneOffset zoneOffset = LocalDateTime.now().atZone(tz.toZoneId()).getOffset();
String offset = "Z".equals(zoneOffset.getId()) ? "" : zoneOffset.getId();
opt.setName(locationName + " (UTC" + offset + ")");
opt.setValue(id);
opt.setSelected(id.equals(timeZone));
group.getOptions().add(opt);
Expand Down

0 comments on commit e5cca4b

Please sign in to comment.