List of usage examples for org.joda.time DateTimeZone isFixed
public abstract boolean isFixed();
From source file:com.funambol.common.pim.converter.TimeZoneHelper.java
License:Open Source License
/** * Extract time-zone information from a zoneinfo (Olson database) ID and * saves them in the TimeZoneHelper fields. * * @param id the time zone ID according to the zoneinfo (Olson) database * @param from the start of the relevant time interval for the generation of * transitions (an istant expressed as a long) * @param to the end of the relevant time interval for the generation of * transitions (an istant expressed as a long) *///from ww w . j a v a 2s.co m protected void processID(String id, long from, long to) { DateTimeZone tz = DateTimeZone.forID(id); if (name == null) { // The name could have been set already using TZID // and in this case it is important not to change it name = id; // The Olson ID is perfect as a unique name } basicOffset = tz.getStandardOffset(from); transitions.clear(); if (!tz.isFixed()) { long oldFrom = from; from = fixFrom(tz, basicOffset, oldFrom); //@todo Consider case when to go beyond last transition (cycle //could become endless) while (tz.getStandardOffset(to) != tz.getOffset(to)) { to = tz.nextTransition(to); } while ((from <= to) && (oldFrom != from)) { transitions.add(new TimeZoneTransition(tz.getOffset(from), from, id)); oldFrom = from; from = tz.nextTransition(oldFrom); } } }
From source file:com.funambol.common.pim.converter.TimeZoneHelper.java
License:Open Source License
private boolean matchesID(String idToCheck) { DateTimeZone tz; try {/*from ww w . jav a 2 s .co m*/ 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.microsoft.exchange.utils.TimeZoneHelper.java
License:Open Source License
/** * Converts the given Java time zone into into the corresponding EWS representation. * * @param tz time zone to convert//from w ww . j a v a2 s .c o m * @return the resulting SerializableTimeZone object */ public static SerializableTimeZone toSerializableTimeZone(TimeZone tz) { long now = DateTimeUtils.currentTimeMillis(); DateTimeZone zone = DateTimeZone.forTimeZone(tz); int standardOffset = zone.getStandardOffset(now); SerializableTimeZone result = new SerializableTimeZone(); result.setBias(toBias(standardOffset)); // check if the zone has no transitions if (zone.isFixed()) { // fake transitions for fixed zones result.setStandardTime(FIXED_STANDARD_TIME); result.setDaylightTime(FIXED_DAYLIGHT_TIME); } else { // it is assumed that 2 subsequent transition will have both STD and DST long transition = setTransitionTime(zone, now, result); setTransitionTime(zone, transition, result); } return result; }
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 om*/ } 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.util.DateTimeZoneWithOffset.java
License:Apache License
public DateTimeZoneWithOffset(DateTimeZone standardDateTimeZone, DateTimeZone offsetDateTimeZone) { this.standardDateTimeZone = standardDateTimeZone; this.offsetDateTimeZone = offsetDateTimeZone; if (offsetDateTimeZone != null && standardDateTimeZone.isFixed()) { throw new IllegalArgumentException( "offsetDateTimeZone must be null when standardDateTimeZone is fixed"); }//www . java 2 s. c o m if (offsetDateTimeZone == null && !standardDateTimeZone.isFixed()) { throw new IllegalArgumentException( "offsetDateTimeZone must be not null when standardDateTimeZone is not fixed"); } }