index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. var buildFormattingTokensRegExp = require('../../_lib/build_formatting_tokens_reg_exp/index.js')
  2. function buildFormatLocale () {
  3. // Note: in Turkish, 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 = ['Oca', 'Şub', 'Mar', 'Nis', 'May', 'Haz', 'Tem', 'Ağu', 'Eyl', 'Eki', 'Kas', 'Ara']
  8. var monthsFull = ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık']
  9. var weekdays2char = ['Pz', 'Pt', 'Sa', 'Ça', 'Pe', 'Cu', 'Ct']
  10. var weekdays3char = ['Paz', 'Pts', 'Sal', 'Çar', 'Per', 'Cum', 'Cts']
  11. var weekdaysFull = ['Pazar', 'Pazartesi', 'Salı', 'Çarşamba', 'Perşembe', 'Cuma', 'Cumartesi']
  12. var meridiemUppercase = ['ÖÖ', 'ÖS']
  13. var meridiemLowercase = ['öö', 'ös']
  14. var meridiemFull = ['ö.ö.', 'ö.s.']
  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. var suffixes = {
  63. 1: '\'inci',
  64. 2: '\'inci',
  65. 3: '\'üncü',
  66. 4: '\'üncü',
  67. 5: '\'inci',
  68. 6: '\'ıncı',
  69. 7: '\'inci',
  70. 8: '\'inci',
  71. 9: '\'uncu',
  72. 10: '\'uncu',
  73. 20: '\'inci',
  74. 30: '\'uncu',
  75. 50: '\'inci',
  76. 60: '\'ıncı',
  77. 70: '\'inci',
  78. 80: '\'inci',
  79. 90: '\'ıncı',
  80. 100: '\'üncü'
  81. }
  82. if (number === 0) {
  83. return '0\'ıncı'
  84. }
  85. var x = number % 10
  86. var y = number % 100 - x
  87. var z = number >= 100 ? 100 : null
  88. return number + (suffixes[x] || suffixes[y] || suffixes[z])
  89. }
  90. module.exports = buildFormatLocale