Scripting Fun :: Automatic Next Meeting Date Calculation

OK. I have finally taken the time to hack together a block for automatically stating the Next PHP Meeting date. What I needed was a way to get the third Saturday of the current month unless it has already past. Then it would get the third Saturday of next month.

If you want to have some fun with a nice academic exercise, read the article and start hacking!

The “algorithm” I hacked together was:

Now make me proud and post your improvements.

Happy Hacking!!

  • ThatGuy
    Re: Scripting Fun :: Automatic Next Meeting Date Calculation
    What? No Zend Framework? After the discussion at the meeting last time, or was it the time before? I figured this would be showing that off.
    • Daniel Holmes
      Re: Scripting Fun :: Automatic Next Meeting Date Calculation

      Er…yeah. I’m using a xoops custom php block and wanted to keep it to just pure php. Any takers on using ZF for fun?

  • Tom Eagle
    Re: Scripting Fun :: Automatic Next Meeting Date Calculation
    Adding year round over:

    < ?php $t=getdate(); $today = mktime(0,0,0,$t['mon'],$t['mday'],$t['year']); $this_month_start = mktime(0,0,0,$t['mon'],1,$t['year']); if ( $t['mon'] < 12 ) { $next_month_start = mktime(0,0,0,$t['mon']+1,1,$t['year']); } else { $next_month_start = mktime(0,0,0,1,1,$t['year']+1); } $this_month_date = strtotime("Third Saturday",$this_month_start); $next_month_date = strtotime("Third Saturday",$next_month_start); if($today <= $this_month_date) { $event_date = $this_month_date; } else { $event_date = $next_month_date; } print "Saturday, ".date('F dS, Y',$event_date)." 2:30pm"; ?>

    • Daniel Holmes
      Re: Scripting Fun :: Automatic Next Meeting Date Calculation
      I shouldn’t have to worry about any carry over, because mktime converts my overflows (month 13 for example) into the appropriate time.

      What I do find odd, is that both September and December this year start on Saturday the 1st. Now, that’s no so strange, but what is is that my little algorithm works on my Unix hosted website, but in XAMPP in windows it’s off a weekend.

      It the month starts on a Saturday, I need to subtract a second from midnight. Naturally, mktime returns the last second of the last day of the previous month…and then the calculation is right.

      $this_month_start = mktime(0,0,-1,$t[‘mon’],1,$t[‘year’]);

      errr…maybe it’s just to late in the evening to be playing around. :-)

      • Eric Poe
        Re: Scripting Fun :: Automatic Next Meeting Date Calculation
        November is off a day (shows the 3rd Sat as 11/16 rather than 11/17).

        strtotime() is using [url=]relative time[/url]. Line 6 of the above link says: [quote]When a relative item causes the resulting date to cross a boundary where the clocks were adjusted, typically for daylight saving time, the resulting date and time are adjusted accordingly.[/quote]
        Yet, the last line says: [quote]Also, take care when manipulating dates around clock changes such as daylight saving leaps. In a few cases these have added or subtracted as much as 24 hours from the clock, so it is often wise to adopt universal time by setting the TZ environment variable to ‘UTC0’ before embarking on calendrical calculations.[/quote]
        The date error looks like it might have something to do with Daylight Saving Time ending in November (new 2007 DST rules).

        • Daniel Holmes
          Re: Scripting Fun :: Automatic Next Meeting Date Calculation
          Thanks Eric. I’ve fixed it this month with a single line that guarantees success:

          $event_date = strtotime(“2007-11-17 14:30:00”);

          I’m a little nervous of what setting the TZ environment and what it would do to Xoops. 😉

          Besides–this fix conformes to my “just barely enough” attitude with maintenance.

  • Tim
    Re: Scripting Fun :: Automatic Next Meeting Date Calculation
    I thought it would be a good idea to add some Microformats to our site for the monthly meetings. Since we now have code to calculate the meeting date, I whipped up a simple routine for generating the event as an hCalendar. I used the [url=]hCalendar creator[/url] as a basis for the format.

    [code]< ?php define("HOUR", 3600); // 1 hour offset in seconds // Set the start date/time to 2:30 pm (14.5 in 24 hr clock) on the $event_date $start_dttm = $event_date + (14.5 * HOUR); // Generate the hCalendar printHCal("KCPUG Meeting", "", "Daily Dose", $start_dttm, $start_dttm + (2 * HOUR), "PHP General Discussion Forum", array("PHP")); // Print HCalendar markup for an event // This routine prepends the month to the name of the event // The format of the link label assumes that the event does not last multiple days function printHCal($name, $url, $location, $start_dttm, $end_dttm, $description="", $tag_list=null, $hide=true) { $title = date("F", $start_dttm)." ".$name; ?>