1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. To combat forum spam, new accounts will need to make at least one (valid) post.
    Otherwise, we will periodically purge all users without posts or that haven't confirmed their account.

{Fixed} Event highlighting muckup...

Discussion in 'General Support' started by ve9gra, Jun 25, 2003.

Thread Status:
Not open for further replies.
  1. ve9gra

    ve9gra Support Team

    I have a weird problem.... I have two hosts... One production, and one dev... I use the same config on both, yet on my dev the highlighted days are all one day late..... I don't understand what's going on..

    Here's what's happening..

    Production

    Dev

    The production server is running Apache on a Linux platform, and the dev server is running IIS6 on Win2003.

    Help me please!!!!! :(
     
  2. Brian

    Brian EPC Developer Staff Member

    I've taken a look at both of your sites and I'm not sure what could be causing this. With over 30,000 downloads, I've never heard of this problem before. :blink:

    Has the source code been modified at all?

    The strange part is that it is marking today's date correctly so the first place I would look would be the source code and see if it was changed somehow.
     
  3. ve9gra

    ve9gra Support Team

    The only sections where the source code was modified is the sections defining the colors and the default values for the variables..... other than that nothing has been modified...

    AND! both the scripts are exact copies..... in fact just before I posted this I re-downloaded the script from my production to my dev server..... and it's still the same...

    :huh: me no comprendo...... :p

    How can the values be changed..... and all consistently.... I could understand if it was only 1 day... but all of em... You can also check the current month and you'll see the same thing....

    This makes absolutely no sense at all..... I'm going :wacko:
     
  4. Brian

    Brian EPC Developer Staff Member

    Can you PM me a complete copy of the file from the server that's showing the incorrect days being marked?
     
  5. ricur

    ricur New Member

    I also have this problem.
    Basically, I copied the whole escalendar.php script into another file, and at the top of the page, hardcoded $es = "2004-11-01";
    $ee = "2004-12-01";
    $mn = 11;
    $yr = 2004.

    For some reason, Mon 1st Nov is not coloured, but if I go to $mn = 12, and look, the 2nd of dec is coloured in for some strange reason.

    If I try this on your website version (ie, using the configuration tool), it works fine.
    I am running apache2, php 4.2.2.
    I am quite desperate to sort this - can you help ?
    Richard
     
  6. ve9gra

    ve9gra Support Team

    Ricur, are you sure that your highlights are the right colors... because your event is set to be from Nov 1 to Dec 1..... so if you inverted your highlight color with the normal color, you'd get normal colors for the event, and then highlights for outside of the event... which falls on Dec 2...

    I hope I'm making sense to you...


    Papa, I just PMed you the whole file.. and both servers are using the exact same file. Downloaded from one, uploaded on the other...
     
  7. ricur

    ricur New Member

    My highlights are the default colours.
    I have just done some playing round, and I can fix it by changing the code slightly - I havent tested it thoroughly tho - I only tested it on my specific date range of 2004-11-01 -> 2004-12-01.

    I changed the following:
    while ($i < $smc) {
    $es[$i] = ereg_replace('-','/', $es[$i]);
    $ee[$i] = ereg_replace('-','/', $ee[$i]);
    $start = intval(strtotime ($es[$i])/86400)+1;
    $end = intval(strtotime ($ee[$i])/86400)+1;

    to read:
    while ($i < $smc) {
    $es[$i] = ereg_replace('-','/', $es[$i]);
    $ee[$i] = ereg_replace('-','/', $ee[$i]);
    $start = intval(strtotime ($es[$i])/86400);
    $end = intval(strtotime ($ee[$i])/86400);
     
  8. ve9gra

    ve9gra Support Team

    do you have a link to your calendar?
     
  9. ve9gra

    ve9gra Support Team

    Hey Ricur... when I did what you did on mine.. (removed the +1 for $start and $end).. it fixed it! :)

    I don't quite understand why that 1 second makes the difference but hey... whatever works...
     
  10. ricur

    ricur New Member

    Sorry - I dont have an external link that I can provide due to company confidentiality etc etc.
    I *THINK* the error is due to leap years or daylight saving changes etc.
    Anyway, glad it helped :)

    Hopefully it will work for me (following further testing of course).

    Any thoughts from the developers ????

    Rich
     
  11. ve9gra

    ve9gra Support Team

    Hi Ricur and Papa,

    I have figured out my "problem"..... Ricur's problem pointed me in the right direction.

    What's happening is that my production server is set in some timezone that I'm not too sure about... but it doesn't use DST at all..... Where as my dev server is currently in the Atlantic Time Zone with Daylight Savings enabled... As soon as I turned it off, dates were fine...

    Kinda weird if you ask me... I thought it'd take the clock settings, but seeing as how the clock is not actually changed when you enable DST, I guess that it messes things up... I guess DST shouldn't be turned on anyways on a server... anywho... if anyone else has that problem... well, there's your fix ;)

    Thanks again for a great product Papa!!
     
  12. Brian

    Brian EPC Developer Staff Member

    :) Wow!

    Great work. I'll add that as an option that can be set by the user in the next version of the script.
     
  13. ve9gra

    ve9gra Support Team

    This has to be a platform issue with PHP and Win2K3 I'm guessing.... because it displays right on my Linux server, it's also ok on my WinXP (installed it just for the purpose of testing this)..... it's only my 2003 Server that causes problems... anyways, I changed the code somewhat to make it work on my dev server.....

    I'm pasting here the same code snipit that Ricur had posted before... and commented out the original lines and followed them with the edited ones...

    Code:
    while ($i < $smc) {
    
    $es[$i] = ereg_replace('-','/', $es[$i]);
    $ee[$i] = ereg_replace('-','/', $ee[$i]);
    //$start = intval(strtotime ($es[$i])/86400)+1;
    //$end = intval(strtotime ($ee[$i])/86400)+1;
    $start = intval(strtotime ($es[$i])/86400)+!date("I", strtotime ($es[$i]));
    $end = intval(strtotime ($ee[$i])/86400)+!date("I", strtotime ($ee[$i]));
    
    So what it does now is a check to see if the date for the start and end are affected by DST (which is what date("I") returns.

    Anyways.... it's now working on my server, but I'm not sure this will help anyone else out there as it seems I'm the only one affected.....

    I'd like to be able to confirm that it's due to the platform..... but this seems the most likely cause of the problem.

    Papa: feedback on this?
     
  14. ricur

    ricur New Member

    I still have the problem even after both ve9gra and my own fix attempts.
    I dont know why, but by removing the "!" from ve9gra's fix, it seems to work correctly.:
    $start = intval(strtotime ($es[$i])/86400)+date("I", strtotime ($es[$i]));
    $end = intval(strtotime ($ee[$i])/86400)+date("I", strtotime ($ee[$i]));

    I am in UK (so we are in BST at the moment, or GMT the rest of the time).
    BTW, I am on Linux so it cant be a Win2k3 issue.
     
  15. ricur

    ricur New Member

    OK I have sorted the problem.
    The fix by ve9gra seems to work fine - the reason I still had the problems was due to another (almost identical coincidentally) bug in my own code which was used to decided which squares to colour.

    Anyway, all is sorted now.

    Thanks all
     
  16. ve9gra

    ve9gra Support Team

    Ricur: Don't use my previous "fix"!!!! I found a bug in it... Here's the explanation.

    The original code will affect either from May-Oct or from Nov-Apr (as far as I can tell)... If you have DST enabled.

    I modified the calender display to be able to figure out how the marking was taking place. I changed it so that you see it in this format... <day of month>-<day number since Jan 1, 1970>... Use the different styles as guidelines to follow...

    =======
    Style 1 - Original calendar code
    http://ve9gra.gotdns.org/reuse/calendar/year1.html

    Highlighted in red, you can see that there's days overlapping (April-May) and days missing (Oct-Nov)...

    So if I mark any days in the May-Oct period, you can see that it marks it one day late. Here I'm marking June 1, 2003 and it's highlighting June 2.

    Onto my first fix...

    ========
    Style 2 - Modification of the highlight function
    http://ve9gra.gotdns.org/reuse/calendar/year2.html

    Here's the code that was changed.....
    Code:
    //$start = intval(strtotime ($es[$i])/86400)+1;
    //$end = intval(strtotime ($ee[$i])/86400)+1;
    $start = intval(strtotime ($es[$i])/86400)+!date("I", strtotime ($es[$i]));
    $end = intval(strtotime ($ee[$i])/86400)+!date("I", strtotime ($ee[$i]));
    In this one you see that where the days mess up are actually the days where the time changes from Standard Time to Daylight Savings Time.... You see in green that the past problem is fixed, and in red, where the problem is now.

    The problem with this fix is that it only addresses the highlighting.. When the calendar is being built, it still uses the same day numbers as in style 1... but it highlights them using style 2... So for 2003, anything highlighted between April 6 to 30, and October 26 to 31 would be messed up.

    Here I'm highlighting April 7 and April 6 is highlited.

    Same for October 27...

    So..... I tried to fix that too...

    ========
    Style 3 - Modification of the day numbering function
    http://ve9gra.gotdns.org/reuse/calendar/year3.html

    Here I undid what I did in Style 2
    Code:
    $start = intval(strtotime ($es[$i])/86400)+1;
    $end = intval(strtotime ($ee[$i])/86400)+1;
    //$start = intval(strtotime ($es[$i])/86400)+!date("I", strtotime ($es[$i]));
    //$end = intval(strtotime ($ee[$i])/86400)+!date("I", strtotime ($ee[$i]));
    But I changed a different section
    Code:
    //$tnum = (intval((date ("U", mktime(20,0,0,$tmo,$tda,$tyr))/86400))); // TODAY'S DAY NUMBER
    $tnum = (intval((date ("U", mktime(21,0,0,$tmo,$tda,$tyr))/86400))); // TODAY'S DAY NUMBER
    ...
    //$daycount = (intval((date ("U", mktime(20,0,0,$mo,1,$yr))/86400)))-$ds; // FIRST OF MONTH DAY NUMBER
    $daycount = (intval((date ("U", mktime(21,0,0,$mo,1,$yr))/86400)))-$ds; // FIRST OF MONTH DAY NUMBER
    Changed from mktime(20 to mktime(21

    By changing this I was avoiding the 1 hour change when I'd enter or leave the DST, forcing to have a 1am timestamp instead of midnight... You can see that all the previous affected regions are now in green... All was working A-OK using this version, but then I started to think about the other timezones... if it would affect them or not. Then, this is when I found another bug by fluke...

    If you look at Jan 1, the day number is 12054 and if you times that by 24*60*60 (number of seconds in 1 day), you get 1041465600 which should be the number of seconds since EPOC (Jan 1, 1970 GMT). BUT!! when I checked that number using echo date("D M j G:i:s T Y",12054*24*60*60), I actually got Wed Jan 1 20:00:00 Atlantic Standard Time 2003 which meant Jan 2, 2003 0:00 GMT...

    so... last fix...

    ========
    Style 4 - Modification of day numbering AND day highlighting functions
    http://ve9gra.gotdns.org/reuse/calendar/year4.html

    You can see here that Jan 1 is now 12053... what it should be...

    Here's what has to be modified
    Code:
    //$tnum = (intval((date ("U", mktime(20,0,0,$tmo,$tda,$tyr))/86400))); // TODAY'S DAY NUMBER
    $tnum = (intval((date ("U", mktime(0,0,0,$tmo,$tda,$tyr)-(intval(date("O", mktime(0,0,0,$tmo,$tda,$tyr)))*36))/86400))); // TODAY'S DAY NUMBER
    ...
    //$daycount = (intval((date ("U", mktime(20,0,0,$mo,1,$yr))/86400)))-$ds; // FIRST OF MONTH DAY NUMBER
    $daycount = (intval((date ("U", mktime(0,0,0,$mo,1,$yr)-(intval(date("O", mktime(0,0,0,$mo,1,$yr)))*36))/86400)))-$ds; // FIRST OF MONTH DAY NUMBER
    And
    Code:
    //$start = intval(strtotime ($es[$i])/86400)+1;
    //$end = intval(strtotime ($ee[$i])/86400)+1;
    $start = intval(strtotime ($es[$i])/86400);
    $end = intval(strtotime ($ee[$i])/86400);
    What this does is reset the day number to actually follow GMT and readjust the time using the timezone of the server (date("O") returns the difference from GMT). For the second part, since now mktime() actually matches the result of strtotime(), there's no need to have the +1 there.....

    Well..... there you have it guys... That's as far as I can think..... tested on both my servers with good results even if they're in different timezones..

    I'd like it if more ppl could try it out and see if it actually fixes anything.. Especially from different time zones.

    And Ricur, I'd like if you could try it and see if it works well on your server too...
     
  17. ricur

    ricur New Member

    Wow. You have been busy.
    I will take a good look at your fix on Monday when I get back to work - I dont have access to the servers from home :(
    Anyway, thanks a lot and I will get back to you.

    Richard
     
  18. Brian

    Brian EPC Developer Staff Member

    ve9gra, are you a technical writer? That was a great explanation.

    I'll test this out on my server and see what happens. If anyone else wants to try this, please post your results in this thread.
     
  19. ve9gra

    ve9gra Support Team

    Technical writer.. :lol: I wish!! I was getting tired and was just rambling on...

    Thanks for the compliment though ;)

    Hope this will work for everybody.
     
  20. ve9gra

    ve9gra Support Team

    WHOO HOO :D

    My code made it to an official release :lol:

    That made my day!!! B)
     
Thread Status:
Not open for further replies.

Share This Page