Skip to content

Commit

Permalink
修复跳转日期的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yanbinbin committed Oct 16, 2017
1 parent 9fd9309 commit f8d8ac5
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 15
targetSdkVersion 25
versionCode 2
versionName "2.4.2"
versionName "2.4.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void toToday(View view) {
}

public void setDate(View view) {
monthcalendar.setDate("2018-10-11");
monthcalendar.setDate("2017-11-11");
// monthcalendar.setDate("2017-12-31");
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_ncalendar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:background="@android:color/white"/>

</com.necer.ncalendar.calendar.NCalendar>

Expand Down
2 changes: 1 addition & 1 deletion ncalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
version = "2.4.2" //版本号
version = "2.4.3" //版本号

android {
compileSdkVersion 25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public void setOnMonthCalendarChangedListener(OnMonthCalendarChangedListener onM

@Override
protected void setDateTime(DateTime dateTime) {

if (dateTime.getMillis() > endDateTime.getMillis() || dateTime.getMillis() < startDateTime.getMillis()) {
Toast.makeText(getContext(), R.string.illegal_date, Toast.LENGTH_SHORT).show();
return;
Expand All @@ -118,7 +117,6 @@ protected void setDateTime(DateTime dateTime) {
//不是当月
if (!Utils.isEqualsMonth(initialDateTime, dateTime)) {
int months = Utils.getIntervalMonths(initialDateTime, dateTime);

int i = getCurrentItem() + months;
setCurrentItem(i, Math.abs(months) < 2);
currectMonthView = getCurrectMonthView();
Expand Down
5 changes: 3 additions & 2 deletions ncalendar/src/main/java/com/necer/ncalendar/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public static boolean isNextMonth(DateTime dateTime1, DateTime dateTime2) {
* @return
*/
public static int getIntervalMonths(DateTime dateTime1, DateTime dateTime2) {
dateTime1 = dateTime1.withTimeAtStartOfDay();
dateTime2 = dateTime2.withTimeAtStartOfDay();
dateTime1 = dateTime1.withDayOfMonth(1).withTimeAtStartOfDay();
dateTime2 = dateTime2.withDayOfMonth(1).withTimeAtStartOfDay();

return Months.monthsBetween(dateTime1, dateTime2).getMonths();
}

Expand Down

0 comments on commit f8d8ac5

Please sign in to comment.