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:org.jevis.commons.dataprocessing.ProcessOptions.java

License:Open Source License

/**
 * @return/*from   w w w.  j  av a  2  s  . c om*/
 */
public static DateTime getOffset(Process task) {
    DateTimeZone zone = DateTimeZone.forID("Europe/Berlin");
    //        Chronology coptic = CopticChronology.getInstance(zone);
    DateTime _offset = new DateTime(2007, 1, 1, 0, 0, 0, zone);
    return _offset;
}

From source file:org.jevis.commons.driver.JEVisImporter.java

License:Open Source License

@Override
public void initialize(JEVisObject dataSource) {
    try {/*from   w  w w .j  a  v a  2s  .co m*/
        _client = dataSource.getDataSource();
        JEVisClass dataSourceClass = _client.getJEVisClass(DataCollectorTypes.DataSource.NAME);
        JEVisType timezoneType = dataSourceClass.getType(DataCollectorTypes.DataSource.TIMEZONE);
        String timezone = DatabaseHelper.getObjectAsString(dataSource, timezoneType);
        _timezone = DateTimeZone.forID(timezone);
    } catch (JEVisException ex) {
        java.util.logging.Logger.getLogger(JEVisImporter.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    }
}

From source file:org.jlucrum.realtime.generators.TickGenerator.java

License:Open Source License

private boolean timeout() {
    DateTimeZone timeZone = null;/* w w w .  j  a v  a 2 s.  co  m*/
    DateTime time = null;
    long startTickerTime = 0;
    long endTickerTime = 0;
    boolean toContinue = false;

    timeZone = DateTimeZone.forID(config.timeZone);

    startTickerTime = config.start_hour * 60 + config.start_minute;
    endTickerTime = config.end_hour * 60 + config.end_minute;

    try {
        time = new DateTime(timeZone);

        System.out.printf("Timezone:%s and week:%d - %d", timeZone.toString(), time.getDayOfWeek(),
                DateTimeConstants.SATURDAY);
        if (DateTimeConstants.SATURDAY == time.getDayOfWeek()) {
            long toSleep = 24 * 60 - time.getMinuteOfDay() + 24 * 60;
            System.out.printf("TickGenerator sleeps until Monday, because it is Saturday\n");
            Thread.sleep(toSleep * 60 * 1000);
            toContinue = true;
        } else if (DateTimeConstants.SUNDAY == time.getDayOfWeek()) {
            long toSleep = 24 * 60 - time.getMinuteOfDay();
            System.out.printf("TickGenerator sleeps until Monday, because it is Sunday\n");
            Thread.sleep(toSleep * 60 * 1000);
            toContinue = true;
        }

        if (time.getMinuteOfDay() < startTickerTime) {
            long minutesToSleep = Math.abs(time.getMinuteOfDay() - startTickerTime);
            System.out.printf("Sleeping (%d) minutes ... Starting 1 at:%d:%d\n", minutesToSleep,
                    config.start_hour, config.start_minute);
            Thread.sleep(minutesToSleep * 60 * 1000);
            toContinue = true;

        } else if (time.getMinuteOfDay() > endTickerTime) {
            long minutesToSleep = 24 * 60 - time.getMinuteOfDay();
            minutesToSleep += startTickerTime;
            System.out.printf("Sleeping (%d) minutes ... Starting 2 at:%d:%d\n", minutesToSleep,
                    config.start_hour, config.start_minute);
            Thread.sleep(minutesToSleep * 60 * 1000);
            toContinue = true;
        }

    } catch (InterruptedException ex) {
        Logger.getLogger(TickGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }

    return toContinue;
}

From source file:org.joda.example.time.TimeZoneTable.java

License:Apache License

public static void main(String[] args) throws Exception {
    Set idSet = DateTimeZone.getAvailableIDs();
    ZoneData[] zones = new ZoneData[idSet.size()];

    {//from   w  w w  .j  a v  a 2  s  .c o  m
        Iterator it = idSet.iterator();
        int i = 0;
        while (it.hasNext()) {
            String id = (String) it.next();
            zones[i++] = new ZoneData(id, DateTimeZone.forID(id));
        }
        Arrays.sort(zones);
    }

    PrintStream out = System.out;

    out.println("<table>");

    out.println("<tr>" + "<th align=\"left\">Standard Offset</th>" + "<th align=\"left\">Canonical ID</th>"
            + "<th align=\"left\">Aliases</th>" + "</tr>");

    ZoneData canonical = null;
    List<ZoneData> aliases = new ArrayList<ZoneData>();

    for (int i = 0; i < zones.length; i++) {
        ZoneData zone = zones[i];

        if (!zone.isCanonical()) {
            aliases.add(zone);
            continue;
        }

        if (canonical != null) {
            printRow(out, canonical, aliases);
        }

        canonical = zone;
        aliases.clear();
    }

    if (canonical != null) {
        printRow(out, canonical, aliases);
    }

    out.println("</table>");
}

From source file:org.jruby.javasupport.ext.JavaTime.java

License:LGPL

/**
 * Convert a Java time zone to a JODA time zone.
 * @param id// w  w w  .j  av  a  2  s  .  co  m
 * @return a (joda) date-time zone from Java time's zone id
 */
private static DateTimeZone convertZone(final String id) {
    if ("Z".equals(id)) { // special Java time case JODA does not handle (for UTC)
        return DateTimeZone.UTC;
    }
    return DateTimeZone.forID(id);
}

From source file:org.jruby.RubyTime.java

License:LGPL

private static DateTimeZone parseTZString(Ruby runtime, String zone) {
    String upZone = zone.toUpperCase();

    Matcher tzMatcher = TZ_PATTERN.matcher(zone);
    if (tzMatcher.matches()) {
        String zoneName = tzMatcher.group(1);
        String sign = tzMatcher.group(2);
        String hours = tzMatcher.group(3);
        String minutes = tzMatcher.group(4);
        String seconds = tzMatcher.group(5);

        if (zoneName == null) {
            zoneName = "";
        }/*w w  w.java  2 s. c o  m*/

        // Sign is reversed in legacy TZ notation
        return getTimeZoneFromHHMM(runtime, zoneName, sign.equals("-"), hours, minutes, seconds);
    } else {
        if (LONG_TZNAME.containsKey(upZone)) {
            zone = LONG_TZNAME.get(upZone);
        } else if (upZone.equals("UTC") || upZone.equals("GMT")) {
            // MRI behavior: With TZ equal to "GMT" or "UTC", Time.now
            // is *NOT* considered as a proper GMT/UTC time:
            //   ENV['TZ']="GMT"; Time.now.gmt? #=> false
            //   ENV['TZ']="UTC"; Time.now.utc? #=> false
            // Hence, we need to adjust for that.
            zone = "Etc/" + upZone;
        }

        try {
            return DateTimeZone.forID(zone);
        } catch (IllegalArgumentException e) {
            runtime.getWarnings().warn("Unrecognized time zone: " + zone);
            return DateTimeZone.UTC;
        }
    }
}

From source file:org.jspringbot.keyword.date.DateHelper.java

License:Open Source License

public void setDateTimeZone(String timeZoneId) {
    LOG.keywordAppender().appendProperty("Time Zone ID", timeZoneId);

    currentTimeZone = DateTimeZone.forID(timeZoneId);
}

From source file:org.jugular.jodatime.factory.ChronologyFactory.java

License:Apache License

public Chronology create(Type chronologyType, String zoneId) {
    DateTimeZone zone;/* w  w w. j  a  va  2 s .  c o  m*/
    Chronology chronology;

    if (zoneId == null || "".equals(zoneId)) {
        zone = controller.getDateTimeZone();
    } else {
        zone = DateTimeZone.forID(zoneId);
    }

    switch (chronologyType) {
    case BUDDHIST:
        chronology = BuddhistChronology.getInstance(zone);
        break;
    case COPTIC:
        chronology = CopticChronology.getInstance(zone);
        break;
    case ETHIOPIC:
        chronology = EthiopicChronology.getInstance(zone);
        break;
    case GREGORIAN:
        chronology = GregorianChronology.getInstance(zone);
        break;
    case GREGORIAN_JULIAN:
        chronology = GJChronology.getInstance(zone);
        break;
    case ISLAMIC:
        chronology = IslamicChronology.getInstance(zone);
        break;
    case ISO:
        chronology = ISOChronology.getInstance(zone);
        break;
    case JULIAN:
        chronology = JulianChronology.getInstance(zone);
        break;
    default:
        throw new AssertionError("Calender system not supported");
    }

    return chronology;

}

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));
        }/*from w  w  w . j a  va 2s  . c  o 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.jaxrs.json.AccountJson.java

License:Apache License

public AccountData toAccountData() {
    return new AccountData() {
        @Override//from  w  w w. j  av  a  2s  .co m
        public DateTimeZone getTimeZone() {
            if (Strings.emptyToNull(timeZone) == null) {
                return null;
            } else {
                return DateTimeZone.forID(timeZone);
            }
        }

        @Override
        public String getStateOrProvince() {
            return state;
        }

        @Override
        public String getPostalCode() {
            return postalCode;
        }

        @Override
        public String getPhone() {
            return phone;
        }

        @Override
        public Boolean isMigrated() {
            return isMigrated;
        }

        @Override
        public Boolean isNotifiedForInvoices() {
            return isNotifiedForInvoices;
        }

        @Override
        public UUID getPaymentMethodId() {
            if (Strings.emptyToNull(paymentMethodId) == null) {
                return null;
            } else {
                return UUID.fromString(paymentMethodId);
            }
        }

        @Override
        public String getName() {
            return name;
        }

        @Override
        public String getLocale() {
            return locale;
        }

        @Override
        public Integer getFirstNameLength() {
            return firstNameLength;
        }

        @Override
        public String getExternalKey() {
            return externalKey;
        }

        @Override
        public String getEmail() {
            return email;
        }

        @Override
        public Currency getCurrency() {
            if (Strings.emptyToNull(currency) == null) {
                return null;
            } else {
                return Currency.valueOf(currency);
            }
        }

        @Override
        public String getCountry() {
            return country;
        }

        @Override
        public String getCompanyName() {
            return company;
        }

        @Override
        public String getCity() {
            return city;
        }

        @Override
        public Integer getBillCycleDayLocal() {
            return billCycleDayLocal;
        }

        @Override
        public String getAddress2() {
            return address2;
        }

        @Override
        public String getAddress1() {
            return address1;
        }
    };
}