Example usage for org.joda.time DateTimeZone forID

List of usage examples for org.joda.time DateTimeZone forID

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone forID.

Prototype

@FromString
public static DateTimeZone forID(String id) 

Source Link

Document

Gets a time zone instance for the specified time zone id.

Usage

From source file:com.foundationdb.server.types.mcompat.mfuncs.MWeek.java

License:Open Source License

@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs,
        ValueTarget output) {/*from   w  ww.  j  av a  2s .c  om*/
    int date = inputs.get(0).getInt32();
    long ymd[] = MDateAndTime.decodeDate(date);
    int mode = getMode(context, inputs);
    if (!MDateAndTime.isValidDateTime(ymd, ZeroFlag.YEAR) || mode < 0) {
        context.warnClient(new InvalidDateFormatException("date", Integer.toString(date)));
        output.putNull();
    } else {
        output.putInt32(
                modes[(int) mode].getWeek(new MutableDateTime(DateTimeZone.forID(context.getCurrentTimezone())),
                        (int) ymd[0], (int) ymd[1], (int) ymd[2]));
    }
}

From source file:com.foundationdb.server.types.mcompat.mfuncs.MYearWeek.java

License:Open Source License

@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs,
        ValueTarget output) {/*from ww w.  j  av  a 2  s  .  c o m*/
    int date = inputs.get(0).getInt32();
    long ymd[] = MDateAndTime.decodeDate(date);
    int mode = getMode(context, inputs);
    if (!MDateAndTime.isValidDateTime(ymd, ZeroFlag.YEAR) || mode < 0) {
        context.warnClient(new InvalidDateFormatException("Invalid DATE value ", date + ""));
        output.putNull();
    } else {
        output.putInt32(modes[(int) mode].getYearWeek(
                new MutableDateTime(DateTimeZone.forID(context.getCurrentTimezone())), (int) ymd[0],
                (int) ymd[1], (int) ymd[2]));
    }
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

public static MutableDateTime toJodaDateTime(long[] dt, String tz) {
    return toJodaDateTime(dt, DateTimeZone.forID(tz));
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

/** Convert millis to a date in the given timezone and then {@link #encodeDate(long, long, long)}. */
public static int encodeDate(long millis, String tz) {
    DateTime dt = new DateTime(millis, DateTimeZone.forID(tz));
    return encodeDate(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth());
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

/** Convert millis to a DateTime and {@link #encodeDateTime(BaseDateTime)}. */
public static long encodeDateTime(long millis, String tz) {
    DateTime dt = new DateTime(millis, DateTimeZone.forID(tz));
    return encodeDateTime(dt);
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

/** Convert {@code millis} to a DateTime and {@link #encodeTime(long, long, long, TExecutionContext)}. */
public static int encodeTime(long millis, String tz) {
    DateTime dt = new DateTime(millis, DateTimeZone.forID(tz));
    return encodeTime(dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute(), null);
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

/** Decode {@code encodedTimestamp} using the {@code tz} timezone. */
public static long[] decodeTimestamp(long encodedTimestamp, String tz) {
    DateTime dt = new DateTime(encodedTimestamp * 1000L, DateTimeZone.forID(tz));
    return new long[] { dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(),
            dt.getMinuteOfHour(), dt.getSecondOfMinute() };
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

/** Parse an hour:min or named timezone. */
public static DateTimeZone parseTimeZone(String tz) {
    try {/*from w  w  w. j  a va  2s .  co  m*/
        Matcher m = TZ_PATTERN.matcher(tz);
        if (m.matches()) {
            int hourSign = "-".equals(m.group(TZ_SIGN_GROUP)) ? -1 : 1;
            int hour = Integer.parseInt(m.group(TZ_HOUR_GROUP));
            int min = Integer.parseInt(m.group(TZ_MINUTE_GROUP));
            return DateTimeZone.forOffsetHoursMinutes(hourSign * hour, min);
        } else {
            // Upper 'utc' but not 'America/New_York'
            if (tz.indexOf('/') == -1) {
                tz = tz.toUpperCase();
            }
            return DateTimeZone.forID(tz);
        }
    } catch (IllegalArgumentException e) {
        throw new InvalidDateFormatException("timezone", tz);
    }
}

From source file:com.funambol.common.pim.converter.CachedTimeZoneHelper.java

License:Open Source License

@Override
public List<Property> getXVCalendarProperties() {

    List<Property> properties = new ArrayList<Property>();
    Map<Integer, String> cache;
    String id = toID();// w w w.  j a  va2 s .com

    synchronized (cache10) { // Acquires lock on cache10

        // Checks the cache for elements needed
        cache: if (cache10.containsKey(id)) { // cached

            cache = cache10.get(id);

            if (!cache.containsKey(FIXED_KEY)) { // not a fixed time zone
                DateTimeZone dtz = DateTimeZone.forID(id);
                int since = TimeZoneHelper.year(fixFrom(dtz, dtz.getStandardOffset(from), from));
                int until = TimeZoneHelper.year(to);
                for (int year = since; year <= until; year++) {
                    if (!cache.containsKey(Integer.valueOf(year))) {
                        break cache; // not enough transitions in cache
                    }
                }
                // All transitions are in cache: they will just be retrieved
                properties.add(new Property("TZ", cache.get(TZ_KEY)));
                for (int year = since; year <= until; year++) {
                    properties.add(new Property("DAYLIGHT", cache.get(Integer.valueOf(year))));
                }
                return properties;

            } else { // a fixed time zone
                properties.add(new Property("TZ", cache.get(TZ_KEY)));
                properties.add(new Property("DAYLIGHT", "FALSE"));
                return properties;
            }

        } else { // not in cache, must be created
            cache = new Hashtable<Integer, String>();
            cache10.put(id, cache);
        }

        // Creates elements missing in the cache
        Property tz = getTZ();
        properties.add(tz);
        cache.put(TZ_KEY, tz.getValue());

        List<Property> dayLightList = getDaylightList();
        properties.addAll(dayLightList);
        for (Property dayLight : dayLightList) {
            Integer year = Integer.valueOf(year(dayLight));
            if (!cache.containsKey(year)) {
                cache.put(year, dayLight.getValue());
            }
        }

    } // Releases lock on cache10

    return properties;
}

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  w w w  .ja v  a 2 s. c  o  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);
        }
    }
}