Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -4820,4 +4820,13 @@ |
4821 | 4821 | 'api-error-uploaddisabled' => 'Uploading is disabled on this wiki.', |
4822 | 4822 | 'api-error-verification-error' => 'This file might be corrupt, or have the wrong extension.', |
4823 | 4823 | |
| 4824 | +# Durations |
| 4825 | +'duration-seconds' => '$1 {{PLURAL:$1|second|seconds}}', |
| 4826 | +'duration-minutes' => '$1 {{PLURAL:$1|minute|minutes}}', |
| 4827 | +'duration-hours' => '$1 {{PLURAL:$1|hour|hours}}', |
| 4828 | +'duration-days' => '$1 {{PLURAL:$1|day|days}}', |
| 4829 | +'duration-weeks' => '$1 {{PLURAL:$1|week|weeks}}', |
| 4830 | +'duration-years' => '$1 {{PLURAL:$1|year|years}}', |
| 4831 | +'duration-centuries' => '$1 {{PLURAL:$1|century|centuries}}', |
| 4832 | + |
4824 | 4833 | ); |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -1910,6 +1910,44 @@ |
1911 | 1911 | } |
1912 | 1912 | |
1913 | 1913 | /** |
| 1914 | + * Takes a number of seconds and turns it into a text using values such as hours and minutes. |
| 1915 | + * |
| 1916 | + * @since 1.20 |
| 1917 | + * |
| 1918 | + * @param integer $seconds The amount of seconds. |
| 1919 | + * @param array $chosenIntervals The intervals to enable. |
| 1920 | + * |
| 1921 | + * @return string |
| 1922 | + */ |
| 1923 | + public function duration( $seconds, array $chosenIntervals = array( 'years', 'days', 'hours', 'minutes', 'seconds' ) ) { |
| 1924 | + $intervals = array( |
| 1925 | + 'years' => 31557600, // 86400 * 365.25 |
| 1926 | + 'weeks' => 604800, |
| 1927 | + 'days' => 86400, |
| 1928 | + 'hours' => 3600, |
| 1929 | + 'minutes' => 60, |
| 1930 | + 'seconds' => 1, |
| 1931 | + ); |
| 1932 | + |
| 1933 | + if ( !empty( $chosenIntervals ) ) { |
| 1934 | + $intervals = array_intersect_key( $intervals, array_flip( $chosenIntervals ) ); |
| 1935 | + } |
| 1936 | + |
| 1937 | + $segments = array(); |
| 1938 | + |
| 1939 | + foreach ( $intervals as $name => $length ) { |
| 1940 | + $value = floor( $seconds / $length ); |
| 1941 | + |
| 1942 | + if ( $value > 0 || ( $name == 'seconds' && empty( $segments ) ) ) { |
| 1943 | + $seconds -= $value * $length; |
| 1944 | + $segments[] = wfMsgExt( 'duration-' . $name, 'parsemag', $value ); |
| 1945 | + } |
| 1946 | + } |
| 1947 | + |
| 1948 | + return $this->listToText( $segments ); |
| 1949 | + } |
| 1950 | + |
| 1951 | + /** |
1914 | 1952 | * Internal helper function for userDate(), userTime() and userTimeAndDate() |
1915 | 1953 | * |
1916 | 1954 | * @param $type String: can be 'date', 'time' or 'both' |