yannecer / NCalendar

一款安卓日历,仿miui,钉钉,华为的日历,万年历、365、周日历,月日历,月视图、周视图滑动切换,农历,节气,Andriod Calendar , MIUI Calendar,小米日历
Apache License 2.0
1.59k stars 314 forks source link

获取到的 CalendarDate 中的 lunarMonthStr 似乎有问题 #62

Open xxst opened 4 years ago

xxst commented 4 years ago
var calendarDate = CalendarUtil.getCalendarDate(localDate)
            Log.e(
                BuildConfig.APPLICATION_ID, 
                        "lunarMonthStr: ${calendarDate.lunar.lunarMonthStr}, " +
                        "lunarMonth: ${calendarDate.lunar.lunarMonth}, " +
                        "lunarDayStr: ${calendarDate.lunar.lunarDayStr}, " +
                        "lunarDay: ${calendarDate.lunar.lunarDay}, " +
                        "leapMonth: ${calendarDate.lunar.leapMonth}, " +
                        "lunarMonth: ${calendarDate.lunar.lunarMonth}, " +
                        "isLeap: ${calendarDate.lunar.isLeap}, " +
                        "lunarOnDrawStr: ${calendarDate.lunar.lunarOnDrawStr}, " +
                        "animals: ${calendarDate.lunar.animals}, " +
                        "chineseEra: ${calendarDate.lunar.chineseEra}"
            )

打印的日志:

问题:当是闰月的时候,lunarMonthStr 应该返回的是 “闰四月” 这种字符串结果吧?

xxst commented 4 years ago

找到 Bug 了,是这个方法 LunarUtil#getMonthStr() 代码 bug。这个方法改造了下

public static String getMonthStr(int lunarMonth, boolean isLeap) {
        String monthStr = CHINESE_NUMBER[lunarMonth - 1] + "月";
        String leapMonthStr = "闰" + monthStr;
        return isLeap ? leapMonthStr : monthStr;
    }