index.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var buildFormattingTokensRegExp = require('../../_lib/build_formatting_tokens_reg_exp/index.js')
  2. function buildFormatLocale () {
  3. // Note: in Indonesian, the names of days of the week and months are capitalized.
  4. // If you are making a new locale based on this one, check if the same is true for the language you're working on.
  5. // Generally, formatted dates should look like they are in the middle of a sentence,
  6. // e.g. in Spanish language the weekdays and months should be in the lowercase.
  7. var months3char = ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des']
  8. var monthsFull = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember']
  9. var weekdays2char = ['Mi', 'Sn', 'Sl', 'Ra', 'Ka', 'Ju', 'Sa']
  10. var weekdays3char = ['Min', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab']
  11. var weekdaysFull = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu']
  12. var meridiemUppercase = ['AM', 'PM']
  13. var meridiemLowercase = ['am', 'pm']
  14. var meridiemFull = ['a.m.', 'p.m.']
  15. var formatters = {
  16. // Month: Jan, Feb, ..., Dec
  17. 'MMM': function (date) {
  18. return months3char[date.getMonth()]
  19. },
  20. // Month: January, February, ..., December
  21. 'MMMM': function (date) {
  22. return monthsFull[date.getMonth()]
  23. },
  24. // Day of week: Su, Mo, ..., Sa
  25. 'dd': function (date) {
  26. return weekdays2char[date.getDay()]
  27. },
  28. // Day of week: Sun, Mon, ..., Sat
  29. 'ddd': function (date) {
  30. return weekdays3char[date.getDay()]
  31. },
  32. // Day of week: Sunday, Monday, ..., Saturday
  33. 'dddd': function (date) {
  34. return weekdaysFull[date.getDay()]
  35. },
  36. // AM, PM
  37. 'A': function (date) {
  38. return (date.getHours() / 12) >= 1 ? meridiemUppercase[1] : meridiemUppercase[0]
  39. },
  40. // am, pm
  41. 'a': function (date) {
  42. return (date.getHours() / 12) >= 1 ? meridiemLowercase[1] : meridiemLowercase[0]
  43. },
  44. // a.m., p.m.
  45. 'aa': function (date) {
  46. return (date.getHours() / 12) >= 1 ? meridiemFull[1] : meridiemFull[0]
  47. }
  48. }
  49. // Generate ordinal version of formatters: M -> Mo, D -> Do, etc.
  50. var ordinalFormatters = ['M', 'D', 'DDD', 'd', 'Q', 'W']
  51. ordinalFormatters.forEach(function (formatterToken) {
  52. formatters[formatterToken + 'o'] = function (date, formatters) {
  53. return ordinal(formatters[formatterToken](date))
  54. }
  55. })
  56. return {
  57. formatters: formatters,
  58. formattingTokensRegExp: buildFormattingTokensRegExp(formatters)
  59. }
  60. }
  61. function ordinal (number) {
  62. switch (number) {
  63. case 1:
  64. return 'pertama'
  65. case 2:
  66. return 'kedua'
  67. case 3:
  68. return 'ketiga'
  69. default:
  70. return 'ke-' + number
  71. }
  72. }
  73. module.exports = buildFormatLocale