Search in sources :

Example 1 with LocalDate

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;
}
Also used : EventDates(org.fossasia.openevent.data.extras.EventDates) ArrayList(java.util.ArrayList) LocalDate(org.threeten.bp.LocalDate) NonNull(android.support.annotation.NonNull)

Example 2 with LocalDate

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);
    }
}
Also used : ZonedDateTime(org.threeten.bp.ZonedDateTime) Duration(org.threeten.bp.Duration) LocalDate(org.threeten.bp.LocalDate)

Example 3 with LocalDate

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);
    }
}
Also used : ZonedDateTime(org.threeten.bp.ZonedDateTime) LocalDate(org.threeten.bp.LocalDate)

Example 4 with LocalDate

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];
}
Also used : LocalDate(org.threeten.bp.LocalDate)

Example 5 with LocalDate

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);
}
Also used : TemporalField(org.threeten.bp.temporal.TemporalField) LocalDate(org.threeten.bp.LocalDate)

Aggregations

LocalDate (org.threeten.bp.LocalDate)20 SuppressLint (android.annotation.SuppressLint)4 ZonedDateTime (org.threeten.bp.ZonedDateTime)4 Nullable (android.support.annotation.Nullable)2 View (android.view.View)2 HighlightWeekendsDecorator (com.prolificinteractive.materialcalendarview.sample.decorators.HighlightWeekendsDecorator)2 MySelectorDecorator (com.prolificinteractive.materialcalendarview.sample.decorators.MySelectorDecorator)2 MainActivity (kogvet.eye.MainActivity)2 Test (org.junit.Test)2 TemporalField (org.threeten.bp.temporal.TemporalField)2 DatePickerDialog (android.app.DatePickerDialog)1 TimePickerDialog (android.app.TimePickerDialog)1 NonNull (android.support.annotation.NonNull)1 TabLayout (android.support.design.widget.TabLayout)1 DatePicker (android.widget.DatePicker)1 TimePicker (android.widget.TimePicker)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1