public static void setTimezone(String tz) { Set<String> idSet = DateTimeZone.getAvailableIDs(); if(idSet.contains(tz)) _timezone = DateTimeZone.forID(tz); else Log.err("Attempted to set unrecognized timezone: "+ tz); }
@Override protected void execImpl() { Set<String> idSet = DateTimeZone.getAvailableIDs(); if(!idSet.contains(tz)) throw new IllegalArgumentException("Unacceptable timezone name given. For a list of acceptable names, use listTimezone()."); SetTimezoneTask task = new SetTimezoneTask(); task._tz = tz; task.invokeOnAllNodes(); }
public DateTimeZone deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonNull()) return null; String tz = json.getAsString(); if (tz.isEmpty()) // defaults to UTC return DateTimeZone.UTC; DateTimeZone timeZone; try { // check if time zone is valid timeZone = DateTimeZone.forID(tz); } catch (IllegalArgumentException e) { throw new ContextualJsonSyntaxException(tz, "is not a valid time zone, must be one of " + DateTimeZone.getAvailableIDs()); } return timeZone; } }
TreeSet<String> jodaZones = new TreeSet<>(DateTimeZone.getAvailableIDs()); TreeSet<String> jdkZones = new TreeSet<>(Arrays.asList(TimeZone.getAvailableIDs()));
public static String listTimezones() { DateTimeFormatter offsetFormatter = new DateTimeFormatterBuilder().appendTimeZoneOffset(null, true, 2, 4).toFormatter(); Set<String> idSet = DateTimeZone.getAvailableIDs(); Map<String, String> tzMap = new TreeMap(); Iterator<String> it = idSet.iterator(); String id, cid, offset, key, output; DateTimeZone tz; int i = 0; long millis = System.currentTimeMillis(); // collect canonical and alias IDs into a map while (it.hasNext()) { id = it.next(); tz = DateTimeZone.forID(id); cid = tz.getID(); offset = offsetFormatter.withZone(tz).print(tz.getStandardOffset(millis)); key = offset + " " + cid; if (id == cid) { // Canonical ID if (!tzMap.containsKey(key)) tzMap.put(key, ""); } else {// alias ID if (!tzMap.containsKey(key)) tzMap.put(key, id); else tzMap.put(key, tzMap.get(key) + ", " + id); } } // assemble result output = "StandardOffset CanonicalID, Aliases\n"; for (Map.Entry<String, String> e : tzMap.entrySet()) output += e.getKey() + e.getValue()+"\n"; return output; }
static DateTimeZone nonDefaultTimeZone() { String defaultId = DateTimeZone.getDefault().getID(); for (String id : DateTimeZone.getAvailableIDs()) { if (!id.equals(defaultId)) { DateTimeZone zone = DateTimeZone.forID(id); if (zone.getStandardOffset(0) != 0) { return zone; } } } throw new IllegalStateException("no non-default timezone"); } }
@Test public void testGetAvailableIDs() { assertTrue(DateTimeZone.getAvailableIDs().contains("UTC")); }
TreeSet<String> jodaZones = new TreeSet<>(DateTimeZone.getAvailableIDs()); TreeSet<String> jdkZones = new TreeSet<>(ZoneId.getAvailableZoneIds());
Multimap<Integer, DateTimeZone> timeZones = LinkedHashMultimap.create(); for (Object obj : DateTimeZone.getAvailableIDs()) { String id = (String) obj; DateTimeZone dateTimeZone = DateTimeZone.forID(id);
public static Set<String> getAvailableIDs() { return DateTimeZone.getAvailableIDs(); }
public static Set<String> getAvailableIDs() { return DateTimeZone.getAvailableIDs(); }
public static DateTimeZone forId(String id) { try { return DateTimeZone.forID(id); } catch (IllegalArgumentException e) { throw new RuntimeException("Unable to find timezone for id '" + id + "'. Consider one of these:" + DateTimeZone.getAvailableIDs()); } } }
public static DateTimeZone forId(String id) { try { return DateTimeZone.forID(id); } catch (IllegalArgumentException e) { throw new RuntimeException("Unable to find timezone for id '" + id + "'. Consider one of these:" + DateTimeZone.getAvailableIDs()); } } }
/** * generate a random DateTimeZone from the ones available in joda library */ public static DateTimeZone randomDateTimeZone() { List<String> ids = new ArrayList<>(DateTimeZone.getAvailableIDs()); Collections.sort(ids); return DateTimeZone.forID(randomFrom(ids)); }
public static void setupAvailableZoneIds() { TreeSet<String> sortedZoneIDs = new TreeSet<>(DateTimeZone.getAvailableIDs()); Properties props = UDFContext.getUDFContext().getUDFProperties( PigImplConstants.PIG_DATETIME_ZONES_LIST.getClass()); props.setProperty(PigImplConstants.PIG_DATETIME_ZONES_LIST, StringUtils.arrayToString( sortedZoneIDs.toArray(new String[0]))); }
public String getOutputTimezone() { if (!containsParameter(OUTPUT_TIMEZONE)) { return DEFAULT_OUTPUT_TIMEZONE; } String timezone = getAsString(OUTPUT_TIMEZONE); Set<String> availableIDs = DateTimeZone.getAvailableIDs(); DateTimeZone zone = availableIDs.contains(timezone) ? DateTimeZone.forID(timezone) : DateTimeZone.UTC; return zone.toString(); }
public void setOutputTimezone(String timezone) { Set<String> availableIDs = DateTimeZone.getAvailableIDs(); DateTimeZone zone = availableIDs.contains(timezone) ? DateTimeZone.forID(timezone) : DateTimeZone.UTC; setParameter(Parameters.OUTPUT_TIMEZONE, IoParameters.getJsonNodeFrom(zone.getID())); }
public void setOutputTimezone(String timezone) { DateTimeZone zone = DateTimeZone.getAvailableIDs() .contains(timezone) ? DateTimeZone.forID(timezone) : DateTimeZone.UTC; addParameter("outputTimezone", IoParameters.getJsonNodeFrom(zone.getID())); }
static DateTimeZone nonDefaultTimeZone() { String defaultId = DateTimeZone.getDefault().getID(); for (String id : DateTimeZone.getAvailableIDs()) { if (!id.equals(defaultId)) { DateTimeZone zone = DateTimeZone.forID(id); if (zone.getStandardOffset(0) != 0) { return zone; } } } throw new IllegalStateException("no non-default timezone"); } }
static DateTimeZone nonDefaultTimeZone() { String defaultId = DateTimeZone.getDefault().getID(); for (String id : DateTimeZone.getAvailableIDs()) { if (!id.equals(defaultId)) { DateTimeZone zone = DateTimeZone.forID(id); if (zone.getStandardOffset(0) != 0) { return zone; } } } throw new IllegalStateException("no non-default timezone"); } }