index.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var buildFormattingTokensRegExp = require('../../_lib/build_formatting_tokens_reg_exp/index.js')
  2. function buildFormatLocale () {
  3. var months3char = ['sij', 'velj', 'ožu', 'tra', 'svi', 'lip', 'srp', 'kol', 'ruj', 'lis', 'stu', 'pro']
  4. var monthsFull = ['siječanj', 'veljača', 'ožujak', 'travanj', 'svibanj', 'lipanj', 'srpanj', 'kolovoz', 'rujan', 'listopad', 'studeni', 'prosinac']
  5. var monthsGenitive = ['siječnja', 'veljače', 'ožujka', 'travnja', 'svibnja', 'lipnja', 'srpnja', 'kolovoza', 'rujna', 'listopada', 'studenog', 'prosinca']
  6. var weekdays2char = ['ne', 'po', 'ut', 'sr', 'če', 'pe', 'su']
  7. var weekdays3char = ['ned', 'pon', 'uto', 'sri', 'čet', 'pet', 'sub']
  8. var weekdaysFull = ['nedjelja', 'ponedjeljak', 'utorak', 'srijeda', 'četvrtak', 'petak', 'subota']
  9. var meridiemUppercase = ['ujutro', 'popodne']
  10. var meridiemLowercase = ['ujutro', 'popodne']
  11. var meridiemFull = ['ujutro', 'popodne']
  12. var formatters = {
  13. // Month: Jan, Feb, ..., Dec
  14. 'MMM': function (date) {
  15. return months3char[date.getMonth()]
  16. },
  17. // Month: January, February, ..., December
  18. 'MMMM': function (date) {
  19. return monthsFull[date.getMonth()]
  20. },
  21. // Day of week: Su, Mo, ..., Sa
  22. 'dd': function (date) {
  23. return weekdays2char[date.getDay()]
  24. },
  25. // Day of week: Sun, Mon, ..., Sat
  26. 'ddd': function (date) {
  27. return weekdays3char[date.getDay()]
  28. },
  29. // Day of week: Sunday, Monday, ..., Saturday
  30. 'dddd': function (date) {
  31. return weekdaysFull[date.getDay()]
  32. },
  33. // AM, PM
  34. 'A': function (date) {
  35. return (date.getHours() / 12) >= 1 ? meridiemUppercase[1] : meridiemUppercase[0]
  36. },
  37. // am, pm
  38. 'a': function (date) {
  39. return (date.getHours() / 12) >= 1 ? meridiemLowercase[1] : meridiemLowercase[0]
  40. },
  41. // a.m., p.m.
  42. 'aa': function (date) {
  43. return (date.getHours() / 12) >= 1 ? meridiemFull[1] : meridiemFull[0]
  44. }
  45. }
  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. return ordinal(formatters[formatterToken](date))
  51. }
  52. })
  53. // Generate formatters like 'D MMMM', where the month is in the genitive case
  54. var monthsGenitiveFormatters = ['D', 'Do', 'DD']
  55. monthsGenitiveFormatters.forEach(function (formatterToken) {
  56. formatters[formatterToken + ' MMM'] = function (date, commonFormatters) {
  57. var formatter = formatters[formatterToken] || commonFormatters[formatterToken]
  58. return formatter(date, commonFormatters) + ' ' + monthsGenitive[date.getMonth()]
  59. }
  60. })
  61. return {
  62. formatters: formatters,
  63. formattingTokensRegExp: buildFormattingTokensRegExp(formatters)
  64. }
  65. }
  66. function ordinal (number) {
  67. return number + '.'
  68. }
  69. module.exports = buildFormatLocale