iliaa                                    Wed, 05 Jan 2011 04:13:23 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=307103

Log:
Optimize unix timestamp to date-string conversion for very high year values

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/date/lib/unixtime2tm.c
    U   php/php-src/trunk/ext/date/lib/unixtime2tm.c

Modified: php/php-src/branches/PHP_5_3/ext/date/lib/unixtime2tm.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/lib/unixtime2tm.c     2011-01-05 
04:04:02 UTC (rev 307102)
+++ php/php-src/branches/PHP_5_3/ext/date/lib/unixtime2tm.c     2011-01-05 
04:13:23 UTC (rev 307103)
@@ -55,6 +55,12 @@

        if (ts >= 0) {
                tmp_days = days + 1;
+
+               if (tmp_days >= DAYS_PER_LYEAR_PERIOD || tmp_days <= 
-DAYS_PER_LYEAR_PERIOD) {
+                       cur_year += YEARS_PER_LYEAR_PERIOD * (tmp_days / 
DAYS_PER_LYEAR_PERIOD);
+                       tmp_days -= DAYS_PER_LYEAR_PERIOD * (tmp_days / 
DAYS_PER_LYEAR_PERIOD);
+               }
+
                while (tmp_days >= DAYS_PER_LYEAR) {
                        cur_year++;
                        if (timelib_is_leap(cur_year)) {

Modified: php/php-src/trunk/ext/date/lib/unixtime2tm.c
===================================================================
--- php/php-src/trunk/ext/date/lib/unixtime2tm.c        2011-01-05 04:04:02 UTC 
(rev 307102)
+++ php/php-src/trunk/ext/date/lib/unixtime2tm.c        2011-01-05 04:13:23 UTC 
(rev 307103)
@@ -55,6 +55,12 @@

        if (ts >= 0) {
                tmp_days = days + 1;
+
+               if (tmp_days >= DAYS_PER_LYEAR_PERIOD || tmp_days <= 
-DAYS_PER_LYEAR_PERIOD) {
+                       cur_year += YEARS_PER_LYEAR_PERIOD * (tmp_days / 
DAYS_PER_LYEAR_PERIOD);
+                       tmp_days -= DAYS_PER_LYEAR_PERIOD * (tmp_days / 
DAYS_PER_LYEAR_PERIOD);
+               }
+
                while (tmp_days >= DAYS_PER_LYEAR) {
                        cur_year++;
                        if (timelib_is_leap(cur_year)) {

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

Reply via email to