Example usage for org.joda.time LocalDate toDateTimeAtStartOfDay

List of usage examples for org.joda.time LocalDate toDateTimeAtStartOfDay

Introduction

In this page you can find the example usage for org.joda.time LocalDate toDateTimeAtStartOfDay.

Prototype

public DateTime toDateTimeAtStartOfDay(DateTimeZone zone) 

Source Link

Document

Converts this LocalDate to a full datetime at the earliest valid time for the date using the specified time zone.

Usage

From source file:com.helger.datetime.holiday.CalendarUtil.java

License:Apache License

/**
 * Searches for the occurrences of a month/day in one chronology within one
 * gregorian year./*from w  ww. j ava  2 s  . co  m*/
 *
 * @param nTargetMonth
 *        Target month
 * @param nTargetDay
 *        Target day
 * @param nGregorianYear
 *        Gregorian year
 * @param aTargetChronoUTC
 *        Target chronology
 * @return the list of gregorian dates.
 */
@Nonnull
public static Set<LocalDate> getDatesFromChronologyWithinGregorianYear(final int nTargetMonth,
        final int nTargetDay, final int nGregorianYear, final Chronology aTargetChronoUTC) {
    final Set<LocalDate> aHolidays = new HashSet<LocalDate>();
    final LocalDate aFirstGregorianDate = PDTFactory.createLocalDate(nGregorianYear, DateTimeConstants.JANUARY,
            1);
    final LocalDate aLastGregorianDate = PDTFactory.createLocalDate(nGregorianYear, DateTimeConstants.DECEMBER,
            31);

    final LocalDate aFirstTargetDate = new LocalDate(
            aFirstGregorianDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()).getMillis(),
            aTargetChronoUTC);
    final LocalDate aLastTargetDate = new LocalDate(
            aLastGregorianDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()).getMillis(),
            aTargetChronoUTC);

    final Interval aInterv = new Interval(
            aFirstTargetDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()),
            aLastTargetDate.plusDays(1).toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()));

    for (int nTargetYear = aFirstTargetDate.getYear(); nTargetYear <= aLastTargetDate
            .getYear(); ++nTargetYear) {
        final LocalDate aLocalDate = new LocalDate(nTargetYear, nTargetMonth, nTargetDay, aTargetChronoUTC);
        if (aInterv.contains(aLocalDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()))) {
            aHolidays.add(convertToGregorianDate(aLocalDate));
        }
    }
    return aHolidays;
}

From source file:com.helger.datetime.holiday.CalendarUtil.java

License:Apache License

/**
 * Takes converts the provided date into a date within the gregorian
 * chronology. If it is already a gregorian date it will return it.
 *
 * @param aDate/*from   w  w  w  .j  av a2s  .com*/
 *        Date to convert
 * @return Converted date
 */
@Nonnull
public static LocalDate convertToGregorianDate(@Nonnull final LocalDate aDate) {
    return PDTFactory.createLocalDateFromMillis(
            aDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()).getMillis());
}

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

License:Apache License

@Nonnull
public static DateTime createDateTime(@Nonnull final LocalDate aLocalDate) {
    return aLocalDate.toDateTimeAtStartOfDay(getLocalDateTimeZone())
            .withChronology(PDTConfig.getDefaultChronology());
}

From source file:com.ning.billing.util.clock.ClockMock.java

License:Apache License

public synchronized void setDay(final LocalDate date) {
    setTime(date.toDateTimeAtStartOfDay(DateTimeZone.UTC));
}

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

License:Apache License

@Override
public void setValue(PreparedStatement st, int startIndex, LocalDate value) throws SQLException {
    st.setDate(startIndex, new Date(value.toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis()), utc());
}

From source file:com.sonicle.webtop.calendar.bol.ORecurrence.java

License:Open Source License

public void set(Recur recur, LocalDate recurStartDate, DateTime eventStartDate, DateTime eventEndDate,
        DateTimeZone eventTimezone) {//from www.  java2  s.  c o m
    DateTime newStart = (recurStartDate != null) ? recurStartDate.toDateTimeAtStartOfDay(eventTimezone)
            : eventStartDate;
    setStartDate(newStart);
    if (ICal4jUtils.recurHasCount(recur)) {
        DateTime untilDate = ICal4jUtils.calculateRecurrenceEnd(recur, newStart, eventTimezone);
        setUntilDate(untilDate.withTimeAtStartOfDay().plusDays(1));
    } else if (ICal4jUtils.recurHasUntilDate(recur)) {
        DateTime untilDate = ICal4jUtils.toJodaDateTime(recur.getUntil(), DateTimeZone.UTC)
                .withZone(eventTimezone);
        setUntilDate(untilDate.withTimeAtStartOfDay().plusDays(1));
    } else {
        setUntilDate(ICal4jUtils.ifiniteDate(eventTimezone));
    }
    setRule(recur.toString());
}

From source file:com.sonicle.webtop.calendar.bol.ORecurrence.java

License:Open Source License

public void updateUntilDate(LocalDate localDate, LocalTime localTime, DateTimeZone timezone) {
    Recur recur = getRecur();/*from  w  ww  .j  a  va  2  s.co  m*/
    ICal4jUtils.setRecurUntilDate(recur, localDate.toDateTime(localTime, timezone));
    setRule(recur.toString());
    setUntilDate(localDate.toDateTimeAtStartOfDay(timezone).plusDays(1));
}

From source file:com.springsource.greenhouse.events.JdbcEventRepository.java

License:Apache License

@Transactional
public List<EventSession> findSessionsOnDay(Long eventId, LocalDate day, Long attendeeId) {
    DateTimeZone eventTimeZone = DateTimeZone.forID(
            jdbcTemplate.queryForObject("select timezone from Event where id = ?", String.class, eventId));
    DateTime dayStart = day.toDateTimeAtStartOfDay(eventTimeZone);
    DateTime dayEnd = dayStart.plusDays(1);
    return jdbcTemplate.query(SELECT_SESSIONS_ON_DAY, eventSessionMapper.list(), attendeeId, eventId,
            dayStart.toDate(), dayEnd.toDate());
}

From source file:google.registry.xml.DateAdapter.java

License:Open Source License

/**
 * Converts {@link LocalDate} to UTC and returns it as an RFC3339 string. If {@code timestamp}
 * is {@code null} then an empty string is returned.
 *///from w w w  . j  ava2  s  . com
@Override
public String marshal(@Nullable LocalDate date) {
    if (date == null) {
        return "";
    }
    return MARSHAL_FORMAT.print(date.toDateTimeAtStartOfDay(UTC));
}

From source file:org.apache.isis.objectstore.sql.jdbc.JdbcConnector.java

License:Apache License

private void addPreparedValues(final PreparedStatement statement) throws SQLException {
    if (queryValues.size() > 0) {
        int i = 1;
        try {/*from w w w. j  ava2  s .com*/
            for (final Object value : queryValues) {
                if (value instanceof LocalDate) {
                    try {
                        statement.setObject(i, value, java.sql.Types.DATE);
                    } catch (final SQLException e) {
                        // TODO This daft catch is required my MySQL, which
                        // also requires the TimeZone offset to be
                        // "undone"
                        final LocalDate localDate = (LocalDate) value;
                        final int millisOffset = -DateTimeZone.getDefault().getOffset(null);
                        final java.util.Date javaDate = localDate
                                .toDateTimeAtStartOfDay(DateTimeZone.forOffsetMillis(millisOffset)).toDate();

                        statement.setObject(i, javaDate, java.sql.Types.DATE);
                    }
                } else if (value instanceof InputStream) {
                    statement.setBlob(i, (InputStream) value);
                } else {
                    statement.setObject(i, value);
                }
                i++;
            }
        } catch (final SQLException e) {
            LOG.error("Error adding prepared value " + i + " of type "
                    + queryValues.get(i - 1).getClass().getSimpleName(), e);
            throw e;
        }
    }
}