Java Code Examples for com.wdullaer.materialdatetimepicker.Utils#trimToMidnight()

The following examples show how to use com.wdullaer.materialdatetimepicker.Utils#trimToMidnight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultDateRangeLimiterPropertyTest.java    From MaterialDateTimePicker with Apache License 2.0 6 votes vote down vote up
@Property
public void setToNearestShouldNeverBeAboveMaxDate(
        @InRange(min = "01/01/1800", max = "12/31/2099", format = "MM/dd/yyyy") Date date,
        @InRange(min = "01/01/1800", max = "12/31/2099", format = "MM/dd/yyyy") Date maxDate
) {
    DefaultDateRangeLimiter limiter = new DefaultDateRangeLimiter();

    Calendar day = Calendar.getInstance();
    day.setTime(date);

    Calendar minDay = Calendar.getInstance();
    minDay.set(Calendar.YEAR, 1800);
    minDay.set(Calendar.MONTH, Calendar.JANUARY);
    minDay.set(Calendar.DAY_OF_MONTH, 1);
    Utils.trimToMidnight(minDay);

    Calendar maxDay = Calendar.getInstance();
    maxDay.setTime(maxDate);

    limiter.setMinDate(minDay);
    limiter.setMaxDate(maxDay);
    Assert.assertTrue(Utils.trimToMidnight(maxDay).getTimeInMillis() >= limiter.setToNearestDate(day).getTimeInMillis());
}
 
Example 2
Source File: DatePickerDialog.java    From MaterialDateTimePicker with Apache License 2.0 5 votes vote down vote up
public void initialize(OnDateSetListener callBack, Calendar initialSelection) {
    mCallBack = callBack;
    mCalendar = Utils.trimToMidnight((Calendar) initialSelection.clone());
    mScrollOrientation = null;
    //noinspection deprecation
    setTimeZone(mCalendar.getTimeZone());

    mVersion = Build.VERSION.SDK_INT < Build.VERSION_CODES.M ? Version.VERSION_1 : Version.VERSION_2;
}
 
Example 3
Source File: DatePickerDialog.java    From MaterialDateTimePicker with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isHighlighted(int year, int month, int day) {
    Calendar date = Calendar.getInstance(getTimeZone());
    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, day);
    Utils.trimToMidnight(date);
    return highlightedDays.contains(date);
}
 
Example 4
Source File: DefaultDateRangeLimiterTest.java    From MaterialDateTimePicker with Apache License 2.0 5 votes vote down vote up
@Test
public void getStartDateShouldReturnMinDate() {
    DefaultDateRangeLimiter limiter = new DefaultDateRangeLimiter();
    Calendar minDate = Calendar.getInstance();

    limiter.setMinDate(minDate);
    minDate = Utils.trimToMidnight(minDate);

    Assert.assertEquals(limiter.getStartDate().getTimeInMillis(), minDate.getTimeInMillis());
}
 
Example 5
Source File: DefaultDateRangeLimiterTest.java    From MaterialDateTimePicker with Apache License 2.0 5 votes vote down vote up
@Test
public void getStartDateShouldReturnMinDateWhenAControllerIsSet() {
    DefaultDateRangeLimiter limiter = new DefaultDateRangeLimiter();
    limiter.setController(controller);
    Calendar minDate = Calendar.getInstance();

    limiter.setMinDate(minDate);
    minDate = Utils.trimToMidnight(minDate);

    Assert.assertEquals(limiter.getStartDate().getTimeInMillis(), minDate.getTimeInMillis());
}
 
Example 6
Source File: DefaultDateRangeLimiterTest.java    From MaterialDateTimePicker with Apache License 2.0 5 votes vote down vote up
@Test
public void getEndDateShouldReturnMaxDate() {
    DefaultDateRangeLimiter limiter = new DefaultDateRangeLimiter();
    Calendar maxDate = Calendar.getInstance();

    limiter.setMaxDate(maxDate);
    maxDate = Utils.trimToMidnight(maxDate);

    Assert.assertEquals(limiter.getEndDate().getTimeInMillis(), maxDate.getTimeInMillis());
}
 
Example 7
Source File: DefaultDateRangeLimiterTest.java    From MaterialDateTimePicker with Apache License 2.0 5 votes vote down vote up
@Test
public void getEndDateShouldReturnMaxDateWhenAControllerIsSet() {
    DefaultDateRangeLimiter limiter = new DefaultDateRangeLimiter();
    limiter.setController(controller);
    Calendar maxDate = Calendar.getInstance();

    limiter.setMaxDate(maxDate);
    maxDate = Utils.trimToMidnight(maxDate);

    Assert.assertEquals(limiter.getEndDate().getTimeInMillis(), maxDate.getTimeInMillis());
}
 
Example 8
Source File: DefaultDateRangeLimiter.java    From MaterialDateTimePicker with Apache License 2.0 4 votes vote down vote up
void setMinDate(@NonNull Calendar calendar) {
    mMinDate = Utils.trimToMidnight((Calendar) calendar.clone());
}
 
Example 9
Source File: DefaultDateRangeLimiter.java    From MaterialDateTimePicker with Apache License 2.0 4 votes vote down vote up
void setMaxDate(@NonNull Calendar calendar) {
    mMaxDate = Utils.trimToMidnight((Calendar) calendar.clone());
}
 
Example 10
Source File: DefaultDateRangeLimiter.java    From MaterialDateTimePicker with Apache License 2.0 4 votes vote down vote up
private boolean isOutOfRange(@NonNull Calendar calendar) {
    Utils.trimToMidnight(calendar);
    return isDisabled(calendar) || !isSelectable(calendar);
}