Re: return a formatted difference between two dates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 any better than what's been done. For example, we could divide the year into 10 equal months, but then we would have 36.52428935 days a month OR we could say that each month should have 30 days, but then we would have 12.17476 months per year -- do you see the problem?

Ahh, not to mention that the year is slowly decreasing and the day is increasing. For example, during the Silurian (400 mya), the year was 405 days long and each day was 22 hours in length (average). So the Earth's orbit is speeding and it's rotations are slowing down.

If you wanted to take this "time topic" further, there is of course a time difference between time at the equator and time at the poles, but that requires relativity computations. You see, time is dependent upon both velocity/gravity which are different for the equator as compared to the poles. I actually did a computation like that in college.

So, when you're dealing with real-world numbers, it's hard to come up with something that divides evenly to our liking.

</tedd's rant>

tedd

--
--------------------------------------------------------------------------------
http://sperling.com

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux