Example usage for org.joda.time DateTimeZone UTC

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

Introduction

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

Prototype

DateTimeZone UTC

To view the source code for org.joda.time DateTimeZone UTC.

Click Source Link

Document

The time zone for Universal Coordinated Time

Usage

From source file:com.querydsl.sql.types.LocalTimeType.java

License:Apache License

@Override
public LocalTime getValue(ResultSet rs, int startIndex) throws SQLException {
    Time time = rs.getTime(startIndex, utc());
    return time != null ? new LocalTime(time.getTime(), DateTimeZone.UTC) : null;
}

From source file:com.restservice.database.Transactor.java

License:Open Source License

/**
 * Adds a search term to the database, to be processed by the daemon.
 * /*from  ww w.  j a  v a2 s  .  c  o m*/
 * @param term
 *            String that should be looked for
 * @throws SQLException
 *             thrown if a SQL-Error occurs
 */
public void saveSearchTerm(String term) throws SQLException {
    try {

        connect = DriverManager.getConnection(dbUrl);

        readStatement = connect.prepareStatement(readQuery);
        readStatement.execute();

        prepStatement = connect.prepareStatement(
                "insert into search_terms (term, active, current_start, old_start, interval_length, time_last_fetched, last_fetched_tweet_id, last_fetched_tweet_count, when_created)"
                        + "values (?, ?, ?, ?, ?, ?, ?, ?, ?);");

        DateTime now = new DateTime(DateTimeZone.UTC);

        String sNow = now.toString();
        sNow = sNow.replace("T", " ");
        if (sNow.indexOf(".") > -1)
            sNow = sNow.substring(0, sNow.indexOf("."));

        //System.out.println("SQL UTC time: " + Timestamp.valueOf(sNow).toString());

        prepStatement.setString(1, term);
        prepStatement.setBoolean(2, true);
        prepStatement.setTimestamp(3, Timestamp.valueOf(sNow));
        prepStatement.setNull(4, java.sql.Types.NULL);
        prepStatement.setTime(5, Time.valueOf("00:15:00"));
        prepStatement.setNull(6, java.sql.Types.NULL);
        prepStatement.setNull(7, java.sql.Types.NULL);
        prepStatement.setNull(8, java.sql.Types.NULL);
        prepStatement.setTimestamp(9, Timestamp.valueOf(sNow));

        prepStatement.execute();
    } catch (SQLException e) {
        throw e;
    } finally {
        close();
    }
}

From source file:com.rincaro.simplejpa.util.AmazonSimpleDBUtil.java

License:Apache License

/**
 * Encodes date value into string format that can be compared lexicographically
 *
 * @param date date value to be encoded/*from w  ww.  jav a 2 s  . c  o  m*/
 * @return string representation of the date value
 */
public static String encodeDateTime(DateTime date) {
    return date.toDateTime(DateTimeZone.UTC).toString();
}

From source file:com.rincaro.simplejpa.util.AmazonSimpleDBUtil.java

License:Apache License

/**
 * Decodes date value from the string representation created using encodeDate(..) function.
 *
 * @param   value   string representation of the date value
 * @return         original date value/*w  w  w .jav a2s .c  o m*/
 */
public static DateTime decodeDateTime(String value) {
    return new DateTime(value, DateTimeZone.UTC);
}

From source file:com.ryan.ryanreader.common.RRTime.java

License:Open Source License

public static long utcCurrentTimeMillis() {
    return DateTime.now(DateTimeZone.UTC).getMillis();
}

From source file:com.salesmanBuddy.dao.JDBCSalesmanBuddyDAO.java

License:Open Source License

private List<SBEmail> generateIndividualSalesmanSummaryEmailsForDealershipIdReportType(Integer dealershipId,
        Integer reportType) {//  w ww.ja  v  a  2  s .  co  m
    DateTime to = new DateTime(DateTimeZone.UTC);
    DateTime from = null;
    switch (reportType) {
    case DAILY_SALESMAN_SUMMARY_EMAIL_TYPE:
        from = to.minusDays(1).minusMinutes(10);
        break;

    case WEEKLY_SALESMAN_SUMMARY_EMAIL_TYPE:
        from = to.minusWeeks(1).minusMinutes(10);
        break;

    case MONTHLY_SALESMAN_SUMMARY_EMAIL_TYPE:
        from = to.minusMonths(1).minusMinutes(10);
        break;

    default:
        throw new RuntimeException(
                "report type invalid for generateIndividualSalesmanSummaryEmailsForDealershipIdReportType");
    }

    List<UserTree> userTrees = this.getUserTreeForDealershipIdType(dealershipId, reportType);
    List<SBEmail> emails = new ArrayList<>();
    for (UserTree ut : userTrees) {

        try {
            String subject = "Report about " + this.getUsersName(ut.getUserId()).getName()
                    + " from Salesman Buddy";
            String body = this.individualSalesmanSummaryReport(this.getUserByGoogleId(ut.getUserId()).getId(),
                    from, to);
            SBEmail email = SBEmail.newPlainTextEmail(REPORTS_EMAIL, null, subject, body, true);
            email.replaceTo(this.getEmailForGoogleId(ut.getSupervisorId()));
            emails.add(email);
        } catch (UserNameException e) {
            e.printStackTrace();
            JDBCSalesmanBuddyDAO.sendErrorToMe(new StringBuilder().append(
                    "Error in generateIndividualSalesmanSummaryEmailsForDealershipIdReportType for getting user's name for userTree: ")
                    .append(ut.toString()).append(", error: ").append(e.getLocalizedMessage()).toString());
        }
    }
    return emails;
}

From source file:com.sandata.lab.common.utils.date.DateUtil.java

License:Open Source License

public static Date convertUTCToTargetTimeZone(Date date, String timezoneName) {
    return new LocalDateTime(date.getTime()).toDateTime(DateTimeZone.UTC)
            .toDateTime(DateTimeZone.forID(timezoneName)).toLocalDateTime().toDate();
}

From source file:com.sandata.lab.common.utils.date.DateUtil.java

License:Open Source License

public static Date convertFromTimeZoneToUTC(Date date, String timezoneName) {
    return new LocalDateTime(date.getTime()).toDateTime(DateTimeZone.forID(timezoneName))
            .toDateTime(DateTimeZone.UTC).toLocalDateTime().toDate();
}

From source file:com.sandata.lab.wcf.lookup.impl.RestLookupTablesService.java

License:Open Source License

private boolean lastCacheUpdateTimeExpired(final SandataLogger logger) {

    boolean bResult = false;
    String method = logger.getMethodName();
    logger.setMethodName("lastCacheUpdateTimeExpired");

    LocalDateTime now = LocalDateTime.now();

    Duration duration = new Duration(lastCacheUpdateTime.toDateTime(DateTimeZone.UTC),
            now.toDateTime(DateTimeZone.UTC));
    long seconds = duration.getStandardSeconds();
    long minutes = duration.getStandardMinutes();

    logger.info(String.format("Last Cache Update: %s", TimeFormat.SecondsToString(seconds)));

    if (minutes >= updateCacheInterval) {
        bResult = true;//from www  . ja  va  2 s .co  m
    }

    logger.setMethodName(method);
    return bResult;
}

From source file:com.sappenin.objectify.translate.UTCReadableInstantDateTranslatorFactory.java

License:Apache License

@Override
protected ValueTranslator<ReadableInstant, Date> createValueTranslator(final TypeKey<ReadableInstant> tk,
        final CreateContext ctx, final Path path) {

    final Class<?> clazz = GenericTypeReflector.erase(tk.getTypeAsClass());

    return new ValueTranslator<ReadableInstant, Date>(Date.class) {
        @Override//from  w ww  .j  av  a2 s  .co m
        protected ReadableInstant loadValue(Date value, LoadContext ctx, Path path) throws SkipException {
            // All the Joda instants have a constructor that will accept a Date
            final MethodHandle ctor = TypeUtils.getConstructor(clazz, Object.class);
            ReadableInstant instance = TypeUtils.invoke(ctor, value);

            // If possible, ensure that the return ReadableInstant is in UTC
            if (AbstractInstant.class.isAssignableFrom(clazz)) {
                instance = ((AbstractInstant) instance).toDateTime(DateTimeZone.UTC);
            }

            return instance;
        }

        @Override
        protected Date saveValue(ReadableInstant value, boolean index, SaveContext ctx, Path path)
                throws SkipException {

            return value.toInstant().toDate();
        }
    };
}