Skip to content
This repository was archived by the owner on Sep 3, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.datetime.internal.TimeChangeListener
import com.afollestad.materialdialogs.datetime.utils.getDatePicker
import com.afollestad.materialdialogs.datetime.utils.isFutureDate
import com.afollestad.materialdialogs.datetime.utils.isSameDayAs
import com.afollestad.materialdialogs.utils.MDUtil.isLandscape
import java.util.Calendar

Expand All @@ -46,10 +47,10 @@ fun MaterialDialog.datePicker(
dialogWrapContent = windowContext.isLandscape()
)

check(minDate == null || currentDate == null || minDate.before(currentDate)) {
check(minDate == null || currentDate == null || minDate.isSameDayAs(currentDate) || minDate.before(currentDate)) {
"Your `minDate` must be less than `currentDate`."
}
check(maxDate == null || currentDate == null || maxDate.after(currentDate)) {
check(maxDate == null || currentDate == null || maxDate.isSameDayAs(currentDate) || maxDate.after(currentDate)) {
"Your `maxDate` must be bigger than `currentDate`."
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ internal fun toCalendar(
set(Calendar.MINUTE, timePicker.minute())
}
}

/**
* Checks if two calendars are the same day
*/
internal fun Calendar.isSameDayAs(other: Calendar): Boolean {
val thisDayOfYear = get(Calendar.DAY_OF_YEAR)
val thisYear = get(Calendar.YEAR)

val otherDayOfYear = other.get(Calendar.DAY_OF_YEAR)
val otherYear = other.get(Calendar.YEAR)

return thisDayOfYear == otherDayOfYear && thisYear == otherYear
}
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ext.versions = [
min_sdk: 16,
compile_sdk: 29,
build_tools: "29.0.0",
publish_version: "3.3.0",
publish_version: "3.3.1",
publish_version_code: 262
]

Expand Down