return $this->sprintfDate( $df, $ts );
}
+ /**
+ * Takes a number of seconds and turns it into a text using values such as hours and minutes.
+ *
+ * @since 1.20
+ *
+ * @param integer $seconds The amount of seconds.
+ * @param array $chosenIntervals The intervals to enable.
+ *
+ * @return string
+ */
+ public function duration( $seconds, array $chosenIntervals = array( 'years', 'days', 'hours', 'minutes', 'seconds' ) ) {
+ $intervals = array(
+ 'years' => 31557600, // 86400 * 365.25
+ 'weeks' => 604800,
+ 'days' => 86400,
+ 'hours' => 3600,
+ 'minutes' => 60,
+ 'seconds' => 1,
+ );
+
+ if ( !empty( $chosenIntervals ) ) {
+ $intervals = array_intersect_key( $intervals, array_flip( $chosenIntervals ) );
+ }
+
+ $segments = array();
+
+ foreach ( $intervals as $name => $length ) {
+ $value = floor( $seconds / $length );
+
+ if ( $value > 0 || ( $name == 'seconds' && empty( $segments ) ) ) {
+ $seconds -= $value * $length;
+ $segments[] = wfMsgExt( 'duration-' . $name, 'parsemag', $value );
+ }
+ }
+
+ return $this->listToText( $segments );
+ }
+
/**
* Internal helper function for userDate(), userTime() and userTimeAndDate()
*
'api-error-uploaddisabled' => 'Uploading is disabled on this wiki.',
'api-error-verification-error' => 'This file might be corrupt, or have the wrong extension.',
+# Durations
+'duration-seconds' => '$1 {{PLURAL:$1|second|seconds}}',
+'duration-minutes' => '$1 {{PLURAL:$1|minute|minutes}}',
+'duration-hours' => '$1 {{PLURAL:$1|hour|hours}}',
+'duration-days' => '$1 {{PLURAL:$1|day|days}}',
+'duration-weeks' => '$1 {{PLURAL:$1|week|weeks}}',
+'duration-years' => '$1 {{PLURAL:$1|year|years}}',
+'duration-centuries' => '$1 {{PLURAL:$1|century|centuries}}',
+
);