Number of seconds that passed?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I usually do something like this:

Code: Select all

<?php
/** 
 * Lets get the time... in seconds... because for some reason 
 * PHP needs to do everything in seconds from January 1, 1970
 */
$timestamp = time();

// Now check to see if now less reset time is greater than one day 
// (in seconds, thanks again to PHP's wonderful handling of dates
if ($timestamp - $profitreset->reset >= 86400 )
{
  //
}
?>
Comments don't scare me so much, so I use them to allow me to come back and easily distinguish what I was doing. Even though

Code: Select all

<?php
$one_day = 60 * 60 * 24;
?>
Seems self explanatory, there is nothing really saying that the units you are using is seconds. It could be 24 parcels per worker, 60 workers per station, 60 stations per region and one days output is 86400 parcels in a region. I know that's a stretch, but a simple comment speaks more to me that making an assumption as to what was intended simply by looking at the values used in a math routine (which to me still does not make sense to have PHP do).
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

yes I suppose that is true... I am not afraid of comments either, but that for some reason always made sense to me. My code is heavily commented anyway.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I feel you. I tend to let things that make sense permeate my code. But simple math just makes sense to me.

I hope I don't come off as argumentative. That is not my intent. I am merely trying to share my opinion on the use of numeric values that I feel should not necessarily be calculated by PHP since most often I have a calculator (or pen and paper) handy to do it.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I hope I don't come off as argumentative.
not at all... no love lost :wink:
Post Reply