Debian Codegraph @

maintenance/language/date-formats.php

raw symbols SCIP
1 <?php
2 /**
3 * Test various language time and date functions
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup MaintenanceLanguage
22 */
23
24 // @codeCoverageIgnoreStart
25 require_once __DIR__ . '/../Maintenance.php';
26 // @codeCoverageIgnoreEnd
27
28 /**
29 * Maintenance script that tests various language time and date functions.
30 *
31 * @ingroup MaintenanceLanguage
32 */
33 class DateFormats extends Maintenance {
34
35 /** @var string */
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;
86 require_once RUN_MAINTENANCE_IF_MAIN;
87 // @codeCoverageIgnoreEnd