List of usage examples for org.joda.time DateTimeZone getAvailableIDs
public static Set<String> getAvailableIDs()
From source file:edu.illinois.cs.cogcomp.temporal.normalizer.main.timex2interval.TimeOfDay.java
License:Open Source License
/** * This function convert a phrase with time zone * @param phrase/* ww w .j a va 2 s . c o m*/ * @return */ public static String converter(String phrase) { Set<String> zoneIds = DateTimeZone.getAvailableIDs(); for (String zoneId : zoneIds) { String longName = TimeZone.getTimeZone(zoneId).getDisplayName(); phrase = phrase.replace(longName.toLowerCase(), ""); String[] zoneList = zoneId.split("/"); // Because we have zone like UTC/GMT+1 for (String zone : zoneList) { phrase = phrase.replace(zone.toLowerCase(), ""); } } // EST wasn't in the canonical ID list in Joda time phrase = phrase.replace("est", ""); phrase = phrase.trim().replaceAll(" +", " "); return phrase; }
From source file:externalTools.TimeZoneTable.java
License:Apache License
public static void main(String[] args) throws Exception { Set idSet = DateTimeZone.getAvailableIDs(); ZoneData[] zones = new ZoneData[idSet.size()]; {/*from ww w. j a v a 2s . c o m*/ Iterator it = idSet.iterator(); int i = 0; while (it.hasNext()) { String id = (String) it.next(); zones[i++] = new ZoneData(id, DateTimeZone.forID(id)); } Arrays.sort(zones); } PrintStream out = System.out; out.println("<table>"); out.println("<tr>" + "<th align=\"left\">Standard Offset</th>" + "<th align=\"left\">Canonical ID</th>" + "<th align=\"left\">Aliases</th>" + "</tr>"); ZoneData canonical = null; List aliases = new ArrayList(); for (int i = 0; i < zones.length; i++) { ZoneData zone = zones[i]; if (!zone.isCanonical()) { aliases.add(zone); continue; } if (canonical != null) { printRow(out, canonical, aliases); } canonical = zone; aliases.clear(); } if (canonical != null) { printRow(out, canonical, aliases); } out.println("</table>"); }
From source file:imas.planning.entity.FlightEntity.java
private String convertTimezone(Date date, String countryName) { DateTime original = new DateTime(date.getTime()); DateTimeZone dtz = DateTimeZone.getDefault(); original.withZone(dtz);// w w w . ja v a 2s .c o m Set<String> tzIds = DateTimeZone.getAvailableIDs(); for (String timeZoneId : tzIds) { if (timeZoneId.contains(countryName)) { dtz = DateTimeZone.forID(timeZoneId); break; } } DateTime dt = original.toDateTime(dtz); DateTimeFormatter dtfOut = DateTimeFormat.forPattern("MMM dd yyyy HH:mm:ss zzz"); return dtfOut.print(dt); }
From source file:io.soliton.time.TimeClient.java
License:Apache License
public static void main(String... args) throws Exception { // Parse arguments TimeClient timeClient = new TimeClient(); new JCommander(timeClient, args); // Create client QuartzClient.Builder clientBuilder = QuartzClient .newClient(HostAndPort.fromParts(timeClient.hostname, timeClient.port)); if (timeClient.ssl) { clientBuilder.setSslContext(getSslContext()); }//from w ww . ja v a2 s . co m QuartzClient client = clientBuilder.build(); // Create service stub Time.TimeService.Interface timeService = Time.TimeService.newStub(client); CountDownLatch latch = new CountDownLatch(DateTimeZone.getAvailableIDs().size()); // For each known timezone, request its current local time. for (String timeZoneId : DateTimeZone.getAvailableIDs()) { DateTimeZone timeZone = DateTimeZone.forID(timeZoneId); Time.TimeRequest request = Time.TimeRequest.newBuilder().setTimezone(timeZoneId).build(); Futures.addCallback(timeService.getTime(request), new Callback(latch, timeZone), EXECUTOR); } latch.await(); client.close(); }
From source file:jp.furplag.util.Localizer.java
License:Apache License
private static DateTimeZone getDateTimeZone(final String zone) { if (zone == null) return DateTimeZone.getDefault(); if (StringUtils.isSimilarToBlank(zone)) return DateTimeZone.UTC; if (DateTimeZone.getAvailableIDs().contains(zone)) return DateTimeZone.forID(zone.toString()); if (LazyInitializer.ZONE_DUPRECATED.containsKey(zone)) return DateTimeZone.forTimeZone(TimeZone.getTimeZone(LazyInitializer.ZONE_DUPRECATED.get(zone))); if (LazyInitializer.AVAILABLE_ZONE_IDS.contains(zone)) return DateTimeZone.forTimeZone(TimeZone.getTimeZone(zone)); Matcher base = OFFSET.matcher(StringUtils.normalize(zone, true)); if (base.find()) { String offsetString = base.group(); int[] offsetTime = JSONifier.parseLazy( JSONifier.stringifyLazy(StringUtils.truncateFirst(offsetString, "[\\+\\-]").split("[:\\.]")), int[].class); if (offsetTime.length < 1) return DateTimeZone.UTC; LocalTime offset = new LocalTime(offsetTime.length > 0 ? offsetTime[0] : 0, offsetTime.length > 1 ? offsetTime[1] : 0, offsetTime.length > 2 ? offsetTime[2] : 0, offsetTime.length > 3 ? offsetTime[3] : 0); return DateTimeZone.forID((offsetString.startsWith("-") ? "-" : "+") + offset.toString(OFFSET_FORMAT)); }//from www . j a v a2 s .c o m return DateTimeZone.UTC; }
From source file:jp.furplag.util.Localizer.java
License:Apache License
private static DateTimeZone getDateTimeZone(final TimeZone zone) { if (zone == null) return DateTimeZone.getDefault(); String zoneID = ((TimeZone) zone).getID(); if (DateTimeZone.getAvailableIDs().contains(zoneID)) return DateTimeZone.forID(zoneID); if (LazyInitializer.ZONE_DUPRECATED.containsKey(zoneID)) return DateTimeZone.forTimeZone(TimeZone.getTimeZone(LazyInitializer.ZONE_DUPRECATED.get(zoneID))); return DateTimeZone.forTimeZone((TimeZone) zone); }
From source file:net.rrm.ehour.ui.admin.config.panel.MiscConfigPanel.java
License:Open Source License
private void addMiscComponents(Form<?> form) { // show turnover checkbox CheckBox showTurnover = new CheckBox("config.showTurnover"); showTurnover.setMarkupId("showTurnover"); form.add(showTurnover);/*from w ww . j a va 2s . c om*/ final MainConfigBackingBean configBackingBean = (MainConfigBackingBean) getDefaultModelObject(); // working hours TextField<Float> workHours = new TextField<>("config.completeDayHours", Float.class); workHours.setLabel(new ResourceModel("admin.config.workHours")); workHours.add(new ValidatingFormComponentAjaxBehavior()); workHours.add(RangeValidator.minimum(0f)); workHours.add(RangeValidator.maximum(24f)); workHours.setRequired(true); form.add(new AjaxFormComponentFeedbackIndicator("workHoursValidationError", workHours)); form.add(workHours); // weeks start at DropDownChoice<Date> weekStartsAt; weekStartsAt = new DropDownChoice<>("firstWeekStart", DateUtil .createDateSequence(DateUtil.getDateRangeForWeek(new GregorianCalendar()), new EhourConfigStub()), new WeekDayRenderer(configBackingBean.getLocaleLanguage())); form.add(weekStartsAt); // Timezone DropDownChoice<String> timezone = new DropDownChoice<>("config.timeZone", Lists.newArrayList(DateTimeZone.getAvailableIDs())); form.add(timezone); // pm access rights form.add(new DropDownChoice<>("config.pmPrivilege", Arrays.asList(PmPrivilege.values()), new EnumChoiceRenderer<PmPrivilege>())); // split admin role final Container convertManagersContainer = new Container("convertManagers"); DropDownChoice<UserRole> convertManagersTo = new DropDownChoice<>("convertManagersTo", Lists.newArrayList(UserRole.ADMIN, UserRole.USER), new UserRoleRenderer()); convertManagersContainer.add(convertManagersTo); convertManagersContainer.setVisible(false); form.add(convertManagersContainer); AjaxCheckBox withManagerCheckbox = new AjaxCheckBox("config.splitAdminRole") { @Override protected void onUpdate(AjaxRequestTarget target) { Boolean managersEnabled = this.getModelObject(); boolean showConvert = !managersEnabled && !userService.getUsers(UserRole.MANAGER).isEmpty(); if (convertManagersContainer.isVisible() != showConvert) { convertManagersContainer.setVisible(showConvert); target.add(convertManagersContainer); } } }; withManagerCheckbox.setMarkupId("splitAdminRole"); form.add(withManagerCheckbox); }
From source file:org.efaps.esjp.admin.user.TimeZoneUI.java
License:Apache License
/** * Method to build a drop down field for html containing all timezone. * * @param _parameter Parameter as passed by the eFaps API * @param _currentTz the current tz//from ww w .ja va2s .c om * @return StringBuilder with drop down * @throws EFapsException on error */ private List<DropDownPosition> getValues(final Parameter _parameter, final String _currentTz) throws EFapsException { final List<DropDownPosition> ret = new ArrayList<DropDownPosition>(); final Set<?> timezoneIds = DateTimeZone.getAvailableIDs(); final Field field = new Field(); for (final Object timezoneId : timezoneIds) { final DropDownPosition val = field.getDropDownPosition(_parameter, timezoneId, timezoneId); val.setSelected(timezoneId.equals(_currentTz)); ret.add(val); } Collections.sort(ret, new Comparator<DropDownPosition>() { @SuppressWarnings("unchecked") @Override public int compare(final DropDownPosition _arg0, final DropDownPosition _arg1) { return _arg0.getOrderValue().compareTo(_arg1.getOrderValue()); } }); return ret; }
From source file:org.elasticsearch.test.ESTestCase.java
License:Apache License
/** * generate a random DateTimeZone from the ones available in joda library */// www.j a v a 2 s. co m public static DateTimeZone randomDateTimeZone() { List<String> ids = new ArrayList<>(DateTimeZone.getAvailableIDs()); Collections.sort(ids); return DateTimeZone.forID(randomFrom(ids)); }
From source file:org.elasticsearch.xpack.qa.sql.jdbc.JdbcIntegrationTestCase.java
License:Open Source License
public static String randomKnownTimeZone() { // We use system default timezone for the connection that is selected randomly by TestRuleSetupAndRestoreClassEnv // from all available JDK timezones. While Joda and JDK are generally in sync, some timezones might not be known // to the current version of Joda and in this case the test might fail. To avoid that, we specify a timezone // known for both Joda and JDK Set<String> timeZones = new HashSet<>(DateTimeZone.getAvailableIDs()); timeZones.retainAll(Arrays.asList(TimeZone.getAvailableIDs())); List<String> ids = new ArrayList<>(timeZones); Collections.sort(ids);/*from ww w .j a va 2 s . c om*/ return randomFrom(ids); }