List of usage examples for org.joda.time DateTimeZone forID
@FromString public static DateTimeZone forID(String id)
From source file:com.funambol.common.pim.converter.TimeZoneHelper.java
License:Open Source License
private boolean matchesID(String idToCheck) { DateTimeZone tz;//from ww w. j a va 2 s . c om try { tz = DateTimeZone.forID(idToCheck); } catch (IllegalArgumentException e) { // the ID is not recognized return false; } if (getTransitions().size() == 0) { // No transitions if (tz.getStandardOffset(REFERENCE_TIME) != basicOffset) { return false; // Offsets don't match: wrong guess } if (tz.isFixed() || (REFERENCE_TIME == tz.nextTransition(REFERENCE_TIME))) { return true; // A right fixed or currently-fixed time zone // has been found } return false; // Wrong guess } long t = getTransitions().get(0).getTime() - 1; if (tz.getStandardOffset(t) != basicOffset) { return false; // Wrong guess } for (TimeZoneTransition transition : getTransitions()) { t = tz.nextTransition(t); if (!isClose(t, transition.getTime())) { return false; // Wrong guess } if (tz.getOffset(t) != transition.getOffset()) { return false; // Wrong guess } } return true; // A right non-fixed time zone has been found }
From source file:com.funambol.common.pim.converter.TimeZoneHelper.java
License:Open Source License
/** * Looks for a substring that corresponds to an Olson ID. * /*from w w w.jav a 2 s .co m*/ * @param label the string to search through * @return the substring that represents an Olson ID */ private String extractID(String label) { Matcher matcher = OLSON_ID_PATTERN.matcher(label); if (matcher.find()) { String id = matcher.group(); try { DateTimeZone.forID(id); // just to check whether it exists } catch (IllegalArgumentException e) { // not found return null; } return id; } return null; }
From source file:com.getperka.flatpack.codexes.DateTimeZoneCodex.java
License:Apache License
@Override public DateTimeZone readNotNull(JsonElement element, DeserializationContext context) { return DateTimeZone.forID(element.getAsString()); }
From source file:com.github.jasonruckman.sidney.ext.common.JodaDateTimeSerializer.java
License:Apache License
@Override public DateTime readValue(Contexts.ReadContext context) { long m = millis.readLong(context); Chronology chronology = chrono.readValue(context); String zone = tz.readValue(context); return new DateTime(m, chronology.withZone(DateTimeZone.forID(zone))); }
From source file:com.github.markserrano.jsonquery.jpa.util.DateTimeZoneRule.java
License:Apache License
public DateTimeZoneRule(String zoneId) throws IllegalArgumentException { this(DateTimeZone.forID(zoneId)); }
From source file:com.github.markserrano.jsonquery.jpa.util.DateTimeZoneRule.java
License:Apache License
@Override public Statement apply(final Statement statement, final FrameworkMethod frameworkMethod, Object target) { return new Statement() { @Override//from ww w . j av a 2 s .c o m public void evaluate() throws Throwable { before(); try { DateTimeZoneModifier annotation = frameworkMethod.getAnnotation(DateTimeZoneModifier.class); if (annotation == null) { statement.evaluate(); } else { DateTimeZone.setDefault(DateTimeZone.forID(annotation.value())); } } finally { after(); } } }; }
From source file:com.google.maps.internal.DateTimeAdapter.java
License:Open Source License
/** * Read a Time object from a Directions API result and convert it to a {@link DateTime}. * * <p>We are expecting to receive something akin to the following: * <pre>/*from ww w .j ava2 s . c o m*/ * { * "text" : "4:27pm", * "time_zone" : "Australia/Sydney", * "value" : 1406528829 * } * </pre> */ @Override public DateTime read(JsonReader reader) throws IOException { if (reader.peek() == JsonToken.NULL) { reader.nextNull(); return null; } String timeZoneId = ""; long secondsSinceEpoch = 0L; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("text")) { // Ignore the human readable rendering. reader.nextString(); } else if (name.equals("time_zone")) { timeZoneId = reader.nextString(); } else if (name.equals("value")) { secondsSinceEpoch = reader.nextLong(); } } reader.endObject(); return new DateTime(secondsSinceEpoch * 1000, DateTimeZone.forID(timeZoneId)); }
From source file:com.google.sampling.experiential.model.Event.java
License:Open Source License
public static DateTime getTimeZoneAdjustedDate(Date time, String defaultTimeZone, String timeZone) { if (time == null) { return null; }/*from w ww. java 2s . co m*/ if (Strings.isNullOrEmpty(timeZone)) { if (Strings.isNullOrEmpty(defaultTimeZone)) { return new DateTime(time); } else { DateTimeZone timezoneForOffsetHours = DateTimeZone.forID(defaultTimeZone); if (timezoneForOffsetHours == null) { return new DateTime(time); } return new DateTime(time).withZone(timezoneForOffsetHours); } } else { String hours = timeZone.substring(0, 3); if (hours.startsWith("+")) { hours = hours.substring(1); } int parseInt; try { parseInt = Integer.parseInt(hours); } catch (NumberFormatException e) { EventServlet.log.info("Timezone hours are not an integer this event."); return new DateTime(time); } DateTimeZone timezoneForOffsetHours = DateTimeZone.forOffsetHours(parseInt); if (timezoneForOffsetHours == null) { return new DateTime(time); } return new DateTime(time).withZone(timezoneForOffsetHours); } }
From source file:com.google.sampling.experiential.server.BackendReportJobExecutorServlet.java
License:Open Source License
public static DateTimeZone getTimeZoneForClient(HttpServletRequest req) { String tzStr = getParam(req, "tz"); if (tzStr != null && !tzStr.isEmpty()) { try {//w w w.ja va 2 s .co m DateTimeZone jodaTimeZone = DateTimeZone.forID(tzStr); return jodaTimeZone; } catch (Exception e) { log.warning("Could not get DateTimeZone for string: " + tzStr); } } Locale clientLocale = req.getLocale(); Calendar calendar = Calendar.getInstance(clientLocale); TimeZone clientTimeZone = calendar.getTimeZone(); DateTimeZone jodaTimeZone = DateTimeZone.forTimeZone(clientTimeZone); return jodaTimeZone; }
From source file:com.google.sampling.experiential.server.EventRetriever.java
License:Open Source License
public static Date adjustTimeToTimezoneIfNecesssary(String tz, Date responseTime) { if (responseTime == null) { return null; }/*from w w w. j ava 2s .c o m*/ DateTimeZone timezone = null; if (tz != null) { timezone = DateTimeZone.forID(tz); } if (timezone != null && responseTime.getTimezoneOffset() != timezone.getOffset(responseTime.getTime())) { responseTime = new DateTime(responseTime).withZone(timezone).toDate(); } return responseTime; }