| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if (!defined('WPINC')) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Ajax communication |
| 10 |
*/ |
| 11 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound |
| 12 |
class EADateTime |
| 13 |
{ |
| 14 |
|
| 15 |
/** |
| 16 |
* @param string $format |
| 17 |
* @return string |
| 18 |
*/ |
| 19 |
function convert_to_moment_format($format) |
| 20 |
{ |
| 21 |
$escaped = array(); |
| 22 |
$local = $format; |
| 23 |
|
| 24 |
// replace escape string \ with [] around |
| 25 |
while (true) { |
| 26 |
$index = strpos($local,'\\'); |
| 27 |
|
| 28 |
if ($index === false) break; |
| 29 |
|
| 30 |
$currentPos = '!' . count($escaped) . '!'; |
| 31 |
$escaped[$currentPos] = "[{$local[$index+1]}]"; |
| 32 |
|
| 33 |
$local = substr($local, 0, $index) . $currentPos . substr($local, ($index+2)); |
| 34 |
} |
| 35 |
|
| 36 |
$replacements = array( |
| 37 |
'd' => 'DD', |
| 38 |
'D' => 'ddd', |
| 39 |
'j' => 'D', |
| 40 |
'l' => 'dddd', |
| 41 |
'N' => 'E', |
| 42 |
'S' => 'o', |
| 43 |
'w' => 'e', |
| 44 |
'z' => 'DDD', |
| 45 |
'W' => 'W', |
| 46 |
'F' => 'MMMM', |
| 47 |
'm' => 'MM', |
| 48 |
'M' => 'MMM', |
| 49 |
'n' => 'M', |
| 50 |
't' => '', // no equivalent |
| 51 |
'L' => '', // no equivalent |
| 52 |
'o' => 'YYYY', |
| 53 |
'Y' => 'YYYY', |
| 54 |
'y' => 'YY', |
| 55 |
'a' => 'a', |
| 56 |
'A' => 'A', |
| 57 |
'B' => '', // no equivalent |
| 58 |
'g' => 'h', |
| 59 |
'G' => 'H', |
| 60 |
'h' => 'hh', |
| 61 |
'H' => 'HH', |
| 62 |
'i' => 'mm', |
| 63 |
's' => 'ss', |
| 64 |
'u' => 'SSS', |
| 65 |
'e' => 'zz', // deprecated since version 1.6.0 of moment.js |
| 66 |
'I' => '', // no equivalent |
| 67 |
'O' => '', // no equivalent |
| 68 |
'P' => '', // no equivalent |
| 69 |
'T' => '', // no equivalent |
| 70 |
'Z' => '', // no equivalent |
| 71 |
'c' => '', // no equivalent |
| 72 |
'r' => '', // no equivalent |
| 73 |
'U' => 'X', |
| 74 |
); |
| 75 |
|
| 76 |
$momentFormat = strtr($local, $replacements); |
| 77 |
$momentFormatWithEscaped = strtr($momentFormat, $escaped); |
| 78 |
return $momentFormatWithEscaped; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Default DateTime format |
| 83 |
* |
| 84 |
* @return string |
| 85 |
*/ |
| 86 |
public function default_format() |
| 87 |
{ |
| 88 |
return 'Y-m-d H:i'; |
| 89 |
} |
| 90 |
} |
| 91 |
|