List of usage examples for org.joda.time DateTimeZone forOffsetMillis
public static DateTimeZone forOffsetMillis(int millisOffset)
From source file:org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder.java
License:Apache License
DateTimeZone rewriteTimeZone(QueryShardContext context) throws IOException { final DateTimeZone tz = timeZone(); if (field() != null && tz != null && tz.isFixed() == false && field() != null && script() == null) { final MappedFieldType ft = context.fieldMapper(field()); final IndexReader reader = context.getIndexReader(); if (ft != null && reader != null) { Long anyInstant = null; final IndexNumericFieldData fieldData = context.getForField(ft); for (LeafReaderContext ctx : reader.leaves()) { AtomicNumericFieldData leafFD = fieldData.load(ctx); SortedNumericDocValues values = leafFD.getLongValues(); if (values.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { anyInstant = values.nextValue(); break; }//from www.jav a 2s . c o m } if (anyInstant != null) { final long prevTransition = tz.previousTransition(anyInstant); final long nextTransition = tz.nextTransition(anyInstant); // We need all not only values but also rounded values to be within // [prevTransition, nextTransition]. final long low; DateTimeUnit intervalAsUnit = getIntervalAsDateTimeUnit(); if (intervalAsUnit != null) { final DateTimeField dateTimeField = intervalAsUnit.field(tz); low = dateTimeField.roundCeiling(prevTransition); } else { final TimeValue intervalAsMillis = getIntervalAsTimeValue(); low = Math.addExact(prevTransition, intervalAsMillis.millis()); } // rounding rounds down, so 'nextTransition' is a good upper bound final long high = nextTransition; if (ft.isFieldWithinQuery(reader, low, high, true, false, DateTimeZone.UTC, EPOCH_MILLIS_PARSER, context) == Relation.WITHIN) { // All values in this reader have the same offset despite daylight saving times. // This is very common for location-based timezones such as Europe/Paris in // combination with time-based indices. return DateTimeZone.forOffsetMillis(tz.getOffset(anyInstant)); } } } } return tz; }
From source file:org.jadira.usertype.dateandtime.joda.AbstractMultiColumnDateMidnight.java
License:Apache License
@Override protected Object[] toConvertedColumns(DateMidnight value) { return new Object[] { value.toLocalDate(), new DateTimeZoneWithOffset(value.getZone(), value.getZone().isFixed() ? null : DateTimeZone.forOffsetMillis(value.getZone().getOffset(value))) }; }
From source file:org.jadira.usertype.dateandtime.joda.PersistentDateTimeAndZoneWithOffset.java
License:Apache License
@Override protected Object[] toConvertedColumns(DateTime value) { final DateTime myValue; if (databaseZone == null) { myValue = value;// ww w . j av a 2s .c o m } else { myValue = value.withZone(databaseZone); } return new Object[] { myValue.toLocalDateTime(), new DateTimeZoneWithOffset(value.getZone(), value.getZone().isFixed() ? null : DateTimeZone.forOffsetMillis(value.getZone().getOffset(value))) }; }
From source file:org.jadira.usertype.dateandtime.joda.util.DateTimeZoneWithOffset.java
License:Apache License
public DateTimeZoneWithOffset(ReadableInstant instant) { this(instant.getZone(), DateTimeZone.forOffsetMillis(instant.getZone().getOffset(instant))); }
From source file:org.jruby.ext.date.RubyDate.java
License:LGPL
static Chronology getChronology(ThreadContext context, final long sg, final int off) { final DateTimeZone zone; if (off == 0) { if (sg == ITALY) return CHRONO_ITALY_UTC; zone = DateTimeZone.UTC;/*w w w . jav a 2 s . c o m*/ } else { try { zone = DateTimeZone.forOffsetMillis(off * 1000); // off in seconds } // NOTE: JODA only allows 'valid': -23:59:59.999 to +23:59:59.999 catch (IllegalArgumentException ex) { // while MRI handles 25/24 fine debug(context, "invalid offset", ex); throw context.runtime.newArgumentError("invalid offset: " + off); } } return getChronology(context, sg, zone); }
From source file:org.jruby.RubyTime.java
License:LGPL
private static DateTimeZone timeZoneWithOffset(String zoneName, int offset) { if (zoneName.isEmpty()) { return DateTimeZone.forOffsetMillis(offset); } else {/*www .j ava 2 s . c o m*/ return new FixedDateTimeZone(zoneName, null, offset, offset); } }
From source file:org.jruby.RubyTime.java
License:LGPL
private IRubyObject inspectCommon(DateTimeFormatter formatter, DateTimeFormatter utcFormatter) { DateTimeFormatter simpleDateFormat; if (dt.getZone() == DateTimeZone.UTC) { simpleDateFormat = utcFormatter; } else {//from w ww . j a va2 s . c om simpleDateFormat = formatter; } String result = simpleDateFormat.print(dt); if (isTzRelative) { // display format needs to invert the UTC offset if this object was // created with a specific offset in the 7-arg form of #new DateTimeZone dtz = dt.getZone(); int offset = dtz.toTimeZone().getOffset(dt.getMillis()); DateTimeZone invertedDTZ = DateTimeZone.forOffsetMillis(offset); DateTime invertedDT = dt.withZone(invertedDTZ); result = simpleDateFormat.print(invertedDT); } return RubyString.newString(getRuntime(), result, USASCIIEncoding.INSTANCE); }
From source file:org.jvyamlb.SafeConstructorImpl.java
public static Object constructYamlTimestamp(final Constructor ctor, final Node node) { Matcher match = YMD_REGEXP.matcher(node.getValue().toString()); if (match.matches()) { final String year_s = match.group(1); final String month_s = match.group(2); final String day_s = match.group(3); DateTime dt = new DateTime(0, 1, 1, 0, 0, 0, 0); if (year_s != null) { dt = dt.withYear(Integer.parseInt(year_s)); }// w w w . j a va 2s . co m if (month_s != null) { dt = dt.withMonthOfYear(Integer.parseInt(month_s)); } if (day_s != null) { dt = dt.withDayOfMonth(Integer.parseInt(day_s)); } return new Object[] { dt }; } match = TIMESTAMP_REGEXP.matcher(node.getValue().toString()); if (!match.matches()) { return new Object[] { ctor.constructPrivateType(node) }; } final String year_s = match.group(1); final String month_s = match.group(2); final String day_s = match.group(3); final String hour_s = match.group(4); final String min_s = match.group(5); final String sec_s = match.group(6); final String fract_s = match.group(7); final String utc = match.group(8); final String timezoneh_s = match.group(9); final String timezonem_s = match.group(10); int usec = 0; if (fract_s != null) { usec = Integer.parseInt(fract_s); if (usec != 0) { while (10 * usec < 1000) { usec *= 10; } } } DateTime dt = new DateTime(0, 1, 1, 0, 0, 0, 0); if ("Z".equalsIgnoreCase(utc)) { dt = dt.withZone(DateTimeZone.forID("Etc/GMT")); } else { if (timezoneh_s != null || timezonem_s != null) { int zone = 0; int sign = +1; if (timezoneh_s != null) { if (timezoneh_s.startsWith("-")) { sign = -1; } zone += Integer.parseInt(timezoneh_s.substring(1)) * 3600000; } if (timezonem_s != null) { zone += Integer.parseInt(timezonem_s) * 60000; } dt = dt.withZone(DateTimeZone.forOffsetMillis(sign * zone)); } } if (year_s != null) { dt = dt.withYear(Integer.parseInt(year_s)); } if (month_s != null) { dt = dt.withMonthOfYear(Integer.parseInt(month_s)); } if (day_s != null) { dt = dt.withDayOfMonth(Integer.parseInt(day_s)); } if (hour_s != null) { dt = dt.withHourOfDay(Integer.parseInt(hour_s)); } if (min_s != null) { dt = dt.withMinuteOfHour(Integer.parseInt(min_s)); } if (sec_s != null) { dt = dt.withSecondOfMinute(Integer.parseInt(sec_s)); } dt = dt.withMillisOfSecond(usec / 1000); return new Object[] { dt, new Integer(usec % 1000) }; }
From source file:org.killbill.billing.util.account.AccountDateTimeUtils.java
License:Apache License
public static DateTimeZone getFixedOffsetTimeZone(final DateTimeZone referenceDateTimeZone, final Entity account) { final DateTime referenceDateTime = getReferenceDateTime(account); // Check if DST was in effect at the reference date time final boolean shouldUseDST = !referenceDateTimeZone.isStandardOffset(referenceDateTime.getMillis()); if (shouldUseDST) { return DateTimeZone.forOffsetMillis(referenceDateTimeZone.getOffset(referenceDateTime.getMillis())); } else {// w w w .j a va2s . com return DateTimeZone .forOffsetMillis(referenceDateTimeZone.getStandardOffset(referenceDateTime.getMillis())); } }
From source file:org.mulgara.store.stringpool.xa.SPDateImpl.java
License:Mozilla Public License
public String getLexicalForm() { if (timezoneOffset == Integer.MIN_VALUE) { // no timezone information return ISODateTimeFormat.date().withZone(DateTimeZone.UTC).print(date.getTime()); }/*from w ww . j a va 2 s . c om*/ DateTimeZone zone = DateTimeZone.forOffsetMillis(timezoneOffset * MILLIS_IN_MINUTE); return outputFormat.withZone(zone).print(date.getTime()); }