List of usage examples for org.joda.time DateTime withTimeAtStartOfDay
public DateTime withTimeAtStartOfDay()
From source file:org.springframework.xd.analytics.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
private long[] getHourCountsForDay(String name, DateTime day) { AggregateKeyGenerator akg = new AggregateKeyGenerator(getPrefix(), name, day.withTimeAtStartOfDay()); return convertToArray(getEntries(akg.getDayKey()), 24, false); }
From source file:rapture.kernel.DecisionApiImpl.java
License:Open Source License
private String getStartOfDayEpoch(Long startInstant) { DateTime dateTime = new DateTime(startInstant, DateTimeZone.UTC); return "" + dateTime.withTimeAtStartOfDay().toInstant().getMillis() / 1000; }
From source file:ru.touchin.templates.calendar.CalendarAdapter.java
License:Apache License
/** * Set selected dates range in calendar. Call this method before attaching this adapter to {@link CalendarRecyclerView}. * * @param startSelectionDate First date that should be selected; * @param endSelectionDate Last date that should be selected (inclusive). *//*w w w. j a v a 2s . c o m*/ public void setSelectedRange(@Nullable final DateTime startSelectionDate, @Nullable final DateTime endSelectionDate) { if (startSelectionDate != null) { startSelectionPosition = CalendarUtils.findPositionByDate(calendarItems, startSelectionDate.withTimeAtStartOfDay().getMillis()); } if (endSelectionDate != null) { endSelectionPosition = CalendarUtils.findPositionByDate(calendarItems, endSelectionDate.withTimeAtStartOfDay().getMillis()); } notifySelectedDaysChanged(); }
From source file:ru.touchin.templates.calendar.CalendarUtils.java
License:Apache License
/** * Create list of {@link CalendarItem} according to start and end Dates. * * @param startDate Start date of the range; * @param endDate End date of the range; * @return List of CalendarItems that could be one of these: {@link CalendarHeaderItem}, {@link CalendarDayItem} or {@link CalendarEmptyItem}. *//* w w w .ja va 2 s . com*/ @NonNull @SuppressWarnings("checkstyle:MethodLength") public static List<CalendarItem> fillRanges(@NonNull final DateTime startDate, @NonNull final DateTime endDate) { final DateTime cleanStartDate = startDate.withTimeAtStartOfDay(); final DateTime cleanEndDate = endDate.plusDays(1).withTimeAtStartOfDay(); DateTime tempTime = cleanStartDate; final List<CalendarItem> calendarItems = fillCalendarTillCurrentDate(cleanStartDate, tempTime); tempTime = tempTime.plusDays(Days.ONE.getDays()); final int totalDaysCount = Days.daysBetween(tempTime, cleanEndDate).getDays(); int shift = calendarItems.get(calendarItems.size() - 1).getEndRange(); int firstDate = tempTime.getDayOfMonth() - 1; int daysEnded = 1; while (true) { final int daysInCurrentMonth = tempTime.dayOfMonth().getMaximumValue(); final long firstRangeDate = tempTime.getMillis(); if ((daysEnded + (daysInCurrentMonth - firstDate)) <= totalDaysCount) { tempTime = tempTime.plusMonths(1).withDayOfMonth(1); calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded, shift + daysEnded + (daysInCurrentMonth - firstDate) - 1, ComparingToToday.AFTER_TODAY)); daysEnded += daysInCurrentMonth - firstDate; if (daysEnded == totalDaysCount) { break; } firstDate = 0; final int firstDayInWeek = tempTime.getDayOfWeek() - 1; if (firstDayInWeek != 0) { calendarItems.add(new CalendarEmptyItem(shift + daysEnded, shift + daysEnded + (DAYS_IN_WEEK - firstDayInWeek - 1))); shift += (DAYS_IN_WEEK - firstDayInWeek); } calendarItems.add(new CalendarHeaderItem(tempTime.getYear(), tempTime.getMonthOfYear() - 1, shift + daysEnded, shift + daysEnded)); shift += 1; if (firstDayInWeek != 0) { calendarItems .add(new CalendarEmptyItem(shift + daysEnded, shift + daysEnded + firstDayInWeek - 1)); shift += firstDayInWeek; } } else { calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded, shift + totalDaysCount, ComparingToToday.AFTER_TODAY)); break; } } return calendarItems; }
From source file:syncthing.android.service.SyncthingUtils.java
License:Open Source License
public static Interval getIntervalForRange(DateTime now, long start, long end) { DateTime daybreak = now.withTimeAtStartOfDay(); Interval interval;// ww w.java 2s .c om if (start < end) { //same day interval = new Interval(daybreak.plus(start), daybreak.plus(end)); } else /*start >|== end*/ { if (now.isAfter(daybreak.plus(start))) { //rolls next day interval = new Interval(daybreak.plus(start), daybreak.plusDays(1).plus(end)); } else { //rolls previous day interval = new Interval(daybreak.minusDays(1).plus(start), daybreak.plus(end)); } } return interval; }