index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var buildFormattingTokensRegExp = require('../../_lib/build_formatting_tokens_reg_exp/index.js')
  2. function buildFormatLocale () {
  3. var months3char = ['sty', 'lut', 'mar', 'kwi', 'maj', 'cze', 'lip', 'sie', 'wrz', 'paź', 'lis', 'gru']
  4. var monthsFull = ['styczeń', 'luty', 'marzec', 'kwiecień', 'maj', 'czerwiec', 'lipiec', 'sierpień', 'wrzesień', 'październik', 'listopad', 'grudzień']
  5. var weekdays2char = ['nd', 'pn', 'wt', 'śr', 'cz', 'pt', 'sb']
  6. var weekdays3char = ['niedz.', 'pon.', 'wt.', 'śr.', 'czw.', 'piąt.', 'sob.']
  7. var weekdaysFull = ['niedziela', 'poniedziałek', 'wtorek', 'środa', 'czwartek', 'piątek', 'sobota']
  8. var meridiem = ['w nocy', 'rano', 'po południu', 'wieczorem']
  9. var formatters = {
  10. // Month: Jan, Feb, ..., Dec
  11. 'MMM': function (date) {
  12. return months3char[date.getMonth()]
  13. },
  14. // Month: January, February, ..., December
  15. 'MMMM': function (date) {
  16. return monthsFull[date.getMonth()]
  17. },
  18. // Day of week: Su, Mo, ..., Sa
  19. 'dd': function (date) {
  20. return weekdays2char[date.getDay()]
  21. },
  22. // Day of week: Sun, Mon, ..., Sat
  23. 'ddd': function (date) {
  24. return weekdays3char[date.getDay()]
  25. },
  26. // Day of week: Sunday, Monday, ..., Saturday
  27. 'dddd': function (date) {
  28. return weekdaysFull[date.getDay()]
  29. },
  30. // Time of day
  31. 'A': function (date) {
  32. var hours = date.getHours()
  33. if (hours >= 17) {
  34. return meridiem[3]
  35. } else if (hours >= 12) {
  36. return meridiem[2]
  37. } else if (hours >= 4) {
  38. return meridiem[1]
  39. } else {
  40. return meridiem[0]
  41. }
  42. }
  43. }
  44. formatters.a = formatters.A
  45. formatters.aa = formatters.A
  46. // Generate ordinal version of formatters: M -> Mo, D -> Do, etc.
  47. var ordinalFormatters = ['M', 'D', 'DDD', 'd', 'Q', 'W']
  48. ordinalFormatters.forEach(function (formatterToken) {
  49. formatters[formatterToken + 'o'] = function (date, formatters) {
  50. // Well, it should be just a number without any suffix
  51. return formatters[formatterToken](date).toString()
  52. }
  53. })
  54. return {
  55. formatters: formatters,
  56. formattingTokensRegExp: buildFormattingTokensRegExp(formatters)
  57. }
  58. }
  59. module.exports = buildFormatLocale