List of usage examples for org.joda.time DateTimeZone previousTransition
public abstract long previousTransition(long instant);
From source file:com.funambol.common.pim.converter.TimeZoneHelper.java
License:Open Source License
protected long fixFrom(DateTimeZone tz, int standardOffset, long from) { if (standardOffset != tz.getOffset(from)) { // NB: this must NOT be // a call to getBasicOffset(), because that method may be // overriden by the cached implementation(s) of this class. do {//from ww w . j a v a 2 s.co m from = tz.previousTransition(from) + 1; } while ((from != 0) && (standardOffset == tz.getOffset(from))); } else { from = tz.nextTransition(from); } return from; }
From source file:divconq.util.TimeUtil.java
License:Open Source License
/** * get the DST end transition for a given year * //from w w w. j av a 2s .co m * @param zone timezone to use for DST rules * @param year the year to use, e.g. 2012 * @return datetime of the end transition */ public static DateTime endDST(DateTimeZone zone, int year) { return new DateTime(zone.previousTransition(new DateTime(year + 1, 1, 1, 0, 0, 0, 0, zone).getMillis())); }
From source file:divconq.util.TimeUtil.java
License:Open Source License
/** * get the DST end transition for a given year * //from w ww .j a v a 2 s . co m * @param year the year to use, e.g. 2012 * @return datetime of the end transition */ public static DateTime endDST(int year) { DateTimeZone zone = DateTimeZone.getDefault(); return new DateTime(zone.previousTransition(new DateTime(year + 1, 1, 1, 0, 0, 0, 0, zone).getMillis())); }
From source file:net.danlew.android.joda.ZoneInfoCompiler.java
License:Apache License
/** * @return false if error./*from w ww. j a va 2 s . c om*/ */ static boolean test(String id, DateTimeZone tz) { if (!id.equals(tz.getID())) { return true; } // Test to ensure that reported transitions are not duplicated. long millis = ISOChronology.getInstanceUTC().year().set(0, 1850); long end = ISOChronology.getInstanceUTC().year().set(0, 2050); int offset = tz.getOffset(millis); String key = tz.getNameKey(millis); List<Long> transitions = new ArrayList<Long>(); while (true) { long next = tz.nextTransition(millis); if (next == millis || next > end) { break; } millis = next; int nextOffset = tz.getOffset(millis); String nextKey = tz.getNameKey(millis); if (offset == nextOffset && key.equals(nextKey)) { System.out.println( "*d* Error in " + tz.getID() + " " + new DateTime(millis, ISOChronology.getInstanceUTC())); return false; } if (nextKey == null || (nextKey.length() < 3 && !"??".equals(nextKey))) { System.out.println("*s* Error in " + tz.getID() + " " + new DateTime(millis, ISOChronology.getInstanceUTC()) + ", nameKey=" + nextKey); return false; } transitions.add(Long.valueOf(millis)); offset = nextOffset; key = nextKey; } // Now verify that reverse transitions match up. millis = ISOChronology.getInstanceUTC().year().set(0, 2050); end = ISOChronology.getInstanceUTC().year().set(0, 1850); for (int i = transitions.size(); --i >= 0;) { long prev = tz.previousTransition(millis); if (prev == millis || prev < end) { break; } millis = prev; long trans = transitions.get(i).longValue(); if (trans - 1 != millis) { System.out.println( "*r* Error in " + tz.getID() + " " + new DateTime(millis, ISOChronology.getInstanceUTC()) + " != " + new DateTime(trans - 1, ISOChronology.getInstanceUTC())); return false; } } return true; }
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 ww w . j a v a 2 s. 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.teavm.classlib.impl.tz.ZoneInfoCompiler.java
License:Apache License
/** * @return false if error./*from w ww .ja v a2 s .c o m*/ */ static boolean test(String id, DateTimeZone tz) { if (!id.equals(tz.getID())) { return true; } // Test to ensure that reported transitions are not duplicated. long millis = ISOChronology.getInstanceUTC().year().set(0, 1850); long end = ISOChronology.getInstanceUTC().year().set(0, 2050); int offset = tz.getOffset(millis); List<Long> transitions = new ArrayList<>(); while (true) { long next = tz.nextTransition(millis); if (next == millis || next > end) { break; } millis = next; int nextOffset = tz.getOffset(millis); if (offset == nextOffset) { System.out.println( "*d* Error in " + tz.getID() + " " + new DateTime(millis, ISOChronology.getInstanceUTC())); return false; } transitions.add(Long.valueOf(millis)); offset = nextOffset; } // Now verify that reverse transitions match up. millis = ISOChronology.getInstanceUTC().year().set(0, 2050); end = ISOChronology.getInstanceUTC().year().set(0, 1850); for (int i = transitions.size(); --i >= 0;) { long prev = tz.previousTransition(millis); if (prev == millis || prev < end) { break; } millis = prev; long trans = transitions.get(i).longValue(); if (trans - 1 != millis) { System.out.println( "*r* Error in " + tz.getID() + " " + new DateTime(millis, ISOChronology.getInstanceUTC()) + " != " + new DateTime(trans - 1, ISOChronology.getInstanceUTC())); return false; } } return true; }