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:de.javakaffee.web.msm.serializer.javolution.JodaDateTimeFormat.java

License:Apache License

private DateTimeZone readTimeZone(final javolution.xml.XMLFormat.InputElement input) throws XMLStreamException {
    final CharArray tz = input.getAttribute(TIME_ZONE);
    return tz != null ? DateTimeZone.forID(tz.toString()) : DateTimeZone.getDefault();
}

From source file:debop4k.data.orm.hibernate.usertypes.jodatime.TimestampAndTimeZoneUserType.java

License:Apache License

@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Timestamp timestamp = (Timestamp) StandardBasicTypes.TIMESTAMP.nullSafeGet(rs, names[0], session, owner);
    String zoneId = (String) StandardBasicTypes.STRING.nullSafeGet(rs, names[1], session, owner);

    if (timestamp != null) {
        return (zoneId != null) ? new DateTime(timestamp, DateTimeZone.forID(zoneId))
                : new DateTime(timestamp, DateTimeZone.UTC);
    } else {/*from ww w  .ja v a  2s  .c  om*/
        return null;
    }
}

From source file:divconq.hub.Clock.java

License:Open Source License

/**
 * Called from Hub.start this method configures the clock features.
 * //w w  w  . ja v a  2  s . co  m
 * @param or logger for the initialize
 * @param config xml holding the configuration
 */
public void init(OperationResult or, XElement config) {
    this.config = config;

    if (config != null) {
        String timeZone = config.getAttribute("TimeZone", "UTC");

        if (StringUtil.isNotEmpty(timeZone))
            DateTimeZone.setDefault(DateTimeZone.forID(timeZone));

        String coreDate = config.getAttribute("CoreDate");

        if (StringUtil.isNotEmpty(coreDate)) {
            this.setAppClock(TimeUtil.parseDateTime(coreDate));
        }

        this.speed = StringUtil.parseInt(config.getAttribute("Speed"), 0);

        String obclass = config.getAttribute("TimerClass");

        if (StringUtil.isNotEmpty(obclass)) {
            try {
                Class<?> obc = this.getClass().getClassLoader().loadClass(obclass);
                this.obfus = (ISettingsObfuscator) obc.newInstance();
            } catch (Exception x) {
                Logger.error("Unable to load custom Settings Obfuscator class: " + obclass, "Code", "207");
            }
        }
    } else {
        DateTimeZone.setDefault(DateTimeZone.UTC);
    }

    if (this.obfus == null)
        this.obfus = new BasicSettingsObfuscator();

    this.obfus.init(config);
}

From source file:divconq.scheduler.limit.LimitHelper.java

License:Open Source License

public void init(XElement config) {
    if (config != null) {
        String zone = config.getAttribute("TimeZone");

        if (StringUtil.isNotEmpty(zone))
            this.zone = DateTimeZone.forID(zone);

        String from = config.getAttribute("ValidFrom");

        if (!StringUtil.isEmpty(from)) {
            this.validFrom = TimeUtil.parseDateTime(from);

            // TODO not sure about this - parsing of ISO string should not be circumvented?
            if (this.zone != null)
                this.validFrom = new DateTime(this.validFrom, this.zone);
        }// ww  w.  j  av a 2  s. c  om

        String to = config.getAttribute("ValidTo");

        if (!StringUtil.isEmpty(to)) {
            this.validTo = TimeUtil.parseDateTime(to);

            // TODO not sure about this - parsing of ISO string should not be circumvented?
            if (this.zone != null)
                this.validTo = new DateTime(this.validTo, this.zone);
        }

        // default to 10 years from now
        if (this.validTo == null)
            this.validTo = new DateTime().plusYears(10);

        for (XElement el : config.selectAll("Months")) {
            MonthWindow ww = new MonthWindow();
            ww.init(this, el);
            this.monthly.add(ww);
        }

        for (XElement el : config.selectAll("Weekdays")) {
            WeekdayWindow ww = new WeekdayWindow();
            ww.init(this, el);
            this.weekly.add(ww);
        }

        this.dailyWindow.init(config);

        String batch = config.getAttribute("LinkBatch");

        if (StringUtil.isNotEmpty(batch))
            this.parent = Hub.instance.getScheduler().getBatch(batch);
    } else {
        this.dailyWindow.init(null);
    }

    if (this.parent != null) {
        // if parent (batch) then we only use our daily overrides, 
        // not our month or weekly  
        this.dailyWindow.setParent(this.parent.getDailyWindow());
    }
}

From source file:divconq.util.TimeUtil.java

License:Open Source License

/**
 * try to lookup a timezone, but use default if it fails 
 * //from  ww  w  . j  a  v  a2s . c  om
 * @param zoneId id of the timezone desired
 * @return timezone to use
 */
static public DateTimeZone selectZone(String zoneId) {
    DateTimeZone zone = DateTimeZone.getDefault();

    try {
        if (StringUtil.isNotEmpty(zoneId))
            zone = DateTimeZone.forID(zoneId);
    } catch (Exception x) {
    }

    return zone;
}

From source file:dk.dma.epd.common.prototype.gui.voct.DatumLineInputPanel.java

License:Apache License

private void updateTimeZone() {

    // System.out.println("Updated timezone");

    String selectedTimeZone = (String) timeZoneDropdown.getSelectedItem();

    timeZone = DateTimeZone.forID(selectedTimeZone);

    // System.out.println("LKP time is: " + LKPDate);
    ///*w w  w.  j  a  va  2 s.c o  m*/
    // // Updated internal time
    // LKPDate = LKPDate.toDateTime(timeZone);
    // CSSDate = CSSDate.toDateTime(timeZone);
    //
    // System.out.println("LKP time is: " + LKPDate);

    // Update spinners

    // Date lkpTempDate = new Date();
    // lkpTempDate.setHours(LKPDate.getHourOfDay());
    // // lkpTempDate.setMinutes(LKPDate.getMinuteOfDay());
    //
    // System.out.println(LKPDate.getHourOfDay());
    // System.out.println(LKPDate.getMinuteOfDay());
    //
    // lkpSpinner.getModel().setValue(lkpTempDate);
    //
    // Date CSSTempDate = new Date();
    // CSSTempDate.setHours(CSSDate.getHourOfDay());
    // // CSSTempDate.setMinutes(CSSDate.getMinuteOfDay());
    //
    // commenceStartSpinner.getModel().setValue(lkpTempDate);

}

From source file:edu.berkeley.path.bots.core.Time.java

License:Apache License

/**
 * @return the equivalent time representation in Joda-time class.
 *///from w  w  w  .  ja v a2s.  c o  m
public DateTime toDateTime() {
    return new DateTime(getYear(), getMonth(), getDayOfMonth(), getHour(), getMinute(), getSecond(),
            getMillisecond(), DateTimeZone.forID("America/Los_Angeles"));
}

From source file:edu.internet2.middleware.grouperClientExt.com.thoughtworks.xstream.converters.extended.ISO8601GregorianCalendarConverter.java

License:Open Source License

public Object fromString(String str) {
    for (int i = 0; i < formattersUTC.length; i++) {
        DateTimeFormatter formatter = formattersUTC[i];
        try {//from   ww w  .  jav a2s.  c o  m
            DateTime dt = formatter.parseDateTime(str);
            Calendar calendar = dt.toCalendar(Locale.getDefault());
            calendar.setTimeZone(TimeZone.getDefault());
            return calendar;
        } catch (IllegalArgumentException e) {
            // try with next formatter
        }
    }
    String timeZoneID = TimeZone.getDefault().getID();
    for (int i = 0; i < formattersNoUTC.length; i++) {
        try {
            DateTimeFormatter formatter = formattersNoUTC[i].withZone(DateTimeZone.forID(timeZoneID));
            DateTime dt = formatter.parseDateTime(str);
            Calendar calendar = dt.toCalendar(Locale.getDefault());
            calendar.setTimeZone(TimeZone.getDefault());
            return calendar;
        } catch (IllegalArgumentException e) {
            // try with next formatter
        }
    }
    throw new ConversionException("Cannot parse date " + str);
}

From source file:edu.unc.lib.dl.util.DateTimeUtil.java

License:Apache License

/**
 * Parse a date in any ISO 8601 format. Default TZ is based on Locale.
 *
 * @param isoDate/*  w  w  w. j av a2  s  . com*/
 *           ISO8601 date/time string with or without TZ offset
 * @return a Joda DateTime object in UTC (call toString() to print)
 */
public static DateTime parseISO8601toUTC(String isoDate) {
    DateTime result = null;
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser().withOffsetParsed();
    // TODO what about preserving the precision of the original?
    DateTime isoDT = fmt.parseDateTime(isoDate);
    if (isoDT.year().get() > 9999) {
        // you parsed my month as part of the year!
        try {
            fmt = DateTimeFormat.forPattern("yyyyMMdd");
            fmt = fmt.withZone(DateTimeZone.forID("America/New_York"));
            isoDT = fmt.parseDateTime(isoDate);
        } catch (IllegalArgumentException e) {
            try {
                fmt = DateTimeFormat.forPattern("yyyyMM");
                fmt = fmt.withZone(DateTimeZone.forID("America/New_York"));
                isoDT = fmt.parseDateTime(isoDate);
            } catch (IllegalArgumentException e1) {
                try {
                    fmt = DateTimeFormat.forPattern("yyyy");
                    fmt = fmt.withZone(DateTimeZone.forID("America/New_York"));
                    isoDT = fmt.parseDateTime(isoDate);
                } catch (IllegalArgumentException ignored) {
                    // I guess we go with first parse?
                }
            }
        }
    }
    result = isoDT.withZoneRetainFields(DateTimeZone.forID("Etc/UTC"));
    return result;
}

From source file:eu.itesla_project.cases.EntsoeCaseRepository.java

License:Mozilla Public License

private static DateTime toCetDate(DateTime date) {
    DateTimeZone CET = DateTimeZone.forID("CET");
    if (!date.getZone().equals(CET)) {
        return date.toDateTime(CET);
    }/*from  w w w  . j  ava2  s .  c o  m*/
    return date;
}