-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarConverter.hooks.php
43 lines (38 loc) · 1.44 KB
/
CalendarConverter.hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class CalendarConverterHooks {
public static function onParserFirstCallInit(&$parser) {
$parser->setFunctionHook("lunar2solar", "CalendarConverter::lunar2solar");
$parser->setFunctionHook("solar2lunar", "CalendarConverter::solar2lunar");
return true;
}
public static function onScribuntoExternalLibraries($engine, &$extraLibraries) {
$extraLibraries["mw.ext.calendarconverter"] = "CalendarConverterLua";
return true;
}
public static function timeconvert($parser, $time = "", $zoneName = "", $format = "") {
try {
$errors = array();
if (empty($time)) {
$time = "now";
$errors[] = wfMessage("timeconvert-notime", $time)->parse();
}
if (empty($zoneName)) {
$zoneName = "Etc/GMT";
$errors[] = wfMessage("timeconvert-nozone", $zoneName)->parse();
}
if (empty($format)) {
$format = DateTime::ISO8601;
}
$dt = new DateTime($time);
$dt->setTimezone(new DateTimeZone($zoneName));
$formattedTime = $dt->format($format);
if (!empty($errors)) {
global $wgLang;
return "(" . $wgLang->commaList($errors) . ") " . $formattedTime;
}
return $formattedTime;
} catch (Exception $e) {
return $e->getMessage();
}
}
}