Re: [PHP] return a formatted difference between two dates

2006-04-18 Thread Richard Lynch
On Mon, April 17, 2006 8:55 pm, tedd wrote:
 As I understand it, it won't make any difference if you use
 strtotime()

 See: http://www.weberdev.com/strtotime

Errr, yeah.

Only problem is, he needs non-existent function that might be named
timetostr which takes an elapsed time and turns it into a string
like 1 week and 3 days

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] return a formatted difference between two dates

2006-04-17 Thread Richard Lynch
On Fri, April 14, 2006 1:24 pm, jonathan wrote:
 is there a function to take a second count and return it as a
 formatted difference?

 like a date_diff('H hours i',6133)

 that uses date()'s formatting.

I think he means something not unlike:

function human_time($seconds){
  $result =  and  . ($seconds % 60) .  seconds;
  $seconds = floor($seconds/60);

  $result = ($seconds % 60)  minutes $result;
  $seconds = floor($seconds/60);

  $result = ($seconds % 24)  hours $result;
  $seconds = floor($seconds/24);

  $result = ($seconds % 30)  days $result;
  $seconds = floor($seconds/365);

  $result = ($seconds % 12)  months $result;
  $seconds = floor($seconds/12);

  $result = $seconds years $result;

  return $result;
}

That, however, is probably not precisely what he wants, as it's WAY
off in the months/years thing... :-)

This WOULD be a nice function to have built-in, but, unfortunately, a
big ol' can of worms is opened up for the months and at 365+ days --
namely that without a start-time, you can't tell how many years have
passed because you won't know if it was a leap year or not...

One has to wonder WHAT our ancestors where thinking when they decided
to make months have different lengths days and this whole leap year
thing...  I mean, the cure is worse than the disease, no?  Don't even
get me started on daylight savings and 15 minute time-zones. :-)

So maybe it could take an optional start-time and assuming dates in
the Unix-time range of 1/1/1970 to MAX_INT do a credible job of it.

Then you'd need directives sort of like date() has for whether to
print out, say, XX seconds if the number is evenly divisible by 60,
or whether to use 0, space, or no prefix for numbers  10, plus...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] return a formatted difference between two dates

2006-04-17 Thread tedd

At 6:17 PM -0500 4/17/06, Richard Lynch wrote:

On Fri, April 14, 2006 1:24 pm, jonathan wrote:

 is there a function to take a second count and return it as a

  formatted difference?



That, however, is probably not precisely what he wants, as it's WAY
off in the months/years thing... :-)

This WOULD be a nice function to have built-in, but, unfortunately, a
big ol' can of worms is opened up for the months and at 365+ days --
namely that without a start-time, you can't tell how many years have
passed because you won't know if it was a leap year or not...


As I understand it, it won't make any difference if you use strtotime()

See: http://www.weberdev.com/strtotime

That's a neat function because it's usually smarter (with respect to 
date) than the person who is using it. For example, you can add 60 
days to Jan 1 and it will give you March 1 unless it's a leap year 
where it gives you February 29 -- neat huh? (I hope my math is right).



One has to wonder WHAT our ancestors where thinking when they decided
to make months have different lengths days and this whole leap year
thing...  I mean, the cure is worse than the disease, no?  Don't even
get me started on daylight savings and 15 minute time-zones. :-)


Oh, now you got me started. :-)

NOTE: Nothing below is PHP related -- so stop reading NOW -- unless 
you have the time, or want to learn about it.


tedd's rant

You wonder about our ancestors?

Our ancestors were pretty smart with respect to time. As far back as 
15,000 years ago, they were detecting and predicting the Equinox 
(i.e., Stonehenge). 10,000 years ago, they computed the age of the 
universe (get this) to be 15 billion years old (way to go Buddhist 
monks). 5000 years ago, they detected the Precession of the Earth, 
which takes 26,000 years to revolve (way to go American Indian). 4000 
years ago, an Egyptian figured the circumstance of the Earth within 
less than a 5% error and his culture built Pyramids that were square 
within 1/4 inch (sorry not time related). Back to point, the Incas 
had calendars that accurately predicted solar and lunar eclipses far 
into the future (some say they still work).


As for the Western calendar, I agree it's has been a bit hard to 
compute -- but there are reasons why. Our ancestors were faced with 
something that isn't easily resolved as one becomes more and more 
accurate measuring time passing -- like the day of the week for 
example.


First of all, we ought to stop at year 1583. Prior to that, the day 
of the week cannot be calculated (it can -- but the algorithm is very 
complex).


In order to understand why we can't calculate the week day, we need 
to look at the calendar history.


Prior to Julius Caesar (100-44 B.C) ruling Rome the Roman year was 
354 days long. When Julius came to power (49-45 B.C.), one of his 
first challenge was to appease the farmers who complained big time 
because according to their calendar it was spring time and time to 
sow/plant but actually it was mid winter.


Julius hired Sosigenes of Alexandria (a mathematician) to figure out 
what went wrong. A tub of wine and a couple of girls later, Sosigenes 
suggested that the length of the year was wrong. It should have been 
365.25 days. The extra .25 day after four years became the extra day 
added in February.


Julius made a mess of 46 B.C. by adding a couple of months (he made 
money on taxes --BIG time) making 46 B.C. 445 days long!


Of course, Sosigenes, not having a calculator, didn't realize that a 
solar year is really 365.2428935 -- his calculations were too large 
by 10 minutes and some seconds for a year (not bad for manual 
computation back in 46 B.C.!)


This error after 1600 years, added up to about 11 days. This was 
detected by astronomers who noticed that the vernal equinox (when 
light and dark periods are equal in length) occurring on March 21 was 
becoming earlier and earlier and in 1582 it was on March 10.


Christopher Clarius, an astronomer, went to Pope Gregory XIII and 
addressed the concern. After seeing all the calculations for 7 
months, pope Gregory knocked off 11 days on October 4, 1582.


The next day, he decreed to be October 15 (so October 5-14 in the 
year 1582 didn't exist), but to not upset the Jews with their 
Sabbath, the day of the week was NOT changed. To avoid this error 
again after 1500 years, Pope Gregory, decreed that every 4 years a 
day will be added. However, on a turn of the century, it will only be 
added if it's divisible by 400. Hence, although year 2000 was a leap 
year -- year 1900 was not. SO, the proper test for a leap year:


A leap year is IF the year is evenly divisible by 4 AND is not the 
turn of the century. IF it is, it must be evenly divisible by 400 -- 
neat huh?


Did you know that this year (2006) we even added a leap second -- you 
don't want to know the computations for that.


It's difficult for anyone to do anything with 365.2428935(more to 
follow) days a year.


So, even now, we couldn't do 

RE: [PHP] return a formatted difference between two dates

2006-04-14 Thread Jay Blanchard
[snip]
is there a function to take a second count and return it as a  
formatted difference?

like a date_diff('H hours i',6133)

that uses date()'s formatting.
[/snip]

http://www.php.net/mktime

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php