Example usage for org.joda.time DateTimeZone forOffsetHours

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

Introduction

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

Prototype

public static DateTimeZone forOffsetHours(int hoursOffset) throws IllegalArgumentException 

Source Link

Document

Gets a time zone instance for the specified offset to UTC in hours.

Usage

From source file:com.flowpowered.jsoncache.connector.DefaultURLConnector.java

License:MIT License

@Override
public InputStream openURL(URL url, final File temp, final File writeTo) throws IOException {
    URLConnection conn = url.openConnection();

    HttpURLConnection httpconn = null;
    if (url.getProtocol().equalsIgnoreCase("http")) {
        httpconn = (HttpURLConnection) conn;
    }//from   w w  w  .  j ava2  s  .c  o m

    // Check modified date.
    DateTime modified = null;
    if (writeTo.exists()) {
        modified = new DateTime(writeTo.lastModified());
        conn.setRequestProperty("If-Modified-Since", modified.toString(HTTP_DATE_TIME));
    }

    setHeaders(conn);

    // Set the user agent for the request.
    System.setProperty("http.agent",
            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19");
    conn.setRequestProperty("User-Agent",
            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19");

    conn.connect();

    onConnected(conn);

    // Modified date handling. If server copy isn't newer than the cache, don't download again and use cached copy instead.

    // This checks if the server has replied with 304 NOT MODIFIED.
    if (httpconn != null && httpconn.getResponseCode() == 304) { // Not modified.
        try {
            conn.getInputStream().close();
        } catch (IOException ignore) {
        }
        try {
            conn.getOutputStream().close();
        } catch (IOException ignore) {
        }
        return new FileInputStream(writeTo);
    }

    if (modified != null) {
        // This checks for the last modified date.
        long i = conn.getHeaderFieldDate("Last-Modified", -1);
        DateTime serverModified = new DateTime(i, DateTimeZone.forOffsetHours(0));
        if (serverModified.isBefore(modified) || serverModified.isEqual(modified)) { // File hasn't changed.
            try {
                conn.getInputStream().close();
            } catch (IOException ignore) {
            }
            try {
                conn.getOutputStream().close();
            } catch (IOException ignore) {
            }
            return new FileInputStream(writeTo);
        }
    }

    return download(conn, temp, writeTo);
}

From source file:com.google.sampling.experiential.model.Event.java

License:Open Source License

public static DateTime getTimeZoneAdjustedDate(Date time, String defaultTimeZone, String timeZone) {
    if (time == null) {
        return null;
    }// w  w w.  ja va2  s  . c o  m

    if (Strings.isNullOrEmpty(timeZone)) {
        if (Strings.isNullOrEmpty(defaultTimeZone)) {
            return new DateTime(time);
        } else {
            DateTimeZone timezoneForOffsetHours = DateTimeZone.forID(defaultTimeZone);
            if (timezoneForOffsetHours == null) {
                return new DateTime(time);
            }
            return new DateTime(time).withZone(timezoneForOffsetHours);
        }
    } else {
        String hours = timeZone.substring(0, 3);
        if (hours.startsWith("+")) {
            hours = hours.substring(1);
        }

        int parseInt;
        try {
            parseInt = Integer.parseInt(hours);
        } catch (NumberFormatException e) {
            EventServlet.log.info("Timezone hours are not an integer this event.");
            return new DateTime(time);
        }
        DateTimeZone timezoneForOffsetHours = DateTimeZone.forOffsetHours(parseInt);
        if (timezoneForOffsetHours == null) {
            return new DateTime(time);
        }
        return new DateTime(time).withZone(timezoneForOffsetHours);
    }
}

From source file:com.marklogic.samplestack.dbclient.MarkLogicQnAService.java

License:Apache License

/**
 * This method simply runs a search against MarkLogic so that its
 * cache warms up while the Java tier is also warming up.
 * @throws Exception//from w  w w  .  j  a v a  2 s . com
 */
@PostConstruct
public void warmupSearchCache() throws Exception {
    logger.info("Warming up MarkLogic Search Caches");
    ObjectNode query = (ObjectNode) mapper.readValue("{\"search\":{\"qtext\":\"\"}}", JsonNode.class);
    try {
        this.rawSearch(SAMPLESTACK_CONTRIBUTOR, query, 1, DateTimeZone.forOffsetHours(1));
    } catch (Exception e) {
        logger.error("Cannot initialize application.  Something is probably wrong with the MarkLogic server.",
                e);
    }
}

From source file:com.thoughtworks.go.server.util.CCDateFormatter.java

License:Apache License

public static DateTime iso8601(String datetime) {
    try {/*  w ww . j a v a 2  s.  c om*/
        //TODO: ChrisS: This seems wierd - surely JodaTime has already got a way to do this?
        return new DateTime(DateUtils.parseISO8601(datetime).getTime(), DateTimeZone.forOffsetHours(0));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.xpn.xwiki.plugin.jodatime.JodaTimePlugin.java

License:Open Source License

/**
 * @see org.joda.time.DateTimeZone#forOffsetHours(int)
 */
public DateTimeZone getTimezone(int offsetHours) {
    return DateTimeZone.forOffsetHours(offsetHours);
}

From source file:io.typebrook.fiveminsmore.Cluster.CustomMarker.java

License:Apache License

public void setDateTime(DateTime time) {
    mTime = time;/*from w  w  w  .j a  v a2s  .  co m*/
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MMMM-dd a HH:mm")
            .withZone(DateTimeZone.forOffsetHours(8));
    mSnippet = ": " + time.toString(fmt) + "\n" + mSnippet;
}

From source file:nodequeryclient.Account.java

public DateTimeZone getTimeInzone() {
    DateTimeZone zoneUTC = DateTimeZone.forOffsetHours(getTimezone());
    return zoneUTC;
}

From source file:nz.al4.airclock.MainActivity.java

License:Open Source License

private void getPreferences() {
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Must set time zones before the hour and minute
    String originTimeZone = prefs.getString("originTimeZone", null);
    if (originTimeZone != null) {
        DateTimeZone zone = DateTimeZone.forOffsetHours(Integer.parseInt(originTimeZone));
        this.mOriginDate.setZone(zone);
    }/*from  w  w  w  .j a v a2  s .co m*/

    String originDate = prefs.getString("takeOffDate", null);
    if (originDate != null) {
        this.mOriginDate.setYear(DatePreference.getYear(originDate));
        this.mOriginDate.setMonthOfYear(DatePreference.getMonth(originDate));
        this.mOriginDate.setDayOfMonth(DatePreference.getDay(originDate));
    } else {
        Log.i("prefs", "takeOffDate is null");
    }

    String originTime = prefs.getString("takeOffTime", null);
    if (originTime != null) {
        this.mOriginDate.setHourOfDay(TimePreference.getHour(originTime));
        this.mOriginDate.setMinuteOfHour(TimePreference.getMinute(originTime));
    } else {
        Log.i("prefs", "takeOffTime is null");
    }

    String destTimeZone = prefs.getString("destTimeZone", null);
    if (destTimeZone != null) {
        DateTimeZone zone = DateTimeZone.forOffsetHours(Integer.parseInt(destTimeZone));
        this.mDestDate.setZone(zone);
    }

    String destDate = prefs.getString("landingDate", null);
    if (destDate != null) {
        this.mDestDate.setYear(DatePreference.getYear(destDate));
        this.mDestDate.setMonthOfYear(DatePreference.getMonth(destDate));
        this.mDestDate.setDayOfMonth(DatePreference.getDay(destDate));
    } else {
        Log.i("prefs", "landingDate is null");
    }

    String destTime = prefs.getString("landingTime", null);
    if (destTime != null) {
        this.mDestDate.setHourOfDay(TimePreference.getHour(destTime));
        this.mDestDate.setMinuteOfHour(TimePreference.getMinute(destTime));
    } else {
        Log.i("prefs", "landingTime is null");
    }

    mDirection = prefs.getString("calc_direction", "auto");
    Log.e("mainfoo", mDirection);

    setTextViews();
    mClockFragment.direction = mDirection;
    mClockFragment.originTime = mOriginDate.toDateTime();
    mClockFragment.destTime = mDestDate.toDateTime();
}

From source file:org.apache.tamaya.jodatime.DateTimeZoneConverter.java

License:Apache License

@Override
public DateTimeZone convert(String value) {
    String trimmed = requireNonNull(value).trim();

    DateTimeZone result = null;/*from w  ww.ja  v  a2 s.c  o  m*/

    try {
        if (isSingleIntegerValue(trimmed)) {
            int offset = Integer.parseInt(trimmed);
            result = DateTimeZone.forOffsetHours(offset);
        } else { // Let us assume a string id
            result = DateTimeZone.forID(trimmed);
        }

    } catch (RuntimeException e) {
        result = null; // Give the next converter a change. Read the JavaDoc of convert
    }

    return result;
}

From source file:org.biokoframework.system.repository.sql.translator.annotation.impl.HSQLDBDateTimeTranslator.java

License:Open Source License

@Override
public String convertFromDBValue(String fieldName, ResultSet resultset, Field fieldAnnotation)
        throws SQLException {
    String sqlFieldValue = resultset.getString(fieldName);
    if (sqlFieldValue == null) {
        return null;
    } else {/*w w w . ja  va2 s.  com*/
        DateTime timestamp = DateTimeFormat.forPattern(MYSQL_TIMESTAMP).parseDateTime(sqlFieldValue);
        timestamp = timestamp.withZone(DateTimeZone.forOffsetHours(1));
        return timestamp.toString(ISO_TIMESTAMP);
    }
}