Hi Edward,
thanks for replying!
On Jul 7, 2005, at 10:44 PM, Edward Vermillion wrote:
One problem is that there's no accounting for leap years, but I
don't know if that's gonna cause you any problems or not.
Course it have, when we multiply the year offset by 31557376.189582
we are using the total seconds of an year, we normally don't use
cause from 4 to 4 years we add a day (Pope Gregory XIII, Bregorian
Calendar decreted in 1 March of 1582). So using the extra seconds we
are, in theory adding that one more day.
The other thing I noticed is that the 'match' bit you have in there
as "year[0]" should be "$year[1]". $year[0] will return the
whole string that was matched, not just the actual match part
between the parenthesis. Although I think you would get the
same thing with your set up. And you will need to put a delimiter
in the regex part, right now it looks like it's going to treat
the parenthesis as the delimiter which will make the return for the
match not work. ie:
" preg_match('([0-2][0-9][0-9][0-9])', $input, $year); " -- $year
will be empty...
should be " preg_match('/([0-2][0-9][0-9][0-9])/', $input, $year); "
or " preg_match('/([0-1][0-9][0-7][0-9])/', $input, $year); " -- to
restrict it to 1970 or before....
but it could also be " preg_match('/([\d]{4})/', $input, $year); "
-- if you don't really need to validate the the year
There's other problems that I can see with the math logic in the
return, like why 1976?, why would you want to generate
a positive number that will conflict with dates before 1970? but it
could just be that I'm not thinking the math all the way
through, and what you eventually want to do with the dates once you
store them.
Why 1976, because it's a leap year and is between valid range for
windows systems.
Let me try to explain the rest.
First I get the input year... which by the way is working fine here...
preg_match('([0-2][0-9][0-9][0-9])', $input, $year);
Second I replace by a valid year between 1970 and 2025....
preg_replace('([0-2][0-9][0-9][0-9])', '1976', $input);
After calculate the date difference from 1976 to given date... let's
say 01/01/1936.....
So we have... -40... and now multiply by number of seconds in a year
(31557376.189582) before Gregorian Calendar, and we will get:
-1262295047.583
Now we calculate the timestamp from 01/01/1976: 189313200
Now we have the final equation: 189313200 + (-1262295047.583).
The result is a negative timestamp: -1072981847.583 Which if we put
in a date function, we would get: 01/01/1936.
Magic! We have negative timestamp in windows!
Was it clear, or I am dreaming awake? hehehehhe
Best Regards,
Bruno B B Magalhaes
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php