feiyu02
2024-08-15 196bb14112448857a885e32dc4149e308e00b01a
src/main/kotlin/cn/flightfeather/supervision/infrastructure/utils/DateUtil.kt
@@ -714,6 +714,31 @@
        }
    }
    /**
     * 根据给定的周期,返回所有可能在周期内的周期组合
     * @param period YYYY/M-M
     */
    fun getSuitablePeriod(period: String?):List<String> {
        var year:Int? = null
        var sMonth:Int? = null
        var eMonth:Int? = null
        period?.split("/")?.takeIf { it.size == 2 }?.let { p ->
            year = p[0].toIntOrNull()
            p[1].split("-").takeIf { it.size == 2 }?.let { m->
                sMonth = m[0].toIntOrNull()
                eMonth = m[1].toIntOrNull()
            }
        }
        val result = mutableListOf<String>()
        if (year != null && sMonth != null && eMonth != null) {
            repeat(eMonth!! - sMonth!! + 1) {
                result.add("${year}/${sMonth}-${sMonth}")
            }
            if (sMonth != eMonth) period?.let { result.add(it) }
        }
        return  result
    }
    enum class DateStyle private constructor(val value: String, val isShowOnly: Boolean) {
        YYYYMMDD("yyyyMMdd", false),