[sf-perl] That's not Perl!
shift8
shift8 at digitrash.com
Wed Jan 18 15:33:43 PST 2006
well, at least you don't have to manually reset array indexes any more,
i guess :)
On Tue, 2006-01-17 at 07:49 -0800, Rich Morin wrote:
> I recently started using PHP for assorted odd jobs (see
> http://www.cfcl.com/~rdm/weblog/archives/000910.html). I
> can't say that I like it as well as either Perl or Ruby
> (a bit too quirky), but it has its uses.
>
> Here's some code I hacked up for the Beer & Scripting SIG
> page (http://www.cfcl.com/rdm/bass/), so that I wouldn't
> have to keep editing the date line, making lame editing
> mistakes, etc. Comments welcome...
>
> -r
>
>
> % cat index.php
> <?
> include '__intro';
>
> dt(dse(4, 3), '8:00 pm'); # 4th Wednesday
>
> include '_Wild_Pepper';
> ?>
>
> % cat __intro
> ...
> # dt - print date and time of event
> #
> function dt($date, $time) {
>
> print " <tr><td> </td></tr>\n\n"
> . " <tr valign=top>\n"
> . " <td width=100>Date:</td>\n"
> . " <td>$date</td>\n"
> . " </tr>\n"
> . " <tr><td> </td></tr>\n\n"
> . " <tr valign=top>\n"
> . " <td width=100>Time:</td>\n"
> . " <td>$time</td>\n"
> . " </tr>\n"
> ;
> }
>
> # dse - get date string for the event
> #
> # $wn - week number (1-5)
> # $dn - day number (0-6)
> #
> function dse($wn, $dn) {
>
> # Get the current date.
>
> list(,,,$mday,$mon,$year,,,) = localtime();
>
> $mon++; # Use PHP's month numbering.
>
> # Second iteration handles "happened already".
>
> for ($try=1; $try<=2; $try++) {
>
> # Get the day of the week for the 1st ($dw1).
>
> $fom = mktime(0, 0, 0, $mon, 1, $year);
>
> list(,,,,,,$dw1,,) = localtime($fom);
>
> # Get the date for the event.
>
> $doe = ($dn+1) + 7 * ($wn-1) - $dw1;
>
> if ($dw1 > $dn) $doe += 7;
>
> if ($doe >= $mday) { # Hasn't happened yet.
>
> # Return a formatted date string.
>
> $toe = mktime(0, 0, 0, $mon, $doe, $year);
> $date = date('l, F j, Y', $toe);
> return $date;
> }
>
> # Whoops; shift to next month and/or year!
>
> $mday = 1;
>
>
> if (++$mon == 13) { $mon=1; $year++; }
> }
>
> return "Yow! Couldn't find a reasonable date.";
> }
> ...
--
-paniq/#dataflow- [Global Notice] Hi all. 23 is the new 42.
More information about the SanFrancisco-pm
mailing list