List of usage examples for org.joda.time DateTimeZone forID
@FromString public static DateTimeZone forID(String id)
From source file:com.thoughtworks.studios.shine.cruise.GoDateTime.java
License:Apache License
public static DateTime parseToUTC(String timestampString) throws GoDateTimeException { DateTimeFormatter format = ISODateTimeFormat.dateTimeNoMillis(); DateTime dateTime;/*from w ww . j a va2 s. c o m*/ try { dateTime = format.parseDateTime(timestampString); } catch (java.lang.IllegalArgumentException e) { // sigh. handle old cruise timestamp format, e.g. 2008-09-19 02:18:39 +0800 format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss Z"); try { dateTime = format.parseDateTime(timestampString); } catch (java.lang.IllegalArgumentException e2) { // give up !! throw new GoDateTimeException("Could not parse datetime " + timestampString, e2); } } return dateTime.toDateTime(DateTimeZone.forID("UTC")); }
From source file:com.thoughtworks.studios.shine.cruise.ZuluDateTimeFormatter.java
License:Apache License
public static String toZuluString(DateTime dateTime) { DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); return format.print(dateTime.toDateTime(DateTimeZone.forID("UTC"))); }
From source file:com.thoughtworks.xstream.converters.extended.ISO8601GregorianCalendarConverter.java
License:Open Source License
public Object fromString(String str) { for (int i = 0; i < formattersUTC.length; i++) { DateTimeFormatter formatter = formattersUTC[i]; try {//from w w w .ja v a 2 s. c o m DateTime dt = formatter.parseDateTime(str); Calendar calendar = dt.toGregorianCalendar(); calendar.setTimeZone(TimeZone.getDefault()); return calendar; } catch (IllegalArgumentException e) { // try with next formatter } } String timeZoneID = TimeZone.getDefault().getID(); for (int i = 0; i < formattersNoUTC.length; i++) { try { DateTimeFormatter formatter = formattersNoUTC[i].withZone(DateTimeZone.forID(timeZoneID)); DateTime dt = formatter.parseDateTime(str); Calendar calendar = dt.toGregorianCalendar(); calendar.setTimeZone(TimeZone.getDefault()); return calendar; } catch (IllegalArgumentException e) { // try with next formatter } } throw new ConversionException("Cannot parse date " + str); }
From source file:com.threewks.thundr.json.DateTimeZoneTypeConvertor.java
License:Apache License
@Override public DateTimeZone deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { return DateTimeZone.forID(json.getAsString()); }
From source file:com.tysanclan.site.projectewok.TysanPage.java
License:Open Source License
public boolean isAprilFoolsDay(int year) { final DateTime easternStandardTime = new DateTime(DateTimeZone.forID("EST")); return easternStandardTime.getDayOfMonth() == 1 && easternStandardTime.getMonthOfYear() == 4 && easternStandardTime.getYear() == year; }
From source file:com.wealdtech.jackson.modules.DateTimeZoneDeserializer.java
License:Open Source License
@Override public DateTimeZone deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { final ObjectCodec oc = jsonParser.getCodec(); final JsonNode node = oc.readTree(jsonParser); DateTimeZone result;/*from w ww .j a v a 2 s .com*/ try { result = DateTimeZone.forID(node.textValue()); } catch (IllegalArgumentException iae) { LOGGER.warn("Attempt to deserialize invalid datetimezone {}", node.textValue()); throw new IOException("Invalid datetimezone value \"" + node.textValue() + "\"", iae); } return result; }
From source file:com.wealdtech.jackson.modules.IntervalDeserializer.java
License:Open Source License
private DateTime deserializeDateTime(final JsonNode node, final String prefix) throws IOException { final JsonNode datetimenode = node.get(prefix + "datetime"); if (datetimenode == null) { LOGGER.warn("Attempt to deserialize malformed interval"); throw new IOException("Invalid interval value"); }//from w w w. j a v a 2 s .c o m final String datetime = datetimenode.textValue(); // Obtain values final JsonNode tznode = node.get(prefix + "timezone"); String timezone = null; if (tznode != null) { timezone = tznode.textValue(); } DateTime result = null; try { if ((timezone == null) || ("UTC".equals(timezone))) { result = formatter.parseDateTime(datetime).withZone(utczone); } else { result = formatter.parseDateTime(datetime).withZone(DateTimeZone.forID(timezone)); } } catch (IllegalArgumentException iae) { LOGGER.warn("Attempt to deserialize invalid interval {},{}", datetime, timezone); throw new IOException("Invalid datetime value", iae); } return result; }
From source file:com.xpn.xwiki.plugin.jodatime.JodaTimePlugin.java
License:Open Source License
/** * @see org.joda.time.DateTimeZone#forID(String) */ public DateTimeZone getTimezone(String locationOrOffset) { return DateTimeZone.forID(locationOrOffset); }
From source file:com.yahoo.bard.webservice.data.config.ConfigurationLoader.java
License:Apache License
/** * Constructor./*w ww . j av a2s . c om*/ * * @param dimensionLoader DimensionLoader to load dimensions from * @param metricLoader MetricLoader to load metrics from * @param tableLoader TableLoader to load tables from */ @Inject public ConfigurationLoader(DimensionLoader dimensionLoader, MetricLoader metricLoader, TableLoader tableLoader) { DateTimeZone.setDefault(DateTimeZone.forID(TIMEZONE)); // Set the max lucene query clauses as high as it can go BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE); this.dimensionLoader = dimensionLoader; this.metricLoader = metricLoader; this.tableLoader = tableLoader; }
From source file:com.yahoo.bard.webservice.data.PreResponseDeserializer.java
License:Apache License
/** * Generates ZonedSchema object from given JsonNode. * * @param schemaNode JsonNode which contains all the columns, timezone and granularity * * @return ResultSetSchema object generated from the JsonNode *//* w w w.j a va2 s.c o m*/ private ResultSetSchema getResultSetSchema(JsonNode schemaNode) { DateTimeZone timezone = generateTimezone(schemaNode.get(SCHEMA_TIMEZONE).asText(), DateTimeZone .forID(SYSTEM_CONFIG.getStringProperty(SYSTEM_CONFIG.getPackageVariableName("timezone"), "UTC"))); //Recreate ResultSetSchema LinkedHashSet<Column> columns = Stream .concat(Streams.stream(schemaNode.get(SCHEMA_DIM_COLUMNS)).map(JsonNode::asText) .map(this::resolveDimensionName).map(DimensionColumn::new), Streams.stream(() -> schemaNode.get(SCHEMA_METRIC_COLUMNS_TYPE).fields()).map( entry -> new MetricColumnWithValueType(entry.getKey(), entry.getValue().asText()))) .collect(Collectors.toCollection(LinkedHashSet::new)); return new ResultSetSchema(generateGranularity(schemaNode.get(SCHEMA_GRANULARITY).asText(), timezone), columns); }