List of usage examples for org.joda.time LocalDateTime withDayOfWeek
public LocalDateTime withDayOfWeek(int dayOfWeek)
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 . java 2s. 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.effektif.workflow.api.model.NextRelativeTime.java
License:Apache License
@Override public LocalDateTime resolve(LocalDateTime base) { LocalDateTime time = null;// w w w . j ava2 s.c om if (HOUR_OF_DAY.equals(indexUnit)) { time = base.withTime(index, 0, 0, 0); if (!time.isAfter(base)) { return time.plusDays(1); } } else if (DAY_OF_WEEK.equals(indexUnit)) { time = base.withDayOfWeek(index).withTime(0, 0, 0, 0); if (!time.isAfter(base)) { time = time.plusWeeks(1); } } else if (DAY_OF_MONTH.equals(indexUnit)) { time = base.withDayOfMonth(index).withTime(0, 0, 0, 0); if (!time.isAfter(base)) { time = time.plusMonths(1); } } if (atHour != null) { time = time.withTime(atHour, atMinute != null ? atMinute : 0, 0, 0); } return time; }
From source file:com.tasomaniac.muzei.tvshows.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 w w w. j a va2s .co 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); } return dateTime.toDate(); }