This is a re-work of Nepali Date Picker Converter in jetpack compose and kotlin.
English Locale | Nepali Locale |
---|---|
Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add the dependency
dependencies {
implementation 'com.github.keyrunHORNET:composeNepaliDatePicker:$version'
}
var showDialog by remember { mutableStateOf(false) }
if (showDialog) {
NepaliDatePicker(
onDateSelected = { date ->
// selected date
},
onDismiss = {
showDialog = false
}
)
}
NepaliDate
is a data class used to hold value of year, month, day and weekday in date converters and in callbacks of date picker.
onDismiss
is mandatory for callback on dismiss of picker dialog.
onDateSelected
is mandatory for callback on date selected. Returns selectedNepaliDate
NepaliDatePicker
can take additional arguments to customise picker to your needs
-
startDate
of typeNepaliDate
for the date you want to start with, in picker. It's default value is current instance. -
showYearPickerFirst
of typeBoolean
to show year picker first when picker is displayed. Itstrue
by default and set it to false if you want month view as default view. Especially if you have limited date for selection in picker. -
minDate
of typeNepaliDate
to set the lower limit of date in picker. -
maxDate
of typeNepaliDate
to set upper limit of date in picker. -
highlightDays
of typeList<NepaliDate>
. This will highlight the given list of dates in picker. -
disableDays
of typeList<NepaliDate>
. This will disable selection of the given dates in 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)
returnstrue
if english date is within the range of conversion. -
NepaliDateUtils.isNepDateInRange(int yy,int mm,int dd)
returnstrue
if nepali date is within the range of conversion. -
NepaliDateUtils.getInstance()
returns current instance of Nepali date -
NepaliDateUtils.fillMissingWeekDayValue(nepaliDate: NepaliDate)
will add missing dayOfWeek for a given NepaliDate.
MIT License
Copyright (c) 2022 Kiran Gyawali
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.