Skip to content

Commit

Permalink
修复腊月二十九的阴历描述
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Sep 30, 2020
1 parent af4c52b commit 2cc7a05
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 121 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
minSdkVersion 15
targetSdkVersion 28
versionCode 2
versionName "5.0.0"
versionName "5.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/necer/ncalendar/TestActivity2.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.necer.ncalendar;

import android.os.Bundle;
import android.util.Log;

import com.necer.MyLog;
import com.necer.calendar.BaseCalendar;
import com.necer.calendar.MonthCalendar;
import com.necer.enumeration.DateChangeBehavior;
Expand All @@ -29,9 +27,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
monthCalendar.setOnCalendarChangedListener(new OnCalendarChangedListener() {
@Override
public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) {
MyLog.d("onCalendarChange:::"+localDate);
}

}
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void jump_2018_08_11(View view) {
}

public void jump_2019_06_20(View view) {
miui9Calendar.jumpDate("2019-06-20");
miui9Calendar.jumpDate("1901-02-01");
}

public void jump_2020_08_11(View view) {
Expand Down
4 changes: 2 additions & 2 deletions ncalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "5.0.0"
versionName "5.0.1"
}
}

Expand All @@ -28,7 +28,7 @@ publish {
repoName = 'maven'//bintray仓库
groupId = 'com.necer.ncalendar'//jcenter上的路径
artifactId = 'ncalendar'//项目名称
publishVersion = '5.0.0'//版本号
publishVersion = '5.0.1'//版本号
desc = 'NCalendar'
website = 'https://github.com/yannecer/NCalendar'
}
24 changes: 0 additions & 24 deletions ncalendar/src/main/java/com/necer/MyLog.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class BaseCalendar extends ViewPager implements ICalendar {
private Attrs mAttrs;
private boolean mScrollEnable = true;
private CheckModel mCheckModel;//选中模式
private final static String mDefaultStartDate = "1901-01-01";
private final static String mDefaultStartDate = "1901-02-01";
private final static String mDefaultEndDateDate = "2099-12-31";

private boolean mDefaultCheckedFirstDate;//默认选择时,翻页选中第一个日期
Expand Down
19 changes: 11 additions & 8 deletions ncalendar/src/main/java/com/necer/utils/CalendarUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public class CalendarUtil {



/**
* 两个日期是否同月
*/
Expand Down Expand Up @@ -223,6 +222,7 @@ public static List<String> getWorkdayList() {

/**
* 转化一周从周日开始
*
* @param date
* @return
*/
Expand All @@ -236,6 +236,7 @@ public static LocalDate getSunFirstDayOfWeek(LocalDate date) {

/**
* 转化一周从周一开始
*
* @param date
* @return
*/
Expand All @@ -246,6 +247,7 @@ public static LocalDate getMonFirstDayOfWeek(LocalDate date) {

/**
* 获取CalendarDate CalendarDate包含需要显示的信息 农历,节气等
*
* @param localDate
* @return
*/
Expand All @@ -256,13 +258,14 @@ public static CalendarDate getCalendarDate(LocalDate localDate) {
int solarDay = localDate.getDayOfMonth();
Lunar lunar = LunarUtil.getLunar(solarYear, solarMonth, solarDay);

if (solarYear != 1900) {
calendarDate.lunar = lunar;
calendarDate.localDate = localDate;
calendarDate.solarTerm = SolarTermUtil.getSolatName(solarYear, (solarMonth < 10 ? ("0" + solarMonth) : (solarMonth + "")) + solarDay);
calendarDate.solarHoliday = HolidayUtil.getSolarHoliday(solarYear, solarMonth, solarDay);
calendarDate.lunarHoliday = HolidayUtil.getLunarHoliday(lunar.lunarYear, lunar.lunarMonth, lunar.lunarDay);
}
LocalDate nextLocalDate = localDate.plusDays(1);
Lunar nextLunar = LunarUtil.getLunar(nextLocalDate.getYear(), nextLocalDate.getMonthOfYear(), nextLocalDate.getDayOfMonth());

calendarDate.lunar = lunar;
calendarDate.localDate = localDate;
calendarDate.solarTerm = SolarTermUtil.getSolatName(solarYear, (solarMonth < 10 ? ("0" + solarMonth) : (solarMonth + "")) + solarDay);
calendarDate.solarHoliday = HolidayUtil.getSolarHoliday(solarYear, solarMonth, solarDay);
calendarDate.lunarHoliday = HolidayUtil.getLunarHoliday(lunar, nextLunar);

return calendarDate;
}
Expand Down
17 changes: 7 additions & 10 deletions ncalendar/src/main/java/com/necer/utils/HolidayUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.necer.utils;

import com.necer.entity.Lunar;

import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -64,11 +66,11 @@ public static String getSolarHoliday(int solarYear, int solarMonth, int solarDay
/**
* 用于获取中国的传统节日
*
* @param lunarMonth 农历的月
* @param lunarDay 农历日
* @return 中国传统节日
*/
public static String getLunarHoliday(int lunarYear, int lunarMonth, int lunarDay) {
public static String getLunarHoliday(Lunar lunar, Lunar nextLunar) {
int lunarMonth = lunar.lunarMonth;
int lunarDay = lunar.lunarDay;
String message = "";
if (lunarMonth == 1 && lunarDay == 1) {
message = "春节";
Expand All @@ -90,13 +92,8 @@ public static String getLunarHoliday(int lunarYear, int lunarMonth, int lunarDay
message = "腊八节";
} else if (lunarMonth == 12 && lunarDay == 23) {
message = "小年";
} else {
if (lunarMonth == 12) {
if ((((LunarUtil.daysInLunarMonth(lunarYear, lunarMonth) == 29) && lunarDay == 29))
|| ((((LunarUtil.daysInLunarMonth(lunarYear, lunarMonth) == 30) && lunarDay == 30)))) {
message = "除夕";
}
}
} else if (lunarMonth == 12 && lunar.lunarMonth != nextLunar.lunarMonth) {
message = "除夕";
}
return message;
}
Expand Down
73 changes: 4 additions & 69 deletions ncalendar/src/main/java/com/necer/utils/LunarUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,71 +100,6 @@ public class LunarUtil {
private static String[] Animals = {"猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗"};
private static String chineseTen[] = {"初", "十", "廿", "卅"};

/**
* 传回农历year年month月的总天数
*
* @param year 要计算的年份
* @param month 要计算的月
* @return 传回天数
*/
public static int daysInMonth(int year, int month) {
return daysInMonth(year, month, false);
}

/**
* 传回农历year年month月的总天数
*
* @param year 要计算的年份
* @param month 要计算的月
* @param leap 当月是否是闰月
* @return 传回天数,如果闰月是错误的,返回0.
*/
public static int daysInMonth(int year, int month, boolean leap) {
int leapMonth = leapMonth(year);
int offset = 0;
// 如果本年有闰月且month大于闰月时,需要校正
if (leapMonth != 0 && month > leapMonth) {
offset = 1;
}
// 不考虑闰月
if (!leap) {
return daysInLunarMonth(year, month + offset);
} else {
// 传入的闰月是正确的月份
if (leapMonth != 0 && leapMonth == month) {
return daysInLunarMonth(year, month + 1);
}
}
return 0;
}


/**
* 传回农历year年month月的总天数,总共有13个月包括闰月
*
* @param year 将要计算的年份
* @param month 将要计算的月份
* @return 传回农历 year年month月的总天数
*/
public static int daysInLunarMonth(int year, int month) {

if ((LUNAR_INFO[year - MIN_YEAR] & (0x100000 >> month)) == 0)
return 29;
else
return 30;
}

/**
* /**
* 传回农历 year年闰哪个月 1-12 , 没闰传回 0
*
* @param year 将要计算的年份
* @return 传回农历 year年闰哪个月1-12, 没闰传回 0
*/
public static int leapMonth(int year) {
return (LUNAR_INFO[year - MIN_YEAR] & 0xF00000) >> 20;
}


private static int getBitInt(int data, int length, int shift) {
return (data & (((1 << length) - 1) << shift)) >> shift;
Expand Down Expand Up @@ -227,7 +162,7 @@ public static Lunar getLunar(int solarYear, int solarMonth, int solarDay) {
lunar.lunarYearStr = getGan(lunar.lunarYear) + getZhi(lunar.lunarYear) + getAnimalString(lunar.lunarYear);
lunar.lunarMonthStr = getMonthStr(lunar.lunarMonth, lunar.isLeap);
lunar.lunarDayStr = getDayStr(lunar.lunarDay);
lunar.lunarOnDrawStr = getDrawStr(lunar.lunarMonth, lunar.lunarDay, lunar.isLeap);
lunar.lunarOnDrawStr = getDrawStr(lunar.lunarMonth, lunar.lunarDay, lunar.lunarDayStr, lunar.isLeap);

return lunar;
}
Expand All @@ -254,11 +189,11 @@ private static String getMonthStr(int lunarMonth, boolean isLeap) {
return isLeap ? "闰" : "" + CHINESE_NUMBER[lunarMonth - 1] + "月";
}

private static String getDrawStr(int lunatMonth, int lunatDay, boolean isLeap) {
private static String getDrawStr(int lunatMonth, int lunatDay, String lunarDayStr, boolean isLeap) {
String relust = "";
if (relust.equals("初一") && isLeap) {
if ("初一".equals(lunarDayStr) && isLeap) {
relust = "闰" + CHINESE_NUMBER[lunatMonth - 1] + "月";
} else if (relust.equals("初一") && !isLeap) {
} else if ("初一".equals(lunarDayStr)) {
relust = CHINESE_NUMBER[lunatMonth - 1] + "月";
} else if (lunatDay == 10) {
relust = "初十";
Expand Down
1 change: 0 additions & 1 deletion ncalendar/src/main/java/com/necer/view/CalendarView2.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.widget.GridView;
import android.widget.ListAdapter;

import com.necer.MyLog;
import com.necer.adapter.GridCalendarAdapter;
import com.necer.calendar.BaseCalendar;
import com.necer.enumeration.CalendarType;
Expand Down

0 comments on commit 2cc7a05

Please sign in to comment.