Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. class MomentJs
  4. {
  5. static public $replacements = [
  6. 'y' => 'Y',
  7. 'yy' => 'YY',
  8. 'yyy' => 'YYY',
  9. 'yyyy' => 'YYYY',
  10. 'yyyyy' => 'YYYY',
  11. 'L' => 'M',
  12. 'LL' => 'MM',
  13. 'LLL' => 'MMM',
  14. 'LLLL' => 'MMMM',
  15. 'd' => 'D',
  16. 'dd' => 'DD',
  17. 'D' => 'DDD',
  18. 'DD' => 'DDDD',
  19. 'E' => 'ddd',
  20. 'EE' => 'ddd',
  21. 'EEE' => 'ddd',
  22. 'e' => 'd',
  23. 'ee' => 'd',
  24. 'eee' => 'ddd',
  25. 'a' => 'A',
  26. 'k' => 'H',
  27. 'kk' => 'HH',
  28. 'K' => 'h',
  29. 'KK' => 'hh'
  30. ];
  31.  
  32. static public function ldlmToMoment ($ldlmPattern)
  33. {
  34. foreach (array_reverse(self::$replacements) as $ldlm => $moment) {
  35. $short = substr($ldlm, 0, 1);
  36. $ldlmPattern = preg_replace("`(?:(?!^$short)|^)($ldlm)(?:(?!^$short)|$)`", $moment, $ldlmPattern);
  37. }
  38. return $ldlmPattern;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement