管灌系统巡查员智能手机App
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.loper7.date_time_picker.controller
 
import com.loper7.date_time_picker.ext.getMaxDayInMonth
import com.loper7.date_time_picker.number_picker.NumberPicker
import java.lang.Exception
import java.util.*
 
/**
 *
 * @CreateDate:     2021/6/18 9:35
 * @Description:    控制器基类
 * @Author:         LOPER7
 * @Email:          loper7@163.com
 */
abstract class BaseDateTimeController : DateTimeInterface {
 
    abstract fun bindPicker(type: Int, picker: NumberPicker?): BaseDateTimeController
 
    abstract fun bindGlobal(global: Int): BaseDateTimeController
 
    abstract fun build(): BaseDateTimeController
 
    /**
     * 获取某月最大天数
     */
    protected fun getMaxDayInMonth(year: Int?, month: Int?): Int {
        if (year == null || month == null)
            return 0
        if (year <= 0 || month < 0)
            return 0
        try {
            val calendar: Calendar = Calendar.getInstance()
            calendar.clear()
            calendar.set(Calendar.YEAR, year)
            calendar.set(Calendar.MONTH, month)
            return calendar.getMaxDayInMonth()
        } catch (e: Exception) {
            return 0
        }
 
    }
 
}