index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. var buildFormattingTokensRegExp = require('../../_lib/build_formatting_tokens_reg_exp/index.js')
  2. function buildFormatLocale () {
  3. var months3char = ['Ene', 'Peb', 'Mar', 'Abr', 'May', 'Hun', 'Hul', 'Ago', 'Set', 'Okt', 'Nob', 'Dis']
  4. var monthsFull = ['Enero', 'Pebrero', 'Marso', 'Abril', 'Mayo', 'Hunyo', 'Hulyo', 'Agosto', 'Setyembre', 'Oktubre', 'Nobyembre', 'Disyembre']
  5. var weekdays2char = ['Li', 'Lu', 'Ma', 'Mi', 'Hu', 'Bi', 'Sa']
  6. var weekdays3char = ['Lin', 'Lun', 'Mar', 'Miy', 'Huw', 'Biy', 'Sab']
  7. var weekdaysFull = ['Linggo', 'Lunes', 'Martes', 'Miyerkules', 'Huwebes', 'Biyernes', 'Sabado']
  8. var meridiemUppercase = ['NU', 'NT', 'NH', 'NG']
  9. var meridiemLowercase = ['nu', 'nt', 'nh', 'ng']
  10. var meridiemFull = ['ng umaga', 'ng tanghali', 'ng hapon', 'ng gabi']
  11. var formatters = {
  12. // Month: Jan, Feb, ..., Dec
  13. 'MMM': function (date) {
  14. return months3char[date.getMonth()]
  15. },
  16. // Month: January, February, ..., December
  17. 'MMMM': function (date) {
  18. return monthsFull[date.getMonth()]
  19. },
  20. // Day of week: Su, Mo, ..., Sa
  21. 'dd': function (date) {
  22. return weekdays2char[date.getDay()]
  23. },
  24. // Day of week: Sun, Mon, ..., Sat
  25. 'ddd': function (date) {
  26. return weekdays3char[date.getDay()]
  27. },
  28. // Day of week: Sunday, Monday, ..., Saturday
  29. 'dddd': function (date) {
  30. return weekdaysFull[date.getDay()]
  31. },
  32. // AM, PM
  33. 'A': function (date) {
  34. if (date.getHours() > 12) {
  35. var modulo = date.getHours() % 12
  36. if (modulo < 6) {
  37. return meridiemUppercase[2]
  38. } else {
  39. return meridiemUppercase[3]
  40. }
  41. } else if (date.getHours() < 12) {
  42. return meridiemUppercase[0]
  43. } else {
  44. return meridiemUppercase[1]
  45. }
  46. },
  47. // am, pm
  48. 'a': function (date) {
  49. if (date.getHours() > 12) {
  50. var modulo = date.getHours() % 12
  51. if (modulo < 6) {
  52. return meridiemLowercase[2]
  53. } else {
  54. return meridiemLowercase[3]
  55. }
  56. } else if (date.getHours() < 12) {
  57. return meridiemLowercase[0]
  58. } else {
  59. return meridiemLowercase[1]
  60. }
  61. },
  62. // a.m., p.m.
  63. 'aa': function (date) {
  64. if (date.getHours() > 12) {
  65. var modulo = date.getHours() % 12
  66. if (modulo < 6) {
  67. return meridiemFull[2]
  68. } else {
  69. return meridiemFull[3]
  70. }
  71. } else if (date.getHours() < 12) {
  72. return meridiemFull[0]
  73. } else {
  74. return meridiemFull[1]
  75. }
  76. }
  77. }
  78. // Generate ordinal version of formatters: M -> Mo, D -> Do, etc.
  79. var ordinalFormatters = ['M', 'D', 'DDD', 'd', 'Q', 'W']
  80. ordinalFormatters.forEach(function (formatterToken) {
  81. formatters[formatterToken + 'o'] = function (date, formatters) {
  82. return ordinal(formatters[formatterToken](date))
  83. }
  84. })
  85. return {
  86. formatters: formatters,
  87. formattingTokensRegExp: buildFormattingTokensRegExp(formatters)
  88. }
  89. }
  90. function ordinal (number) {
  91. return 'ika-' + number
  92. }
  93. module.exports = buildFormatLocale