SpongeBobSun / mCalendarView

Customizable & Shrinkable Calendar Widget for Android
Apache License 2.0
243 stars 73 forks source link

CalendarUtil.java has Error. #6

Closed oong closed 8 years ago

oong commented 8 years ago

Hi.

CalendarUtil.position2Year(int pos) method has logical error.

problem : 2014/11 <- 2015/12 -> 2016/1

i modified this method .... else { ret = tmpYear - ((500 - pos)+tmpMonth)/12; }

to

... else { ret = tmpYear - ((500-pos)/12); }

This works normally.

SpongeBobSun commented 8 years ago

Oooops that's my bug. I've already merged your code to my version. Thank you very much! And I've added your name to the credits section in readme file. Thanks again.

fg2q1q3q commented 8 years ago

A few days ago in the course of the use, I also found this bug, but I think the current code is still has problem, when it is now in January, the problem came out. Below are my modify code, if it has mistakes, please let me know, thank you.

   if (pos > COUNT/2) {
        ret = tmpYear + ((pos - COUNT/2) + date.getMonth() - 1) / 12;
    } else {
        int temp=COUNT/2 - pos;
        ret = tmpYear - temp / 12;
        if(temp%12==date.getMonth()){
            ret-=1;
        }
    }
SpongeBobSun commented 8 years ago

Hi there, @oong 's code still have bug as @fg2q1q3q described. You can set your phone's date to 2015-01-05 and swipe left & right to test it. @fg2q1q3q 's code also have an issue. I set my phone's date to 2016-01 and swipe left, the first wipe is fine, which switch to 2014-12, but the second swipe is not correct. I modified my code as below.

public static int position2Year(int pos){
        int tmpYear,tmpMonth;
        Calendar c = Calendar.getInstance();
//        tmpYear = c.get(Calendar.YEAR);
        // TODO: 15/12/10 Maybe using current year is a mistake.
        tmpYear = date.getYear();
        tmpMonth = CalendarUtil.position2Month(pos);
        int ret;
        if(pos == 500){
            return tmpYear;
        }
        if(pos > 500){

            ret = tmpYear + ((pos - 500) + c.get(Calendar.MONTH))/12;
//            ret = tmpYear + ((pos - 500) + date.getMonth() - 1)/12;//oong

        }else{
            ret =  tmpYear - ((500 - pos)+tmpMonth - 1)/12;
//            ret = tmpYear - ((500-pos)/12);   //oong
        }
        return ret;
    }

And tested on my phone which date is set to 2015-01-05 and 2015-12-05. It works fine now.

If any questions, please let me know. I reopened this issue due to we still need a thorough test on this.

Thanks you guys.

Bob.

SpongeBobSun commented 8 years ago

@oong @fg2q1q3q Hi guys, my homie @mBigFlower just added an awesome expandable calendar view on this project. Check out readme page for screenshots.