Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Basic Calendar Obvious Bug

  1. #1
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Basic Calendar Obvious Bug

    1) Script Title: Basic Calendar

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...iccalendar.htm

    3) Describe problem: hehe, it is cearly shown on the URL above. Go to the section where there are 3 months displayed in a row. It stops executing on December 2009. It also clearly says, "undefined - 2009" instead of January 2010. Does anybody know how to fix it? I run it on my web-site too and it does not look cool any more. :-(

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I think it's cause the month is just being added with no consideration for what the value becomes. Try putting in a conditional statement in. This is example code not functioning code (i think).


    Code:
    <script type="text/javascript">
    var todaydate=new Date()
    var curmonth=todaydate.getMonth()+1 //get current month (1-12)
    var curyear=todaydate.getFullYear() //get current year
    </script>
    <table border="0" cellspacing="0" cellpadding="3">
    <tr>
    <td width="33%">
    <script>
    document.write(buildCal(curmonth-1 ,curyear, "main", "month", "daysofweek", "days", 1));
    </script></td>
    <td width="33%">
    <script>
    document.write(buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1));
    </script></td>
    <td width="34%">
    <script>
    if (curmonth +1 > 12) {
    curmonth = curmonth - 12;
    curyear = curyear + 1;
    }
    document.write(curmonth+1 ,curyear, "main", "month", "daysofweek", "days", 1);
    </script></td>
    </tr>
    </table>

  3. #3
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ... I mean I know how to fix it manually but are there any constant fixes in code so that when it comes to the end of the year I would not have to do it manually?

    Until the year jumps to the first 3 months January February March or any other 3 months in a row within the same year it's OK. When it changes years for example November 2009, December 2009, and January 2010 (or any other versions finishing one year and entering into the next year) we run into a bug as January 2010 is not shown.

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    That code says

    If the current month + 1 is greater then 12, subtract 12 from the current month and add 1, increase the year by 1.

    The only instance this will occur is December subtracting 12 brings it back to 0 and adding 1 to it sets it to 1, or January. The current year is then increased by 1 as well to account for the 12 months that were subtracted. This will also need to be done but in reverse order for January, I think. This is a fix ( if it works), it doesn't require a rework every year the year is being called dynamically, it's not static.

  5. #5
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ************************
    Thanks for a great tip! Conditional statements work! Why didn't I think of it myself too? lol Now we also need to be added into this copy right's stuff to be the bug finders and co-authors of the script hehe. Anyway, I suggest they fix it on dynamicdrive.com as well 'cause displaying the code together with this bug included looks a little wierd
    ************************

    Quote Originally Posted by bluewalrus View Post
    I think it's cause the month is just being added with no consideration for what the value becomes. Try putting in a conditional statement in. This is example code not functioning code (i think).
    Code:
    <script type="text/javascript">
    var todaydate=new Date()
    var curmonth=todaydate.getMonth()+1 //get current month (1-12)
    var curyear=todaydate.getFullYear() //get current year
    </script>
    <table border="0" cellspacing="0" cellpadding="3">
    <tr>
    <td width="33%">
    <script>
    document.write(buildCal(curmonth-1 ,curyear, "main", "month", "daysofweek", "days", 1));
    </script></td>
    <td width="33%">
    <script>
    document.write(buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1));
    </script></td>
    <td width="34%">
    <script>
    if (curmonth +1 > 12) {
    curmonth = curmonth - 12;
    curyear = curyear + 1;
    }
    document.write(curmonth+1 ,curyear, "main", "month", "daysofweek", "days", 1);
    </script></td>
    </tr>
    </table>

  6. #6
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I hear you and understand your code Thanks again. You were simply quicker in replying. I thought I would add another explanation to my first post but you got in with your response faster

    Quote Originally Posted by bluewalrus View Post
    That code says

    If the current month + 1 is greater then 12, subtract 12 from the current month and add 1, increase the year by 1.

    The only instance this will occur is December subtracting 12 brings it back to 0 and adding 1 to it sets it to 1, or January. The current year is then increased by 1 as well to account for the 12 months that were subtracted. This will also need to be done but in reverse order for January, I think. This is a fix ( if it works), it doesn't require a rework every year the year is being called dynamically, it's not static.

  7. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Well the code itself works just the demo is incorrect. This one has the workaround for January, assuming the other worked. To test it adjust the calender on your computer.

    Code:
    <script type="text/javascript">
    var todaydate=new Date()
    var curmonth=todaydate.getMonth()+1 //get current month (1-12)
    var curyear=todaydate.getFullYear() //get current year
    </script>
    <table border="0" cellspacing="0" cellpadding="3">
    <tr>
    <td width="33%">
    <script>
    if (curmonth - 1 < 1) {
    curmonth = curmonth + 12;
    curyear = curyear - 1;
    }
    document.write(buildCal(curmonth-1 ,curyear, "main", "month", "daysofweek", "days", 1));
    </script></td>
    <td width="33%">
    <script>
    document.write(buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1));
    </script></td>
    <td width="34%">
    <script>
    if (curmonth +1 > 12) {
    curmonth = curmonth - 12;
    curyear = curyear + 1;
    }
    document.write(curmonth+1 ,curyear, "main", "month", "daysofweek", "days", 1);
    </script></td>
    </tr>
    </table>

  8. #8
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey, now the middle part has a problem. The last month of the previous year (December 2009 for example) shows OK, January 2010 (in the middle) is indefined and February 2010 (the last one) is OK as well. Which conditional do I add for this case? Thanks.

  9. #9
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    on the second thought the third's case conditional suits perfectly well but are there any "under water hidden" bugs? Will it not stop working somewhere down the road will it? Any ideas anybody?

    if (curmonth +1 > 12) {
    curmonth = curmonth - 12;
    curyear = curyear + 1;
    }

  10. #10
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey, now the middle part has a problem. The last but one month of the previous year (November 2010 for example) shows OK, December 2010 (in the middle) is indefined and January 2011 is OK as well. Which conditional do I add for this case? Any ideas anybody? Thanks.

    look here http://www.ltornado.com/calendarlt.html

    the code I use is this:

    <script type="text/javascript">

    var todaydate=new Date()
    var curmonth=todaydate.getMonth()+1 //get current month (1-12)
    var curyear=todaydate.getFullYear() //get current year

    </script>

    <table border="0" cellspacing="0" cellpadding="3">
    <tr>
    <td width="33%">
    <script>
    if (curmonth - 1 < 1) {
    curmonth = curmonth + 12;
    curyear = curyear - 1;
    }
    document.write(buildCal(curmonth-1,curyear, "main", "month", "daysofweek", "days", 1));
    </script></td>
    <td width="33%">
    <script>
    if (curmonth +1 > 12) {
    curmonth = curmonth - 12;
    curyear = curyear + 1;
    }
    document.write(buildCal(curmonth,curyear, "main", "month", "daysofweek", "days", 1));
    </script></td>
    <td width="34%">
    <script>
    if (curmonth +1 > 12) {
    curmonth = curmonth - 12;
    curyear = curyear + 1;
    }
    document.write(buildCal(curmonth+1 ,curyear, "main", "month", "daysofweek", "days", 1));
    </script></td>
    </tr>
    </table>
    <!--end calendar script-->

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •