List of usage examples for org.joda.time DateTimeZone forID
@FromString public static DateTimeZone forID(String id)
From source file:org.codehaus.httpcache4j.HeaderUtils.java
License:Open Source License
public static DateTime fromHttpDate(Header header) { if (header == null) { return null; }//from ww w . j a v a 2 s. c o m if ("0".equals(header.getValue().trim())) { return new DateTime(1970, 1, 1, 0, 0, 0, 0).withZone(DateTimeZone.forID("UTC")); } DateTimeFormatter formatter = DateTimeFormat.forPattern(PATTERN_RFC1123).withZone(DateTimeZone.forID("UTC")) .withLocale(Locale.US); DateTime formattedDate = null; try { formattedDate = formatter.parseDateTime(header.getValue()); } catch (IllegalArgumentException ignore) { } return formattedDate; }
From source file:org.codehaus.httpcache4j.HeaderUtils.java
License:Open Source License
public static Header toHttpDate(String headerName, DateTime time) { DateTimeFormatter formatter = DateTimeFormat.forPattern(PATTERN_RFC1123).withZone(DateTimeZone.forID("UTC")) .withLocale(Locale.US); return new Header(headerName, formatter.print(time)); }
From source file:org.codehaus.httpcache4j.util.RequestWriter.java
License:Open Source License
private void writeGeneralHeaders(PrintWriter writer) { Header dateHeader = HeaderUtils.toHttpDate("Date", new DateTime(DateTimeZone.forID("UTC"))); writer.println(dateHeader);/*from w w w. ja va2s. c o m*/ writer.println("Connection: close"); }
From source file:org.codelibs.elasticsearch.common.io.stream.StreamInput.java
License:Apache License
private DateTime readDateTime() throws IOException { final String timeZoneId = readString(); return new DateTime(readLong(), DateTimeZone.forID(timeZoneId)); }
From source file:org.codelibs.elasticsearch.common.io.stream.StreamInput.java
License:Apache License
/** * Read a {@linkplain DateTimeZone}. */ public DateTimeZone readTimeZone() throws IOException { return DateTimeZone.forID(readString()); }
From source file:org.codelibs.elasticsearch.common.io.stream.StreamInput.java
License:Apache License
/** * Read an optional {@linkplain DateTimeZone}. *//* www. ja v a 2 s . c o m*/ public DateTimeZone readOptionalTimeZone() throws IOException { if (readBoolean()) { return DateTimeZone.forID(readString()); } return null; }
From source file:org.codelibs.elasticsearch.index.query.QueryStringQueryBuilder.java
License:Apache License
/** * In case of date field, we can adjust the from/to fields using a timezone *//*from www .ja v a2s. co m*/ public QueryStringQueryBuilder timeZone(String timeZone) { if (timeZone != null) { this.timeZone = DateTimeZone.forID(timeZone); } else { this.timeZone = null; } return this; }
From source file:org.codelibs.elasticsearch.index.query.RangeQueryBuilder.java
License:Apache License
/** * In case of date field, we can adjust the from/to fields using a timezone *///from www .j a v a 2 s.c o m public RangeQueryBuilder timeZone(String timeZone) { if (timeZone == null) { throw new IllegalArgumentException("timezone cannot be null"); } this.timeZone = DateTimeZone.forID(timeZone); return this; }
From source file:org.codelibs.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder.java
License:Apache License
/** * Read from a stream./*from w w w . j a v a 2s .c o m*/ */ private void read(StreamInput in) throws IOException { field = in.readOptionalString(); if (in.readBoolean()) { script = new Script(in); } if (in.readBoolean()) { valueType = ValueType.readFromStream(in); } format = in.readOptionalString(); missing = in.readGenericValue(); if (in.readBoolean()) { timeZone = DateTimeZone.forID(in.readString()); } }
From source file:org.codelibs.elasticsearch.search.aggregations.support.ValuesSourceParserHelper.java
License:Apache License
private static <VS extends ValuesSource> void declareFields( ObjectParser<? extends ValuesSourceAggregationBuilder<VS, ?>, QueryParseContext> objectParser, boolean scriptable, boolean formattable, boolean timezoneAware, ValuesSourceType valuesSourceType, ValueType targetValueType) {// w w w . j ava 2 s . c om objectParser.declareField(ValuesSourceAggregationBuilder::field, XContentParser::text, new ParseField("field"), ObjectParser.ValueType.STRING); objectParser.declareField(ValuesSourceAggregationBuilder::missing, XContentParser::objectText, new ParseField("missing"), ObjectParser.ValueType.VALUE); objectParser.declareField(ValuesSourceAggregationBuilder::valueType, p -> { ValueType valueType = ValueType.resolveForScript(p.text()); if (targetValueType != null && valueType.isNotA(targetValueType)) { throw new ParsingException(p.getTokenLocation(), "Aggregation [" + objectParser.getName() + "] was configured with an incompatible value type [" + valueType + "]. It can only work on value of type [" + targetValueType + "]"); } return valueType; }, new ParseField("value_type", "valueType"), ObjectParser.ValueType.STRING); if (formattable) { objectParser.declareField(ValuesSourceAggregationBuilder::format, XContentParser::text, new ParseField("format"), ObjectParser.ValueType.STRING); } if (scriptable) { objectParser.declareField(ValuesSourceAggregationBuilder::script, org.codelibs.elasticsearch.script.Script::parse, Script.SCRIPT_PARSE_FIELD, ObjectParser.ValueType.OBJECT_OR_STRING); } if (timezoneAware) { objectParser.declareField(ValuesSourceAggregationBuilder::timeZone, p -> { if (p.currentToken() == XContentParser.Token.VALUE_STRING) { return DateTimeZone.forID(p.text()); } else { return DateTimeZone.forOffsetHours(p.intValue()); } }, TIME_ZONE, ObjectParser.ValueType.LONG); } }