Do correct average year length arithmetic.
authorLiangent <liangent@gmail.com>
Sat, 29 Dec 2012 14:07:21 +0000 (22:07 +0800)
committerLiangent <liangent@gmail.com>
Sat, 29 Dec 2012 14:15:36 +0000 (22:15 +0800)
We have ( 24 * 3 + 25 ) leap years in total every 400 years in the
Gregorian calendar.

Change-Id: I2ad9036473afa914ecf8ddcf99ce27e316178f76

languages/Language.php
tests/phpunit/languages/LanguageTest.php

index 80baf06..c050ad2 100644 (file)
@@ -160,10 +160,10 @@ class Language {
         * @var array
         */
        static public $durationIntervals = array(
-               'millennia' => 31557600000,
-               'centuries' => 3155760000,
-               'decades' => 315576000,
-               'years' => 31557600, // 86400 * 365.25
+               'millennia' => 31556952000,
+               'centuries' => 3155695200,
+               'decades' => 315569520,
+               'years' => 31556952, // 86400 * ( 365 + ( 24 * 3 + 25 ) / 400 )
                'weeks' => 604800,
                'days' => 86400,
                'hours' => 3600,
index 94ccfd0..f75f444 100644 (file)
@@ -847,35 +847,36 @@ class LanguageTest extends LanguageClassesTestCase {
                                '2 days',
                        ),
                        array(
-                               365.25 * 86400, // 365.25 * 86400 = 31557600
+                               // ( 365 + ( 24 * 3 + 25 ) / 400 ) * 86400 = 31556952
+                               ( 365 + ( 24 * 3 + 25 ) / 400.0 ) * 86400,
                                '1 year',
                        ),
                        array(
-                               2 * 31557600,
+                               2 * 31556952,
                                '2 years',
                        ),
                        array(
-                               10 * 31557600,
+                               10 * 31556952,
                                '1 decade',
                        ),
                        array(
-                               20 * 31557600,
+                               20 * 31556952,
                                '2 decades',
                        ),
                        array(
-                               100 * 31557600,
+                               100 * 31556952,
                                '1 century',
                        ),
                        array(
-                               200 * 31557600,
+                               200 * 31556952,
                                '2 centuries',
                        ),
                        array(
-                               1000 * 31557600,
+                               1000 * 31556952,
                                '1 millennium',
                        ),
                        array(
-                               2000 * 31557600,
+                               2000 * 31556952,
                                '2 millennia',
                        ),
                        array(
@@ -887,11 +888,11 @@ class LanguageTest extends LanguageClassesTestCase {
                                '1 hour and 1 second'
                        ),
                        array(
-                               31557600 + 2 * 86400 + 9000,
+                               31556952 + 2 * 86400 + 9000,
                                '1 year, 2 days, 2 hours and 30 minutes'
                        ),
                        array(
-                               42 * 1000 * 31557600 + 42,
+                               42 * 1000 * 31556952 + 42,
                                '42 millennia and 42 seconds'
                        ),
                        array(
@@ -910,7 +911,7 @@ class LanguageTest extends LanguageClassesTestCase {
                                array( 'seconds' ),
                        ),
                        array(
-                               31557600 + 2 * 86400 + 9000,
+                               31556952 + 2 * 86400 + 9000,
                                '1 year, 2 days and 150 minutes',
                                array( 'years', 'days', 'minutes' ),
                        ),
@@ -920,7 +921,7 @@ class LanguageTest extends LanguageClassesTestCase {
                                array( 'years', 'days' ),
                        ),
                        array(
-                               31557600 + 2 * 86400 + 9000,
+                               31556952 + 2 * 86400 + 9000,
                                '1 year, 2 days and 150 minutes',
                                array( 'minutes', 'days', 'years' ),
                        ),