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 global $IP;
33 foreach ( glob( "$IP/languages/messages/Messages*.php" ) as $filename ) {
34 $base = basename( $filename );
35 $m = [];
36 if ( !preg_match( '/Messages(.*)\.php$/', $base, $m ) ) {
37 continue;
38 }
39 $code = str_replace( '_', '-', strtolower( $m[1] ) );
40 $this->output( "$code " );
41 $lang = $this->getServiceContainer()->getLanguageFactory()->getLanguage( $code );
42 $prefs = $lang->getDatePreferences();
43 if ( !$prefs ) {
44 $prefs = [ 'default' ];
45 }
46 $this->output( "date: " );
47 foreach ( $prefs as $index => $pref ) {
48 if ( $index > 0 ) {
49 $this->output( ' | ' );
50 }
51 $this->output( $lang->date( $this->ts, false, $pref ) );
52 }
53 $this->output( "\n$code time: " );
54 foreach ( $prefs as $index => $pref ) {
55 if ( $index > 0 ) {
56 $this->output( ' | ' );
57 }
58 $this->output( $lang->time( $this->ts, false, $pref ) );
59 }
60 $this->output( "\n$code both: " );
61 foreach ( $prefs as $index => $pref ) {
62 if ( $index > 0 ) {
63 $this->output( ' | ' );
64 }
65 $this->output( $lang->timeanddate( $this->ts, false, $pref ) );
66 }
67 $this->output( "\n\n" );
68 }
69 }
70}
71
72// @codeCoverageIgnoreStart
73$maintClass = DateFormats::class;
74require_once RUN_MAINTENANCE_IF_MAIN;
75// @codeCoverageIgnoreEnd
if(!defined('MEDIAWIKI')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:90
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