use of org.threeten.bp.LocalDate in project open-event-android by fossasia.
the class DateConverter method getDaysInBetween.
@NonNull
public static List<EventDates> getDaysInBetween(@NonNull String startDate, @NonNull String endDate) throws DateTimeParseException {
List<EventDates> dates = new ArrayList<>();
LocalDate start = getDate(startDate).toLocalDate();
LocalDate end = getDate(endDate).toLocalDate();
// add start date
dates.add(new EventDates(DateTimeFormatter.ISO_LOCAL_DATE.format(start)));
// add dates between start date and end date
for (int i = 1; start.plusDays(i).isBefore(end); i++) {
dates.add(new EventDates(DateTimeFormatter.ISO_LOCAL_DATE.format(start.plusDays(i))));
}
// add end date
dates.add(new EventDates(DateTimeFormatter.ISO_LOCAL_DATE.format(end)));
return dates;
}
use of org.threeten.bp.LocalDate in project Douya by DreaminginCodeZH.
the class TimeUtils method formatDateTime.
public static String formatDateTime(ZonedDateTime dateTime, Context context) {
ZonedDateTime now = ZonedDateTime.now().withZoneSameInstant(dateTime.getZone());
LocalDate date = dateTime.toLocalDate();
LocalDate nowDate = now.toLocalDate();
if (date.equals(nowDate)) {
Duration duration = Duration.between(dateTime, now);
if (duration.compareTo(Duration.ZERO) > 0) {
if (duration.compareTo(JUST_NOW_DURATION) < 0) {
return context.getString(R.string.just_now);
} else if (duration.compareTo(MINUTE_PATTERN_DURATION) < 0) {
return context.getString(R.string.minute_format, Math.round((float) duration.getSeconds() / SECONDS_PER_MINUTE));
} else if (duration.compareTo(HOUR_PATTERN_DURATION) < 0) {
return context.getString(R.string.hour_format, Math.round((float) duration.getSeconds() / SECONDS_PER_HOUR));
}
}
return DateTimeFormatter.ofPattern(context.getString(R.string.today_hour_minute_pattern)).format(dateTime);
}
if (date.plusDays(1).equals(nowDate)) {
return DateTimeFormatter.ofPattern(context.getString(R.string.yesterday_hour_minute_pattern)).format(dateTime);
} else if (date.getYear() == nowDate.getYear()) {
return DateTimeFormatter.ofPattern(context.getString(R.string.month_day_hour_minute_pattern)).format(dateTime);
} else {
return DateTimeFormatter.ofPattern(context.getString(R.string.date_hour_minute_pattern)).format(dateTime);
}
}
use of org.threeten.bp.LocalDate in project Douya by DreaminginCodeZH.
the class TimeUtils method formatDate.
public static String formatDate(LocalDate date, ZoneId zone, Context context) {
ZonedDateTime now = ZonedDateTime.now().withZoneSameInstant(zone);
LocalDate nowDate = now.toLocalDate();
if (date.equals(nowDate)) {
return context.getString(R.string.today);
}
if (date.plusDays(1).equals(nowDate)) {
return context.getString(R.string.yesterday);
} else if (date.getYear() == nowDate.getYear()) {
return DateTimeFormatter.ofPattern(context.getString(R.string.month_day_pattern)).format(date);
} else {
return DateTimeFormatter.ofPattern(context.getString(R.string.date_pattern)).format(date);
}
}
use of org.threeten.bp.LocalDate in project Douya by DreaminginCodeZH.
the class CalendarDay method getDayOfWeekText.
public String getDayOfWeekText(Context context) {
String[] dayOfWeekNames = context.getResources().getStringArray(R.array.calendar_day_of_week_names);
LocalDate date = getDate();
return dayOfWeekNames[date.getDayOfWeek().getValue() - 1];
}
use of org.threeten.bp.LocalDate in project material-calendarview by prolificinteractive.
the class CalendarPagerView method resetAndGetWorkingCalendar.
protected LocalDate resetAndGetWorkingCalendar() {
final TemporalField firstDayOfWeek = WeekFields.of(this.firstDayOfWeek, 1).dayOfWeek();
final LocalDate temp = getFirstViewDay().getDate().with(firstDayOfWeek, 1);
int dow = temp.getDayOfWeek().getValue();
int delta = getFirstDayOfWeek().getValue() - dow;
// If the delta is positive, we want to remove a week
boolean removeRow = showOtherMonths(showOtherDates) ? delta >= 0 : delta > 0;
if (removeRow) {
delta -= DEFAULT_DAYS_IN_WEEK;
}
return temp.plusDays(delta);
}
Aggregations