MediaWiki master
date-formats.php
Go to the documentation of this file.
1<?php
11
12// @codeCoverageIgnoreStart
13require_once __DIR__ . '/../Maintenance.php';
14// @codeCoverageIgnoreEnd
15
21class DateFormats extends Maintenance {
22
24 private $ts = '20010115123456';
25
26 public function __construct() {
27 parent::__construct();
28 $this->addDescription( 'Test various language time and date functions' );
29 }
30
31 public function execute() {
32 foreach ( glob( MW_INSTALL_PATH . '/languages/messages/Messages*.php' ) as $filename ) {
33 $base = basename( $filename );
34 $m = [];
35 if ( !preg_match( '/Messages(.*)\.php$/', $base, $m ) ) {
36 continue;
37 }
38 $code = str_replace( '_', '-', strtolower( $m[1] ) );
39 $this->output( "$code " );
40 $lang = $this->getServiceContainer()->getLanguageFactory()->getLanguage( $code );
41 $prefs = $lang->getDatePreferences();
42 if ( !$prefs ) {
43 $prefs = [ 'default' ];
44 }
45 $this->output( "date: " );
46 foreach ( $prefs as $index => $pref ) {
47 if ( $index > 0 ) {
48 $this->output( ' | ' );
49 }
50 $this->output( $lang->date( $this->ts, false, $pref ) );
51 }
52 $this->output( "\n$code time: " );
53 foreach ( $prefs as $index => $pref ) {
54 if ( $index > 0 ) {
55 $this->output( ' | ' );
56 }
57 $this->output( $lang->time( $this->ts, false, $pref ) );
58 }
59 $this->output( "\n$code both: " );
60 foreach ( $prefs as $index => $pref ) {
61 if ( $index > 0 ) {
62 $this->output( ' | ' );
63 }
64 $this->output( $lang->timeanddate( $this->ts, false, $pref ) );
65 }
66 $this->output( "\n\n" );
67 }
68 }
69}
70
71// @codeCoverageIgnoreStart
72$maintClass = DateFormats::class;
73require_once RUN_MAINTENANCE_IF_MAIN;
74// @codeCoverageIgnoreEnd
Maintenance script that tests various language time and date functions.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
$maintClass