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:
[code]
[/code]
[code]
[/code]
Now make me proud and post your improvements.
Happy Hacking!!
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?
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. 🙂
strtotime() is using [url=http://www.gnu.org/software/tar/manual/html_node/tar_119.html]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).
$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 kcpug.org maintenance.
[code]
= $title ?>
“>= date("F jS g:ia", $start_dttm) ?> —
“>= date("g:ia Y", $end_dttm) ?>, at
= $location ?>
if ($description != "") { ?>
} if ($tag_list != null && count($tag_list) > 0) {
?>
foreach ($tag_list as $tag) { ?>
[/code]
I did look into using the Zend framework for the date/time manipulation, but I had some trouble with the Zend library and the [url=http://framework.zend.com/apidoc/core/]documentation[/url] wasn’t much help. For one, the getMonth() routine returns the next month instead of the current month (v 1.0.0 and v 1.0.2) and even then you still have to use toString() to get just the month. I may have missed it, but I didn’t see any way to get all the formatting options I needed. I went back to the classic date() routine because it’s simple, does everything I needed and the [url=http://us3.php.net/manual/en/function.date.php]documentation[/url] is very concise. In particular, this time it really helped to have O for the timezone offset and S to help with 21st, 20th, etc.