*/ private const PHP_TO_MOMENT = array( 'Y' => 'YYYY', 'y' => 'YY', 'F' => 'MMMM', 'M' => 'MMM', 'm' => 'MM', 'n' => 'M', 'd' => 'DD', 'j' => 'D', 'l' => 'dddd', 'D' => 'ddd', 'H' => 'HH', 'G' => 'H', 'h' => 'hh', 'g' => 'h', 'i' => 'mm', 's' => 'ss', 'a' => 'a', 'A' => 'A', ); /** * Converts a PHP date format string to a moment.js-compatible one. * * @since 1.0.0 * * @param string $php_format PHP date format string. * * @return string Moment.js format string. */ public static function to_javascript( string $php_format ): string { $out = ''; $length = strlen( $php_format ); for ( $i = 0; $i < $length; $i++ ) { $char = $php_format[ $i ]; // Backslash escapes the next character — pass it through as a literal. if ( '\\' === $char && $i + 1 < $length ) { $out .= '[' . $php_format[ $i + 1 ] . ']'; ++$i; continue; } $out .= self::PHP_TO_MOMENT[ $char ] ?? $char; } return $out; } }