MediaWiki master
date-formats.php
Go to the documentation of this file.
1<?php
24// @codeCoverageIgnoreStart
25require_once __DIR__ . '/../Maintenance.php';
26// @codeCoverageIgnoreEnd
27
33class DateFormats extends Maintenance {
34
36 private $ts = '20010115123456';
37
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( 'Test various language time and date functions' );
41 }
42
43 public function execute() {
44 global $IP;
45 foreach ( glob( "$IP/languages/messages/Messages*.php" ) as $filename ) {
46 $base = basename( $filename );
47 $m = [];
48 if ( !preg_match( '/Messages(.*)\.php$/', $base, $m ) ) {
49 continue;
50 }
51 $code = str_replace( '_', '-', strtolower( $m[1] ) );
52 $this->output( "$code " );
53 $lang = $this->getServiceContainer()->getLanguageFactory()->getLanguage( $code );
54 $prefs = $lang->getDatePreferences();
55 if ( !$prefs ) {
56 $prefs = [ 'default' ];
57 }
58 $this->output( "date: " );
59 foreach ( $prefs as $index => $pref ) {
60 if ( $index > 0 ) {
61 $this->output( ' | ' );
62 }
63 $this->output( $lang->date( $this->ts, false, $pref ) );
64 }
65 $this->output( "\n$code time: " );
66 foreach ( $prefs as $index => $pref ) {
67 if ( $index > 0 ) {
68 $this->output( ' | ' );
69 }
70 $this->output( $lang->time( $this->ts, false, $pref ) );
71 }
72 $this->output( "\n$code both: " );
73 foreach ( $prefs as $index => $pref ) {
74 if ( $index > 0 ) {
75 $this->output( ' | ' );
76 }
77 $this->output( $lang->timeanddate( $this->ts, false, $pref ) );
78 }
79 $this->output( "\n\n" );
80 }
81 }
82}
83
84// @codeCoverageIgnoreStart
85$maintClass = DateFormats::class;
86require_once RUN_MAINTENANCE_IF_MAIN;
87// @codeCoverageIgnoreEnd
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:104
Maintenance script that tests various language time and date functions.
$maintClass