ru.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. package ru
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ru struct {
  10. locale string
  11. pluralsCardinal []locales.PluralRule
  12. pluralsOrdinal []locales.PluralRule
  13. pluralsRange []locales.PluralRule
  14. decimal string
  15. group string
  16. minus string
  17. percent string
  18. perMille string
  19. timeSeparator string
  20. inifinity string
  21. currencies []string // idx = enum of currency code
  22. currencyPositiveSuffix string
  23. currencyNegativeSuffix string
  24. monthsAbbreviated []string
  25. monthsNarrow []string
  26. monthsWide []string
  27. daysAbbreviated []string
  28. daysNarrow []string
  29. daysShort []string
  30. daysWide []string
  31. periodsAbbreviated []string
  32. periodsNarrow []string
  33. periodsShort []string
  34. periodsWide []string
  35. erasAbbreviated []string
  36. erasNarrow []string
  37. erasWide []string
  38. timezones map[string]string
  39. }
  40. // New returns a new instance of translator for the 'ru' locale
  41. func New() locales.Translator {
  42. return &ru{
  43. locale: "ru",
  44. pluralsCardinal: []locales.PluralRule{2, 4, 5, 6},
  45. pluralsOrdinal: []locales.PluralRule{6},
  46. pluralsRange: []locales.PluralRule{2, 4, 5, 6},
  47. decimal: ",",
  48. group: " ",
  49. minus: "-",
  50. percent: "%",
  51. perMille: "‰",
  52. timeSeparator: ":",
  53. inifinity: "∞",
  54. currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "A$", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "FJD", "FKP", "FRF", "£", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MX$", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZ$", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "₽", "р.", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "STN", "SUR", "SVC", "SYP", "SZL", "฿", "TJR", "TJS", "TMM", "ТМТ", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "₴", "UAK", "UGS", "UGX", "$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
  55. currencyPositiveSuffix: " ",
  56. currencyNegativeSuffix: " ",
  57. monthsAbbreviated: []string{"", "янв.", "февр.", "мар.", "апр.", "мая", "июн.", "июл.", "авг.", "сент.", "окт.", "нояб.", "дек."},
  58. monthsNarrow: []string{"", "Я", "Ф", "М", "А", "М", "И", "И", "А", "С", "О", "Н", "Д"},
  59. monthsWide: []string{"", "января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"},
  60. daysAbbreviated: []string{"вс", "пн", "вт", "ср", "чт", "пт", "сб"},
  61. daysNarrow: []string{"вс", "пн", "вт", "ср", "чт", "пт", "сб"},
  62. daysShort: []string{"вс", "пн", "вт", "ср", "чт", "пт", "сб"},
  63. daysWide: []string{"воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"AM", "PM"},
  66. periodsWide: []string{"AM", "PM"},
  67. erasAbbreviated: []string{"до н. э.", "н. э."},
  68. erasNarrow: []string{"до н.э.", "н.э."},
  69. erasWide: []string{"до Рождества Христова", "от Рождества Христова"},
  70. timezones: map[string]string{"HNPM": "Сен-Пьер и Микелон, стандартное время", "EAT": "Восточная Африка", "AWDT": "Западная Австралия, летнее время", "NZST": "Новая Зеландия, стандартное время", "AKDT": "Аляска, летнее время", "WARST": "Западная Аргентина, летнее время", "CLST": "Чили, летнее время", "CST": "Центральная Америка, стандартное время", "PDT": "Тихоокеанское летнее время", "EDT": "Восточная Америка, летнее время", "VET": "Венесуэла", "NZDT": "Новая Зеландия, летнее время", "HKT": "Гонконг, стандартное время", "MYT": "Малайзия", "JST": "Япония, стандартное время", "COST": "Колумбия, летнее время", "HNCU": "Куба, стандартное время", "AWST": "Западная Австралия, стандартное время", "AEST": "Восточная Австралия, стандартное время", "WAST": "Западная Африка, летнее время", "MST": "Стандартное горное время (Северная Америка)", "EST": "Восточная Америка, стандартное время", "TMT": "Туркмения, стандартное время", "UYT": "Уругвай, стандартное время", "UYST": "Уругвай, летнее время", "CHAST": "Чатем, стандартное время", "AEDT": "Восточная Австралия, летнее время", "WEZ": "Западная Европа, стандартное время", "WITA": "Центральная Индонезия", "HNEG": "Восточная Гренландия, стандарное время", "HEEG": "Восточная Гренландия, летнее время", "MEZ": "Центральная Европа, стандартное время", "HEPM": "Сен-Пьер и Микелон, летнее время", "AST": "Атлантическое стандартное время", "WESZ": "Западная Европа, летнее время", "GFT": "Французская Гвиана", "ACDT": "Центральная Австралия, летнее время", "HENOMX": "Северо-западное мексиканское летнее время", "CAT": "Центральная Африка", "WIT": "Восточная Индонезия", "OESZ": "Восточная Европа, летнее время", "CHADT": "Чатем, летнее время", "MESZ": "Центральная Европа, летнее время", "GMT": "Среднее время по Гринвичу", "SAST": "Южная Африка", "ACST": "Центральная Австралия, стандартное время", "HAST": "Гавайско-алеутское стандартное время", "ACWDT": "Центральная Австралия, западное летнее время", "HEOG": "Западная Гренландия, летнее время", "HAT": "Ньюфаундленд, летнее время", "COT": "Колумбия, стандартное время", "ChST": "Чаморро", "CDT": "Центральная Америка, летнее время", "HNPMX": "Тихоокеанское мексиканское стандартное время", "SGT": "Сингапур", "HEPMX": "Тихоокеанское мексиканское летнее время", "MDT": "Летнее горное время (Северная Америка)", "ECT": "Эквадор", "WART": "Западная Аргентина, стандартное время", "LHDT": "Лорд-Хау, летнее время", "SRT": "Суринам", "HNNOMX": "Северо-западное мексиканское стандартное время", "TMST": "Туркмения, летнее время", "ARST": "Аргентина, летнее время", "HECU": "Куба, летнее время", "ACWST": "Центральная Австралия, западное стандартное время", "HNOG": "Западная Гренландия, стандартное время", "HKST": "Гонконг, летнее время", "IST": "Индия", "LHST": "Лорд-Хау, стандартное время", "HNT": "Ньюфаундленд, стандартное время", "PST": "Тихоокеанское стандартное время", "BT": "Бутан", "BOT": "Боливия", "JDT": "Япония, летнее время", "∅∅∅": "Бразилия, летнее время", "AKST": "Аляска, стандартное время", "HADT": "Гавайско-алеутское летнее время", "GYT": "Гайана", "OEZ": "Восточная Европа, стандартное время", "ART": "Аргентина, стандартное время", "ADT": "Атлантическое летнее время", "WAT": "Западная Африка, стандартное время", "WIB": "Западная Индонезия", "CLT": "Чили, стандартное время"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (ru *ru) Locale() string {
  75. return ru.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'ru'
  78. func (ru *ru) PluralsCardinal() []locales.PluralRule {
  79. return ru.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ru'
  82. func (ru *ru) PluralsOrdinal() []locales.PluralRule {
  83. return ru.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'ru'
  86. func (ru *ru) PluralsRange() []locales.PluralRule {
  87. return ru.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ru'
  90. func (ru *ru) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. iMod10 := i % 10
  94. iMod100 := i % 100
  95. if v == 0 && iMod10 == 1 && iMod100 != 11 {
  96. return locales.PluralRuleOne
  97. } else if v == 0 && iMod10 >= 2 && iMod10 <= 4 && (iMod100 < 12 || iMod100 > 14) {
  98. return locales.PluralRuleFew
  99. } else if (v == 0 && iMod10 == 0) || (v == 0 && iMod10 >= 5 && iMod10 <= 9) || (v == 0 && iMod100 >= 11 && iMod100 <= 14) {
  100. return locales.PluralRuleMany
  101. }
  102. return locales.PluralRuleOther
  103. }
  104. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ru'
  105. func (ru *ru) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  106. return locales.PluralRuleOther
  107. }
  108. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ru'
  109. func (ru *ru) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  110. start := ru.CardinalPluralRule(num1, v1)
  111. end := ru.CardinalPluralRule(num2, v2)
  112. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  113. return locales.PluralRuleOne
  114. } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
  115. return locales.PluralRuleFew
  116. } else if start == locales.PluralRuleOne && end == locales.PluralRuleMany {
  117. return locales.PluralRuleMany
  118. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  119. return locales.PluralRuleOther
  120. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOne {
  121. return locales.PluralRuleOne
  122. } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew {
  123. return locales.PluralRuleFew
  124. } else if start == locales.PluralRuleFew && end == locales.PluralRuleMany {
  125. return locales.PluralRuleMany
  126. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
  127. return locales.PluralRuleOther
  128. } else if start == locales.PluralRuleMany && end == locales.PluralRuleOne {
  129. return locales.PluralRuleOne
  130. } else if start == locales.PluralRuleMany && end == locales.PluralRuleFew {
  131. return locales.PluralRuleFew
  132. } else if start == locales.PluralRuleMany && end == locales.PluralRuleMany {
  133. return locales.PluralRuleMany
  134. } else if start == locales.PluralRuleMany && end == locales.PluralRuleOther {
  135. return locales.PluralRuleOther
  136. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  137. return locales.PluralRuleOne
  138. } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew {
  139. return locales.PluralRuleFew
  140. } else if start == locales.PluralRuleOther && end == locales.PluralRuleMany {
  141. return locales.PluralRuleMany
  142. }
  143. return locales.PluralRuleOther
  144. }
  145. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  146. func (ru *ru) MonthAbbreviated(month time.Month) string {
  147. return ru.monthsAbbreviated[month]
  148. }
  149. // MonthsAbbreviated returns the locales abbreviated months
  150. func (ru *ru) MonthsAbbreviated() []string {
  151. return ru.monthsAbbreviated[1:]
  152. }
  153. // MonthNarrow returns the locales narrow month given the 'month' provided
  154. func (ru *ru) MonthNarrow(month time.Month) string {
  155. return ru.monthsNarrow[month]
  156. }
  157. // MonthsNarrow returns the locales narrow months
  158. func (ru *ru) MonthsNarrow() []string {
  159. return ru.monthsNarrow[1:]
  160. }
  161. // MonthWide returns the locales wide month given the 'month' provided
  162. func (ru *ru) MonthWide(month time.Month) string {
  163. return ru.monthsWide[month]
  164. }
  165. // MonthsWide returns the locales wide months
  166. func (ru *ru) MonthsWide() []string {
  167. return ru.monthsWide[1:]
  168. }
  169. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  170. func (ru *ru) WeekdayAbbreviated(weekday time.Weekday) string {
  171. return ru.daysAbbreviated[weekday]
  172. }
  173. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  174. func (ru *ru) WeekdaysAbbreviated() []string {
  175. return ru.daysAbbreviated
  176. }
  177. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  178. func (ru *ru) WeekdayNarrow(weekday time.Weekday) string {
  179. return ru.daysNarrow[weekday]
  180. }
  181. // WeekdaysNarrow returns the locales narrow weekdays
  182. func (ru *ru) WeekdaysNarrow() []string {
  183. return ru.daysNarrow
  184. }
  185. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  186. func (ru *ru) WeekdayShort(weekday time.Weekday) string {
  187. return ru.daysShort[weekday]
  188. }
  189. // WeekdaysShort returns the locales short weekdays
  190. func (ru *ru) WeekdaysShort() []string {
  191. return ru.daysShort
  192. }
  193. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  194. func (ru *ru) WeekdayWide(weekday time.Weekday) string {
  195. return ru.daysWide[weekday]
  196. }
  197. // WeekdaysWide returns the locales wide weekdays
  198. func (ru *ru) WeekdaysWide() []string {
  199. return ru.daysWide
  200. }
  201. // Decimal returns the decimal point of number
  202. func (ru *ru) Decimal() string {
  203. return ru.decimal
  204. }
  205. // Group returns the group of number
  206. func (ru *ru) Group() string {
  207. return ru.group
  208. }
  209. // Group returns the minus sign of number
  210. func (ru *ru) Minus() string {
  211. return ru.minus
  212. }
  213. // FmtNumber returns 'num' with digits/precision of 'v' for 'ru' and handles both Whole and Real numbers based on 'v'
  214. func (ru *ru) FmtNumber(num float64, v uint64) string {
  215. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  216. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  217. count := 0
  218. inWhole := v == 0
  219. b := make([]byte, 0, l)
  220. for i := len(s) - 1; i >= 0; i-- {
  221. if s[i] == '.' {
  222. b = append(b, ru.decimal[0])
  223. inWhole = true
  224. continue
  225. }
  226. if inWhole {
  227. if count == 3 {
  228. for j := len(ru.group) - 1; j >= 0; j-- {
  229. b = append(b, ru.group[j])
  230. }
  231. count = 1
  232. } else {
  233. count++
  234. }
  235. }
  236. b = append(b, s[i])
  237. }
  238. if num < 0 {
  239. b = append(b, ru.minus[0])
  240. }
  241. // reverse
  242. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  243. b[i], b[j] = b[j], b[i]
  244. }
  245. return string(b)
  246. }
  247. // FmtPercent returns 'num' with digits/precision of 'v' for 'ru' and handles both Whole and Real numbers based on 'v'
  248. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  249. func (ru *ru) FmtPercent(num float64, v uint64) string {
  250. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  251. l := len(s) + 3
  252. b := make([]byte, 0, l)
  253. for i := len(s) - 1; i >= 0; i-- {
  254. if s[i] == '.' {
  255. b = append(b, ru.decimal[0])
  256. continue
  257. }
  258. b = append(b, s[i])
  259. }
  260. if num < 0 {
  261. b = append(b, ru.minus[0])
  262. }
  263. // reverse
  264. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  265. b[i], b[j] = b[j], b[i]
  266. }
  267. b = append(b, ru.percent...)
  268. return string(b)
  269. }
  270. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ru'
  271. func (ru *ru) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  272. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  273. symbol := ru.currencies[currency]
  274. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  275. count := 0
  276. inWhole := v == 0
  277. b := make([]byte, 0, l)
  278. for i := len(s) - 1; i >= 0; i-- {
  279. if s[i] == '.' {
  280. b = append(b, ru.decimal[0])
  281. inWhole = true
  282. continue
  283. }
  284. if inWhole {
  285. if count == 3 {
  286. for j := len(ru.group) - 1; j >= 0; j-- {
  287. b = append(b, ru.group[j])
  288. }
  289. count = 1
  290. } else {
  291. count++
  292. }
  293. }
  294. b = append(b, s[i])
  295. }
  296. if num < 0 {
  297. b = append(b, ru.minus[0])
  298. }
  299. // reverse
  300. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  301. b[i], b[j] = b[j], b[i]
  302. }
  303. if int(v) < 2 {
  304. if v == 0 {
  305. b = append(b, ru.decimal...)
  306. }
  307. for i := 0; i < 2-int(v); i++ {
  308. b = append(b, '0')
  309. }
  310. }
  311. b = append(b, ru.currencyPositiveSuffix...)
  312. b = append(b, symbol...)
  313. return string(b)
  314. }
  315. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ru'
  316. // in accounting notation.
  317. func (ru *ru) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  318. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  319. symbol := ru.currencies[currency]
  320. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  321. count := 0
  322. inWhole := v == 0
  323. b := make([]byte, 0, l)
  324. for i := len(s) - 1; i >= 0; i-- {
  325. if s[i] == '.' {
  326. b = append(b, ru.decimal[0])
  327. inWhole = true
  328. continue
  329. }
  330. if inWhole {
  331. if count == 3 {
  332. for j := len(ru.group) - 1; j >= 0; j-- {
  333. b = append(b, ru.group[j])
  334. }
  335. count = 1
  336. } else {
  337. count++
  338. }
  339. }
  340. b = append(b, s[i])
  341. }
  342. if num < 0 {
  343. b = append(b, ru.minus[0])
  344. }
  345. // reverse
  346. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  347. b[i], b[j] = b[j], b[i]
  348. }
  349. if int(v) < 2 {
  350. if v == 0 {
  351. b = append(b, ru.decimal...)
  352. }
  353. for i := 0; i < 2-int(v); i++ {
  354. b = append(b, '0')
  355. }
  356. }
  357. if num < 0 {
  358. b = append(b, ru.currencyNegativeSuffix...)
  359. b = append(b, symbol...)
  360. } else {
  361. b = append(b, ru.currencyPositiveSuffix...)
  362. b = append(b, symbol...)
  363. }
  364. return string(b)
  365. }
  366. // FmtDateShort returns the short date representation of 't' for 'ru'
  367. func (ru *ru) FmtDateShort(t time.Time) string {
  368. b := make([]byte, 0, 32)
  369. if t.Day() < 10 {
  370. b = append(b, '0')
  371. }
  372. b = strconv.AppendInt(b, int64(t.Day()), 10)
  373. b = append(b, []byte{0x2e}...)
  374. if t.Month() < 10 {
  375. b = append(b, '0')
  376. }
  377. b = strconv.AppendInt(b, int64(t.Month()), 10)
  378. b = append(b, []byte{0x2e}...)
  379. if t.Year() > 0 {
  380. b = strconv.AppendInt(b, int64(t.Year()), 10)
  381. } else {
  382. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  383. }
  384. return string(b)
  385. }
  386. // FmtDateMedium returns the medium date representation of 't' for 'ru'
  387. func (ru *ru) FmtDateMedium(t time.Time) string {
  388. b := make([]byte, 0, 32)
  389. b = strconv.AppendInt(b, int64(t.Day()), 10)
  390. b = append(b, []byte{0x20}...)
  391. b = append(b, ru.monthsAbbreviated[t.Month()]...)
  392. b = append(b, []byte{0x20}...)
  393. if t.Year() > 0 {
  394. b = strconv.AppendInt(b, int64(t.Year()), 10)
  395. } else {
  396. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  397. }
  398. b = append(b, []byte{0x20, 0xd0, 0xb3}...)
  399. b = append(b, []byte{0x2e}...)
  400. return string(b)
  401. }
  402. // FmtDateLong returns the long date representation of 't' for 'ru'
  403. func (ru *ru) FmtDateLong(t time.Time) string {
  404. b := make([]byte, 0, 32)
  405. b = strconv.AppendInt(b, int64(t.Day()), 10)
  406. b = append(b, []byte{0x20}...)
  407. b = append(b, ru.monthsWide[t.Month()]...)
  408. b = append(b, []byte{0x20}...)
  409. if t.Year() > 0 {
  410. b = strconv.AppendInt(b, int64(t.Year()), 10)
  411. } else {
  412. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  413. }
  414. b = append(b, []byte{0x20, 0xd0, 0xb3}...)
  415. b = append(b, []byte{0x2e}...)
  416. return string(b)
  417. }
  418. // FmtDateFull returns the full date representation of 't' for 'ru'
  419. func (ru *ru) FmtDateFull(t time.Time) string {
  420. b := make([]byte, 0, 32)
  421. b = append(b, ru.daysWide[t.Weekday()]...)
  422. b = append(b, []byte{0x2c, 0x20}...)
  423. b = strconv.AppendInt(b, int64(t.Day()), 10)
  424. b = append(b, []byte{0x20}...)
  425. b = append(b, ru.monthsWide[t.Month()]...)
  426. b = append(b, []byte{0x20}...)
  427. if t.Year() > 0 {
  428. b = strconv.AppendInt(b, int64(t.Year()), 10)
  429. } else {
  430. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  431. }
  432. b = append(b, []byte{0x20, 0xd0, 0xb3}...)
  433. b = append(b, []byte{0x2e}...)
  434. return string(b)
  435. }
  436. // FmtTimeShort returns the short time representation of 't' for 'ru'
  437. func (ru *ru) FmtTimeShort(t time.Time) string {
  438. b := make([]byte, 0, 32)
  439. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  440. b = append(b, ru.timeSeparator...)
  441. if t.Minute() < 10 {
  442. b = append(b, '0')
  443. }
  444. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  445. return string(b)
  446. }
  447. // FmtTimeMedium returns the medium time representation of 't' for 'ru'
  448. func (ru *ru) FmtTimeMedium(t time.Time) string {
  449. b := make([]byte, 0, 32)
  450. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  451. b = append(b, ru.timeSeparator...)
  452. if t.Minute() < 10 {
  453. b = append(b, '0')
  454. }
  455. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  456. b = append(b, ru.timeSeparator...)
  457. if t.Second() < 10 {
  458. b = append(b, '0')
  459. }
  460. b = strconv.AppendInt(b, int64(t.Second()), 10)
  461. return string(b)
  462. }
  463. // FmtTimeLong returns the long time representation of 't' for 'ru'
  464. func (ru *ru) FmtTimeLong(t time.Time) string {
  465. b := make([]byte, 0, 32)
  466. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  467. b = append(b, ru.timeSeparator...)
  468. if t.Minute() < 10 {
  469. b = append(b, '0')
  470. }
  471. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  472. b = append(b, ru.timeSeparator...)
  473. if t.Second() < 10 {
  474. b = append(b, '0')
  475. }
  476. b = strconv.AppendInt(b, int64(t.Second()), 10)
  477. b = append(b, []byte{0x20}...)
  478. tz, _ := t.Zone()
  479. b = append(b, tz...)
  480. return string(b)
  481. }
  482. // FmtTimeFull returns the full time representation of 't' for 'ru'
  483. func (ru *ru) FmtTimeFull(t time.Time) string {
  484. b := make([]byte, 0, 32)
  485. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  486. b = append(b, ru.timeSeparator...)
  487. if t.Minute() < 10 {
  488. b = append(b, '0')
  489. }
  490. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  491. b = append(b, ru.timeSeparator...)
  492. if t.Second() < 10 {
  493. b = append(b, '0')
  494. }
  495. b = strconv.AppendInt(b, int64(t.Second()), 10)
  496. b = append(b, []byte{0x20}...)
  497. tz, _ := t.Zone()
  498. if btz, ok := ru.timezones[tz]; ok {
  499. b = append(b, btz...)
  500. } else {
  501. b = append(b, tz...)
  502. }
  503. return string(b)
  504. }