473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Question from php cookbook

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
Dec 13 '05 #1
5 1077
"Mike" wrote:
This is a little snippet from the calendar recipe 3.17. I dont understand
what the $yesterday and $day_secs are for? $yesterday = time() - 86400;
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)
$day_secs = mktime(0, 0, 0, $month, $day, $year);


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/

Dec 14 '05 #2
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" <in*****@invalid.invalid> wrote in message
news:BFC511EC.3C6F9%in*****@invalid.invalid...
"Mike" wrote:
This is a little snippet from the calendar recipe 3.17. I dont understand
what the $yesterday and $day_secs are for?

$yesterday = time() - 86400;


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)
$day_secs = mktime(0, 0, 0, $month, $day, $year);


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/

Dec 14 '05 #3
"Mike" wrote:
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???


(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/

Dec 14 '05 #4
Mike wrote:
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.


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 */
}

Dec 14 '05 #5
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

Dec 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ringwraith | last post by:
Hello! I want to ask You the question about the licence of ASPN online Python Cookbook recipes. Under what licence are those recipes. If I want to use in my application some parts of the code...
0
by: Alex Martelli | last post by:
Greetings, fellow Pythonistas! We (Alex Martelli, David Ascher and Anna Martelli Ravenscroft) are in the process of selecting recipes for the Second Edition of the Python Cookbook. Please...
16
by: Chris Wright | last post by:
Hi, 1) I want to iterate over a list "N at a time" sort of like: # Two at a time... won't work, obviously >>> for a, b in : .... print a,b ....
2
by: RickMuller | last post by:
I had a question about the second edition of the Python Cookbook. I own and have thoroughly enjoyed the first edition of the Python Cookbook. How much of the second edition is new? Is this...
0
by: TechBookReport | last post by:
TechBookReport (http://www.techbookreport.com) has just published a review of the Python Cookbook. This is an extract from the full review: We're big fans of cookbooks here at TechBookReport,...
7
by: .net lear | last post by:
if I have an object, say a recipe, which is added to a database, whose responsibility is it to add to the db? The recipe or something else? Let's say I want to delete a recipe? Does the recipe...
0
by: Frederick Noronha \(FN\) | last post by:
---------- Forwarded message ---------- Solutions to Everyday User Interface and Programming Problems O'Reilly Releases "Access Cookbook, Second Edition" Sebastopol, CA--Neither reference book...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
1
by: Marko.Cain.23 | last post by:
Hi, I am following the example of Python cookbook (14.7) about using cookielib in python2.4 cj = cookielib.LWPCookieJar() //.... code to send out the request print...
3
by: Steve Howell | last post by:
George Sakkis produced the following cookbook recipe, which addresses a common problem that comes up on this mailing list: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/521877 I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.