Results 1 to 10 of 10

Thread: November dates wrong

  1. #1
    Join Date
    Oct 2016
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default November dates wrong

    1) Script Title: Dynamic Date Selector (DtTvB)

    2) Script URL: http://www.javascriptkit.com/script/...selector.shtml

    3) Describe problem: Has worked fine but I just noticed that there's a problem with getting the November calendar dates. The month shows but the calendar dates are those of December. You can see it on the Example.
    Last edited by jscheuer1; 10-31-2016 at 07:25 PM.

  2. #2
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    The example page looks correct to me. 1st November 2016 is a Tuesday.

  3. #3
    Join Date
    Oct 2016
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That's not what I see. I see November 1 as a Thursday.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I see the problem Thursday is 11/1/16 in IE 11, Opera, Chrome, and Firefox (all latest for Win 7). What do you think could be causing you (styxlawyer) to see the correct Tuesday for 11/1/16? Maybe you're in a different timezone and it wasn't Oct 31 yet, or was already Nov 1. In any case, I will be looking at the code and report back what I find, if anything.
    Last edited by jscheuer1; 11-01-2016 at 03:54 AM. Reason: figured a possible reason for styxlawyer's results
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, in limited testing it appears the problem is that the date is set after the month and year, which apparently allows it to sometimes go ahead an extra month owing to the fact that some months are shorter than others and on the last day of a long month that pushes it ahead to the first day of the next month after next. I've changed it to set the date prior to setting the the month and year, hopefully this will not allow it to jump backward one extra month in certain cases - I'm thinking it probably will not. In any case, change:

    Code:
    // This one draws calendar...
    function ds_draw_calendar(m, y) {
    	// First clean the output buffer.
    	ds_ob_clean();
    	// Here we go, do the header
    	ds_echo (ds_template_main_above(ds_monthnames[m - 1] + ' ' + y));
    	for (i = 0; i < 7; i ++) {
    		ds_echo (ds_template_day_row(ds_daynames[i]));
    	}
    	// Make a date object.
    	var ds_dc_date = new Date();
    	ds_dc_date.setMonth(m - 1);
    	ds_dc_date.setFullYear(y);
    	ds_dc_date.setDate(1);
    	if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
    		days = 31;
    	} else if (m == 4 || m = . . .
    To:

    Code:
    // This one draws calendar...
    function ds_draw_calendar(m, y) {
    	// First clean the output buffer.
    	ds_ob_clean();
    	// Here we go, do the header
    	ds_echo (ds_template_main_above(ds_monthnames[m - 1] + ' ' + y));
    	for (i = 0; i < 7; i ++) {
    		ds_echo (ds_template_day_row(ds_daynames[i]));
    	}
    	// Make a date object.
    	var ds_dc_date = new Date();
    	ds_dc_date.setDate(1);
    	ds_dc_date.setMonth(m - 1);
    	ds_dc_date.setFullYear(y);
    	if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
    		days = 31;
    	} else if (m == 4 || m = . . .
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    Sorry for not replying earlier, I was asleep! I'm in the UK on GMT using Windows 8.1 with Opera 41.0 and it was already 1st November when I looked at the demo page.

  7. #7
    Join Date
    Oct 2016
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for concurring with my observation. I love the script -- I'm using it on one of my websites and was surprised when it misbehaved. I'm not familiar with javascript so I appreciate your effort to debug it.

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Oct 2016
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes I see your fix. I'll patch it on my website.
    Can you make the change on the Javascriptkiit website so others won't be trapped in the future.

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm neither a contributor to nor admin of javascriptkit. So my voice would be as likely to gain notice as anyone's on this issue. I will look into reporting it.

    Oh, looks like the admin from here runs that site as well (something I often suspected, but was never sure of). So that increases the chances it will be dealt with. In any case, I sent him an email explaining the issue and the fix.
    Last edited by jscheuer1; 11-02-2016 at 10:58 PM. Reason: add last paragraph
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  11. The Following User Says Thank You to jscheuer1 For This Useful Post:

    james438 (11-03-2016)

Similar Threads

  1. different dates
    By james438 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 06-09-2010, 06:35 AM
  2. Math wrong? Array wrong?
    By bluewalrus in forum PHP
    Replies: 0
    Last Post: 10-17-2009, 02:32 PM
  3. my rss pause scroller dates seem wrong 1969?
    By rcw in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 01-08-2008, 04:58 PM
  4. Standard Dates
    By helpless in forum PHP
    Replies: 1
    Last Post: 12-18-2006, 09:50 PM
  5. Dates
    By NXArmada in forum PHP
    Replies: 10
    Last Post: 05-22-2006, 05:11 PM

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
  •