This is KMP port of a date picker library written using Jetpack Compose for Android. A big thanks to Kiran Gyawali for this awesome library
Add common library as dependency in common build.gradle:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.thegbguy:nepali-date-picker:1.0.2")
}
Android | iOS |
---|---|
var showDialog by remember { mutableStateOf(false) }
if (showDialog) {
NepaliDatePicker(
onDateSelected = { date ->
// selected date
},
onDismiss = {
showDialog = false
}
)
}
NepaliDate
is a data class used to hold the value of year, month, day, and weekday in date converters and in callbacks
of the date picker.
onDismiss
is mandatory for the callback on the dismiss of the picker dialog.onDateSelected
is mandatory for the callback on the date selected. ReturnsselectedNepaliDate
.
NepaliDatePicker
can take additional arguments to customize the picker to your needs:
startDate
of typeNepaliDate
for the date you want to start with in the picker. Its default value is the current instance.showYearPickerFirst
of typeBoolean
to show the year picker first when the picker is displayed. It is true by default; set it to false if you want the month view as the default view, especially if you have a limited date for selection in the picker.minDate
of typeNepaliDate
to set the lower limit of the date in the picker.maxDate
of typeNepaliDate
to set the upper limit of the date in the picker.highlightDays
of typeList<NepaliDate>
. This will highlight the given list of dates in the picker.disableDays
of typeList<NepaliDate>
. This will disable the selection of the given dates in the picker.
Value when passed beyond the conversion range throws an IllegalArgumentException
. Make sure you catch them.
Converting English Date to Nepali date (i.e., A.D to B.S):
NepaliDateUtils.adToBs(engYY, engMM, engDD)
You can also pass the Calendar
instance as an argument.
Converting Nepali Date to English date (i.e., B.S to A.D):
NepaliDateUtils.bsToAd(nepYY, nepMM, nepDD)
You can also pass NepaliDate
as an argument.
Accessible from NepaliDateUtils
:
NepaliDateUtils.isEngDateInRange(int yy, int mm, int dd)
returns true if the English date is within the range of conversion.NepaliDateUtils.isNepDateInRange(int yy, int mm, int dd)
returns true if the Nepali date is within the range of conversion.NepaliDateUtils.getInstance()
returns the current instance of the Nepali date.NepaliDateUtils.fillMissingWeekDayValue(nepaliDate: NepaliDate)
will add the missingdayOfWeek
for a givenNepaliDate
.
If you like this project, please star this project to encourage the author and fork it in case you need additional features.
If you want to contact me you can reach me at [email protected].
This project uses the following license: MIT License.