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