Example usage for org.joda.time LocalDateTime toDateTime

List of usage examples for org.joda.time LocalDateTime toDateTime

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime toDateTime.

Prototype

public DateTime toDateTime(DateTimeZone zone) 

Source Link

Document

Converts this object to a DateTime using the specified zone.

Usage

From source file:com.act.lcms.db.model.CuratedStandardMetlinIon.java

License:Open Source License

protected void bindInsertOrUpdateParameters(PreparedStatement stmt, String note, LocalDateTime createdAtDate,
        String bestMetlinIon, Integer standardIonResultId, String author) throws SQLException, IOException {
    stmt.setString(DB_FIELD.NOTE.getInsertUpdateOffset(), note);
    stmt.setTimestamp(DB_FIELD.CREATED_AT.getInsertUpdateOffset(),
            new Timestamp(createdAtDate.toDateTime(utcDateTimeZone).getMillis()));
    stmt.setString(DB_FIELD.BEST_METLIN_ION.getInsertUpdateOffset(), bestMetlinIon);
    stmt.setString(DB_FIELD.AUTHOR.getInsertUpdateOffset(), author);
    stmt.setInt(DB_FIELD.STANDARD_ION_RESULT_ID.getInsertUpdateOffset(), standardIonResultId);
}

From source file:com.alliander.osgp.domain.core.valueobjects.smartmetering.CosemDateTime.java

License:Open Source License

/**
 * Returns this {@link CosemDateTime} as {@link DateTime} if the date, time
 * and deviation are specified./*from   ww  w  .  j a v a 2  s.c  o  m*/
 *
 * @return this {@link CosemDateTime} as {@link DateTime}, or {@code null}
 *         if not {@link #isDateTimeSpecified()}.
 *
 * @see #isDateTimeSpecified()
 */
public DateTime asDateTime() {
    if (!this.isDateTimeSpecified()) {
        return null;
    }
    final LocalDateTime localDateTime = this.asLocalDateTime();
    final DateTimeZone zone = DateTimeZone.forOffsetMillis(-this.deviation * MILLISECONDS_PER_MINUTE);
    return localDateTime.toDateTime(zone);
}

From source file:com.battlelancer.seriesguide.util.TimeTools.java

License:Apache License

/**
 * Calculates the episode release date time as a millisecond instant. Adjusts for time zone
 * effects on release time, e.g. delays between time zones (e.g. in the United States) and DST.
 *
 * @param showTimeZone See {@link #getDateTimeZone(String)}.
 * @param showReleaseTime See {@link #getShowReleaseTime(int)}.
 * @return -1 if no conversion was possible. Otherwise, any other long value (may be negative!).
 *//*from  www . j  a va2s  .c o  m*/
public static long parseEpisodeReleaseDate(@NonNull DateTimeZone showTimeZone, @Nullable String releaseDate,
        @NonNull LocalTime showReleaseTime, @Nullable String showCountry, @NonNull String deviceTimeZone) {
    if (releaseDate == null || releaseDate.length() == 0) {
        return Constants.EPISODE_UNKNOWN_RELEASE;
    }

    // get date
    LocalDate localDate;
    try {
        localDate = TVDB_DATE_FORMATTER.parseLocalDate(releaseDate);
    } catch (IllegalArgumentException e) {
        // date string could not be parsed
        Timber.e(e, "TheTVDB date could not be parsed: " + releaseDate);
        return Constants.EPISODE_UNKNOWN_RELEASE;
    }

    // set time
    LocalDateTime localDateTime = localDate.toLocalDateTime(showReleaseTime);

    localDateTime = handleHourPastMidnight(showCountry, localDateTime);
    localDateTime = handleDstGap(showTimeZone, localDateTime);

    // finally get a valid datetime in the show time zone
    DateTime dateTime = localDateTime.toDateTime(showTimeZone);

    // handle time zone effects on release time for US shows (only if device is set to US zone)
    if (deviceTimeZone.startsWith(TIMEZONE_ID_PREFIX_AMERICA)) {
        dateTime = applyUnitedStatesCorrections(showCountry, deviceTimeZone, dateTime);
    }

    return dateTime.getMillis();
}

From source file:com.battlelancer.seriesguide.util.TimeTools.java

License:Apache License

/**
 * Calculates the current release date time. Adjusts for time zone effects on release time, e.g.
 * delays between time zones (e.g. in the United States) and DST. Adjusts for user-defined
 * offset.//from  ww  w.ja  va  2 s.  c o  m
 *
 * @param time See {@link #getShowReleaseTime(int)}.
 * @return The date is today or on the next day matching the given week day.
 */
public static Date getShowReleaseDateTime(@NonNull Context context, @NonNull LocalTime time, int weekDay,
        @Nullable String timeZone, @Nullable String country) {
    // determine show time zone (falls back to America/New_York)
    DateTimeZone showTimeZone = getDateTimeZone(timeZone);

    // create current date in show time zone, set local show release time
    LocalDateTime localDateTime = new LocalDate(showTimeZone).toLocalDateTime(time);

    // adjust day of week so datetime is today or within the next week
    // for daily shows (weekDay == 0) just use the current day
    if (weekDay >= 1 && weekDay <= 7) {
        // joda tries to preserve week
        // so if we want a week day earlier in the week, advance by 7 days first
        if (weekDay < localDateTime.getDayOfWeek()) {
            localDateTime = localDateTime.plusWeeks(1);
        }
        localDateTime = localDateTime.withDayOfWeek(weekDay);
    }

    localDateTime = handleHourPastMidnight(country, localDateTime);
    localDateTime = handleDstGap(showTimeZone, localDateTime);

    DateTime dateTime = localDateTime.toDateTime(showTimeZone);

    // handle time zone effects on release time for US shows (only if device is set to US zone)
    String localTimeZone = TimeZone.getDefault().getID();
    if (localTimeZone.startsWith(TIMEZONE_ID_PREFIX_AMERICA)) {
        dateTime = applyUnitedStatesCorrections(country, localTimeZone, dateTime);
    }

    dateTime = applyUserOffset(context, dateTime);

    return dateTime.toDate();
}

From source file:com.coderoad.automation.common.util.DateUtil.java

License:Open Source License

/**
 * Convert timezone./*from w w w .ja v a  2s .  co m*/
 * 
 * @param date the date
 * @param srcTimeZone the src time zone
 * @param destTimeZone the dest time zone
 * @return the date
 */
public static Date convertTimezone(LocalDateTime date, String srcTimeZone, String destTimeZone) {

    DateTime srcDateTime = date.toDateTime(DateTimeZone.forID(srcTimeZone));
    DateTime dstDateTime = srcDateTime.withZone(DateTimeZone.forID(destTimeZone));
    return dstDateTime.toLocalDateTime().toDateTime().toDate();
}

From source file:com.dalendev.meteotndata.service.TimeService.java

License:Open Source License

public static Long getMillis(final LocalDateTime date) {
    return date.toDateTime(DateTimeZone.forID("Europe/Rome")).getMillis();
}

From source file:com.effektif.workflow.impl.json.types.LocalDateTimeStreamMapper.java

License:Apache License

@Override
public void write(LocalDateTime objectValue, JsonWriter jsonWriter) {
    jsonWriter.writeString(PRINTER.print(objectValue.toDateTime(DateTimeZone.UTC)));
}

From source file:com.helger.datetime.PDTFactory.java

License:Apache License

@Nonnull
public static DateTime createDateTime(@Nonnull final LocalDateTime aLocalDateTime) {
    return aLocalDateTime.toDateTime(getLocalDateTimeZone()).withChronology(PDTConfig.getDefaultChronology());
}

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

License:Apache License

@Override
public void setValue(PreparedStatement st, int index, LocalDateTime value) throws SQLException {
    DateTime dt = value.toDateTime(DateTimeZone.UTC);
    st.setTimestamp(index, new Timestamp(dt.getMillis()), utc());
}

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 w  ww  . j a v  a  2 s. com
    }

    logger.setMethodName(method);
    return bResult;
}