index.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. var buildFormattingTokensRegExp = require('../../_lib/build_formatting_tokens_reg_exp/index.js')
  2. function buildFormatLocale () {
  3. // Note: in Romanian language the weekdays and months should be in the lowercase.
  4. var months3char = ['ian', 'feb', 'mar', 'apr', 'mai', 'iun', 'iul', 'aug', 'sep', 'oct', 'noi', 'dec']
  5. var monthsFull = ['ianuarie', 'februarie', 'martie', 'aprilie', 'mai', 'iunie', 'iulie', 'august', 'septembrie', 'octombrie', 'noiembrie', 'decembrie']
  6. var weekdays2char = ['du', 'lu', 'ma', 'mi', 'jo', 'vi', 'sâ']
  7. var weekdays3char = ['dum', 'lun', 'mar', 'mie', 'joi', 'vin', 'sâm']
  8. var weekdaysFull = ['duminică', 'luni', 'marți', 'miercuri', 'joi', 'vineri', 'sâmbăta']
  9. var meridiemUppercase = ['AM', 'PM']
  10. var meridiemLowercase = ['am', 'pm']
  11. var meridiemFull = ['a.m.', 'p.m.']
  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. return {
  54. formatters: formatters,
  55. formattingTokensRegExp: buildFormattingTokensRegExp(formatters)
  56. }
  57. }
  58. function ordinal (number) {
  59. return number.toString()
  60. }
  61. module.exports = buildFormatLocale