Connecting Tech Pros Worldwide Help | Site Map

Question from php cookbook

Mike
Guest
 
Posts: n/a
#1: Dec 13 '05
This is a little snippet from the calendar recipe 3.17. I dont understand
what the $yesterday and $day_secs are for?

If you need more code I can send it,but if you have the book you can see for
yourself.

$yesterday = time() - 86400;

for ($day = 1; $day <= $totaldays; $day++) {

$day_secs = mktime(0, 0, 0, $month, $day, $year);

if ($day_secs >= $yesterday) {

if ($day_highlight && ($day == $this_day)) {

print sprintf('<td align="center" bgcolor="%s">%d</td>',

$opts['today_color'], $day);



Any help will be appreciated

Thanks

Mike


Philip Ronan
Guest
 
Posts: n/a
#2: Dec 14 '05

re: Question from php cookbook


"Mike" wrote:
[color=blue]
> This is a little snippet from the calendar recipe 3.17. I dont understand
> what the $yesterday and $day_secs are for?[/color]
[color=blue]
> $yesterday = time() - 86400;[/color]

time() is the current time in seconds. If you subtract 86400 from that, you
get the same time on the previous day (Hint: 86400 = 24 x 3600)
[color=blue]
> $day_secs = mktime(0, 0, 0, $month, $day, $year);[/color]

Uhm, you *are* aware that the PHP documentation is all available online,
aren't you? If you visit <http://php.net/mktime> and read what's there, then
it should become fairly obvious what this means.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

Mike
Guest
 
Posts: n/a
#3: Dec 14 '05

re: Question from php cookbook


Philip,(and All)
I understand the documentation well. And yes I read the documentation.And
yes I know those functions in and out. That wasnt my question.Let me
clarify:
I wrote:"I dont understand what the $yesterday and $day_secs are for?"
What do those 2 variables have to do with creating the calendar???
This is why I refered to the book.

Thanks
Mike
"Philip Ronan" <invalid@invalid.invalid> wrote in message
news:BFC511EC.3C6F9%invalid@invalid.invalid...[color=blue]
> "Mike" wrote:
>[color=green]
>> This is a little snippet from the calendar recipe 3.17. I dont understand
>> what the $yesterday and $day_secs are for?[/color]
>[color=green]
>> $yesterday = time() - 86400;[/color]
>
> time() is the current time in seconds. If you subtract 86400 from that,
> you
> get the same time on the previous day (Hint: 86400 = 24 x 3600)
>[color=green]
>> $day_secs = mktime(0, 0, 0, $month, $day, $year);[/color]
>
> Uhm, you *are* aware that the PHP documentation is all available online,
> aren't you? If you visit <http://php.net/mktime> and read what's there,
> then
> it should become fairly obvious what this means.
>
> --
> phil [dot] ronan @ virgin [dot] net
> http://vzone.virgin.net/phil.ronan/
>[/color]


Philip Ronan
Guest
 
Posts: n/a
#4: Dec 14 '05

re: Question from php cookbook


"Mike" wrote:
[color=blue]
> I understand the documentation well. And yes I read the documentation.And
> yes I know those functions in and out. That wasnt my question.Let me
> clarify:
> I wrote:"I dont understand what the $yesterday and $day_secs are for?"
> What do those 2 variables have to do with creating the calendar???[/color]

(Please don't top-post)

Presumably the calendar writes dates in a different style if they are in the
past. So if ($day_secs >= $yesterday), that means the date currently being
draw is either today's date or some future date. I expect if you look
further down in teh code you'll see that these dates are displayed in bold
type, for example.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

Chung Leong
Guest
 
Posts: n/a
#5: Dec 14 '05

re: Question from php cookbook


Mike wrote:[color=blue]
> I wrote:"I dont understand what the $yesterday and $day_secs are for?"
> What do those 2 variables have to do with creating the calendar???
> This is why I refered to the book.[/color]

The conversions to Unix timestamp is done presumbly so to make it
easier to determine whether the days shown are in the past or in the
future. Instead of comparing three numbers--the year, the month, and
the day--you compare just one. The strategy just ends up complicating
the code. It'd easy enough to do this:

if($year < $today_year || $month < $today_month || $day < $today_day) {
/* days in the past */
}
else if($year > $today_year || $month > $today_month || $day >
$today_day) {
/* days in the future */
}
else {
/* today */
}

Ian B
Guest
 
Posts: n/a
#6: Dec 14 '05

re: Question from php cookbook


Mike,

Just been and had a look.

Answer: It doesn't do anything.

Take out the

if ($day_secs >= $yesterday) {

and the else clause, and it still works the same

Ian

Closed Thread