be.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. package be
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type be 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. percentSuffix string
  19. perMille string
  20. timeSeparator string
  21. inifinity string
  22. currencies []string // idx = enum of currency code
  23. currencyNegativePrefix string
  24. currencyNegativeSuffix string
  25. monthsAbbreviated []string
  26. monthsNarrow []string
  27. monthsWide []string
  28. daysAbbreviated []string
  29. daysNarrow []string
  30. daysShort []string
  31. daysWide []string
  32. periodsAbbreviated []string
  33. periodsNarrow []string
  34. periodsShort []string
  35. periodsWide []string
  36. erasAbbreviated []string
  37. erasNarrow []string
  38. erasWide []string
  39. timezones map[string]string
  40. }
  41. // New returns a new instance of translator for the 'be' locale
  42. func New() locales.Translator {
  43. return &be{
  44. locale: "be",
  45. pluralsCardinal: []locales.PluralRule{2, 4, 5, 6},
  46. pluralsOrdinal: []locales.PluralRule{4, 6},
  47. pluralsRange: nil,
  48. decimal: ",",
  49. group: " ",
  50. minus: "-",
  51. percent: "%",
  52. perMille: "‰",
  53. timeSeparator: ".",
  54. inifinity: "∞",
  55. 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 ", "BRL", "BRN ", "BRR ", "BRZ ", "BSD", "BTN", "BUK ", "BWP", "BYB ", "р.", "BZD", "CAD", "CDF", "CHE ", "CHF", "CHW ", "CLE ", "CLF ", "CLP", "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", "NZD", "OMR", "PAB", "PEI ", "PEN", "PES ", "PGK", "PHP", "PKR", "PLN", "PLZ ", "PTE ", "PYG", "QAR", "RHD ", "ROL ", "RON", "RSD", "₽", "RUR ", "RWF", "SAR", "SBD", "SCR", "SDD ", "SDG", "SDP ", "SEK", "SGD", "SHP", "SIT ", "SKK ", "SLL", "SOS", "SRD", "SRG ", "SSP", "STD", "SUR ", "SVC ", "SYP", "SZL", "THB", "TJR ", "TJS", "TMM ", "TMT", "TND", "TOP", "TPE ", "TRL ", "TRY", "TTD", "NT$", "TZS", "UAH", "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 ", "XXX ", "YDD ", "YER", "YUD ", "YUM ", "YUN ", "YUR ", "ZAL ", "ZAR", "ZMK ", "ZMW", "ZRN ", "ZRZ ", "ZWD ", "ZWL ", "ZWR "},
  56. percentSuffix: " ",
  57. currencyNegativePrefix: "(",
  58. currencyNegativeSuffix: ")",
  59. monthsAbbreviated: []string{"", "сту", "лют", "сак", "кра", "мая", "чэр", "ліп", "жні", "вер", "кас", "ліс", "сне"},
  60. monthsNarrow: []string{"", "с", "л", "с", "к", "м", "ч", "л", "ж", "в", "к", "л", "с"},
  61. monthsWide: []string{"", "студзеня", "лютага", "сакавіка", "красавіка", "мая", "чэрвеня", "ліпеня", "жніўня", "верасня", "кастрычніка", "лістапада", "снежня"},
  62. daysAbbreviated: []string{"нд", "пн", "аў", "ср", "чц", "пт", "сб"},
  63. daysNarrow: []string{"н", "п", "а", "с", "ч", "п", "с"},
  64. daysShort: []string{"нд", "пн", "аў", "ср", "чц", "пт", "сб"},
  65. daysWide: []string{"нядзеля", "панядзелак", "аўторак", "серада", "чацвер", "пятніца", "субота"},
  66. periodsAbbreviated: []string{"раніцы", "вечара"},
  67. periodsNarrow: []string{"ран.", "веч."},
  68. periodsWide: []string{"да паўдня", "пасля паўдня"},
  69. erasAbbreviated: []string{"да н.э.", "н.э."},
  70. erasNarrow: []string{"", ""},
  71. erasWide: []string{"", ""},
  72. timezones: map[string]string{"VET": "Венесуэльскі час", "SGT": "Сінгапурскі час", "JST": "Стандартны час Японіі", "MEZ": "Цэнтральнаеўрапейскі стандартны час", "HAST": "Гавайска-Алеуцкі стандартны час", "ART": "Аргенцінскі стандартны час", "CHAST": "Стандартны час Чатэма", "CLT": "Чылійскі стандартны час", "WAT": "Заходнеафрыканскі стандартны час", "WAST": "Заходнеафрыканскі летні час", "NZST": "Стандартны час Новай Зеландыі", "NZDT": "Летні час Новай Зеландыі", "AEDT": "Летні час усходняй Аўстраліі", "AST": "Атлантычны стандартны час", "EDT": "Паўночнаамерыканскі ўсходні летні час", "HKT": "Стандартны час Ганконга", "JDT": "Летні час Японіі", "PST": "Ціхаакіянскі стандартны час", "WITA": "Цэнтральнаінданезійскі час", "IST": "Час Індыі", "TMT": "Стандартны час Туркменістана", "GYT": "Час Гаяны", "CDT": "Паўночнаамерыканскі цэнтральны летні час", "WESZ": "Заходнееўрапейскі летні час", "ACWDT": "Заходні летні час Цэнтральнай Аўстраліі", "WARST": "Летні час Заходняй Аргенціны", "AKDT": "Летні час Аляскі", "MESZ": "Цэнтральнаеўрапейскі летні час", "ChST": "Час Чамора", "CLST": "Чылійскі летні час", "OEZ": "Усходнееўрапейскі стандартны час", "MYT": "Час Малайзіі", "PDT": "Ціхаакіянскі летні час", "CAT": "Цэнтральнаафрыканскі час", "GMT": "Час па Грынвічы", "WIT": "Усходнеінданезійскі час", "EAT": "Усходнеафрыканскі час", "ARST": "Аргенцінскі летні час", "AEST": "Стандартны час усходняй Аўстраліі", "COT": "Калумбійскі стандартны час", "GFT": "Час Французскай Гвіяны", "ACDT": "Летні час цэнтральнай Аўстраліі", "ADT": "Атлантычны летні час", "SAST": "Паўднёваафрыканскі час", "TMST": "Летні час Туркменістана", "ECT": "Эквадорскі час", "BT": "Час Бутана", "OESZ": "Усходнееўрапейскі летні час", "AKST": "Стандартны час Аляскі", "UYT": "Уругвайскі стандартны час", "CST": "Паўночнаамерыканскі цэнтральны стандартны час", "WEZ": "Заходнееўрапейскі стандартны час", "ACWST": "Заходні стандартны час Цэнтральнай Аўстраліі", "HAT": "Ньюфаўндлендскі летні час", "ACST": "Стандартны час цэнтральнай Аўстраліі", "AWST": "Стандартны час заходняй Аўстраліі", "UYST": "Уругвайскі летні час", "MST": "Паўночнаамерыканскі горны стандартны час", "COST": "Калумбійскі летні час", "HADT": "Гавайска-Алеуцкі летні час", "MDT": "Паўночнаамерыканскі горны летні час", "∅∅∅": "Бразільскі летні час", "LHST": "Стандартны час Лорд-Хау", "SRT": "Час Сурынама", "HKST": "Летні час Ганконга", "WART": "Стандартны час Заходняй Аргенціны", "HNT": "Ньюфаўндлендскі стандартны час", "WIB": "Заходнеінданезійскі час", "LHDT": "Летні час Лорд-Хау", "BOT": "Балівійскі час", "CHADT": "Летні час Чатэма", "EST": "Паўночнаамерыканскі ўсходні стандартны час", "AWDT": "Летні час заходняй Аўстраліі"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (be *be) Locale() string {
  77. return be.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'be'
  80. func (be *be) PluralsCardinal() []locales.PluralRule {
  81. return be.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'be'
  84. func (be *be) PluralsOrdinal() []locales.PluralRule {
  85. return be.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'be'
  88. func (be *be) PluralsRange() []locales.PluralRule {
  89. return be.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'be'
  92. func (be *be) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. nMod10 := math.Mod(n, 10)
  95. nMod100 := math.Mod(n, 100)
  96. if nMod10 == 1 && nMod100 != 11 {
  97. return locales.PluralRuleOne
  98. } else if nMod10 >= 2 && nMod10 <= 4 && nMod100 < 12 && nMod100 > 14 {
  99. return locales.PluralRuleFew
  100. } else if (nMod10 == 0) || (nMod10 >= 5 && nMod10 <= 9) || (nMod100 >= 11 && nMod100 <= 14) {
  101. return locales.PluralRuleMany
  102. }
  103. return locales.PluralRuleOther
  104. }
  105. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'be'
  106. func (be *be) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  107. n := math.Abs(num)
  108. nMod10 := math.Mod(n, 10)
  109. nMod100 := math.Mod(n, 100)
  110. if (nMod10 == 2 || nMod10 == 3) && (nMod100 != 12 && nMod100 != 13) {
  111. return locales.PluralRuleFew
  112. }
  113. return locales.PluralRuleOther
  114. }
  115. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'be'
  116. func (be *be) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  117. return locales.PluralRuleUnknown
  118. }
  119. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  120. func (be *be) MonthAbbreviated(month time.Month) string {
  121. return be.monthsAbbreviated[month]
  122. }
  123. // MonthsAbbreviated returns the locales abbreviated months
  124. func (be *be) MonthsAbbreviated() []string {
  125. return be.monthsAbbreviated[1:]
  126. }
  127. // MonthNarrow returns the locales narrow month given the 'month' provided
  128. func (be *be) MonthNarrow(month time.Month) string {
  129. return be.monthsNarrow[month]
  130. }
  131. // MonthsNarrow returns the locales narrow months
  132. func (be *be) MonthsNarrow() []string {
  133. return be.monthsNarrow[1:]
  134. }
  135. // MonthWide returns the locales wide month given the 'month' provided
  136. func (be *be) MonthWide(month time.Month) string {
  137. return be.monthsWide[month]
  138. }
  139. // MonthsWide returns the locales wide months
  140. func (be *be) MonthsWide() []string {
  141. return be.monthsWide[1:]
  142. }
  143. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  144. func (be *be) WeekdayAbbreviated(weekday time.Weekday) string {
  145. return be.daysAbbreviated[weekday]
  146. }
  147. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  148. func (be *be) WeekdaysAbbreviated() []string {
  149. return be.daysAbbreviated
  150. }
  151. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  152. func (be *be) WeekdayNarrow(weekday time.Weekday) string {
  153. return be.daysNarrow[weekday]
  154. }
  155. // WeekdaysNarrow returns the locales narrow weekdays
  156. func (be *be) WeekdaysNarrow() []string {
  157. return be.daysNarrow
  158. }
  159. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  160. func (be *be) WeekdayShort(weekday time.Weekday) string {
  161. return be.daysShort[weekday]
  162. }
  163. // WeekdaysShort returns the locales short weekdays
  164. func (be *be) WeekdaysShort() []string {
  165. return be.daysShort
  166. }
  167. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  168. func (be *be) WeekdayWide(weekday time.Weekday) string {
  169. return be.daysWide[weekday]
  170. }
  171. // WeekdaysWide returns the locales wide weekdays
  172. func (be *be) WeekdaysWide() []string {
  173. return be.daysWide
  174. }
  175. // FmtNumber returns 'num' with digits/precision of 'v' for 'be' and handles both Whole and Real numbers based on 'v'
  176. func (be *be) FmtNumber(num float64, v uint64) string {
  177. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  178. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  179. count := 0
  180. inWhole := v == 0
  181. b := make([]byte, 0, l)
  182. for i := len(s) - 1; i >= 0; i-- {
  183. if s[i] == '.' {
  184. b = append(b, be.decimal[0])
  185. inWhole = true
  186. continue
  187. }
  188. if inWhole {
  189. if count == 3 {
  190. for j := len(be.group) - 1; j >= 0; j-- {
  191. b = append(b, be.group[j])
  192. }
  193. count = 1
  194. } else {
  195. count++
  196. }
  197. }
  198. b = append(b, s[i])
  199. }
  200. if num < 0 {
  201. b = append(b, be.minus[0])
  202. }
  203. // reverse
  204. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  205. b[i], b[j] = b[j], b[i]
  206. }
  207. return string(b)
  208. }
  209. // FmtPercent returns 'num' with digits/precision of 'v' for 'be' and handles both Whole and Real numbers based on 'v'
  210. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  211. func (be *be) FmtPercent(num float64, v uint64) string {
  212. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  213. l := len(s) + 5
  214. b := make([]byte, 0, l)
  215. for i := len(s) - 1; i >= 0; i-- {
  216. if s[i] == '.' {
  217. b = append(b, be.decimal[0])
  218. continue
  219. }
  220. b = append(b, s[i])
  221. }
  222. if num < 0 {
  223. b = append(b, be.minus[0])
  224. }
  225. // reverse
  226. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  227. b[i], b[j] = b[j], b[i]
  228. }
  229. b = append(b, be.percentSuffix...)
  230. b = append(b, be.percent...)
  231. return string(b)
  232. }
  233. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'be'
  234. func (be *be) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  235. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  236. symbol := be.currencies[currency]
  237. l := len(s) + len(symbol) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  238. count := 0
  239. inWhole := v == 0
  240. b := make([]byte, 0, l)
  241. for i := len(s) - 1; i >= 0; i-- {
  242. if s[i] == '.' {
  243. b = append(b, be.decimal[0])
  244. inWhole = true
  245. continue
  246. }
  247. if inWhole {
  248. if count == 3 {
  249. for j := len(be.group) - 1; j >= 0; j-- {
  250. b = append(b, be.group[j])
  251. }
  252. count = 1
  253. } else {
  254. count++
  255. }
  256. }
  257. b = append(b, s[i])
  258. }
  259. for j := len(symbol) - 1; j >= 0; j-- {
  260. b = append(b, symbol[j])
  261. }
  262. if num < 0 {
  263. b = append(b, be.minus[0])
  264. }
  265. // reverse
  266. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  267. b[i], b[j] = b[j], b[i]
  268. }
  269. if int(v) < 2 {
  270. if v == 0 {
  271. b = append(b, be.decimal...)
  272. }
  273. for i := 0; i < 2-int(v); i++ {
  274. b = append(b, '0')
  275. }
  276. }
  277. return string(b)
  278. }
  279. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'be'
  280. // in accounting notation.
  281. func (be *be) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  282. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  283. symbol := be.currencies[currency]
  284. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  285. count := 0
  286. inWhole := v == 0
  287. b := make([]byte, 0, l)
  288. for i := len(s) - 1; i >= 0; i-- {
  289. if s[i] == '.' {
  290. b = append(b, be.decimal[0])
  291. inWhole = true
  292. continue
  293. }
  294. if inWhole {
  295. if count == 3 {
  296. for j := len(be.group) - 1; j >= 0; j-- {
  297. b = append(b, be.group[j])
  298. }
  299. count = 1
  300. } else {
  301. count++
  302. }
  303. }
  304. b = append(b, s[i])
  305. }
  306. if num < 0 {
  307. for j := len(symbol) - 1; j >= 0; j-- {
  308. b = append(b, symbol[j])
  309. }
  310. b = append(b, be.currencyNegativePrefix[0])
  311. } else {
  312. for j := len(symbol) - 1; j >= 0; j-- {
  313. b = append(b, symbol[j])
  314. }
  315. }
  316. // reverse
  317. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  318. b[i], b[j] = b[j], b[i]
  319. }
  320. if int(v) < 2 {
  321. if v == 0 {
  322. b = append(b, be.decimal...)
  323. }
  324. for i := 0; i < 2-int(v); i++ {
  325. b = append(b, '0')
  326. }
  327. }
  328. if num < 0 {
  329. b = append(b, be.currencyNegativeSuffix...)
  330. }
  331. return string(b)
  332. }
  333. // FmtDateShort returns the short date representation of 't' for 'be'
  334. func (be *be) FmtDateShort(t time.Time) string {
  335. b := make([]byte, 0, 32)
  336. b = strconv.AppendInt(b, int64(t.Day()), 10)
  337. b = append(b, []byte{0x2e}...)
  338. b = strconv.AppendInt(b, int64(t.Month()), 10)
  339. b = append(b, []byte{0x2e}...)
  340. if t.Year() > 9 {
  341. b = append(b, strconv.Itoa(t.Year())[2:]...)
  342. } else {
  343. b = append(b, strconv.Itoa(t.Year())[1:]...)
  344. }
  345. return string(b)
  346. }
  347. // FmtDateMedium returns the medium date representation of 't' for 'be'
  348. func (be *be) FmtDateMedium(t time.Time) string {
  349. b := make([]byte, 0, 32)
  350. b = strconv.AppendInt(b, int64(t.Day()), 10)
  351. b = append(b, []byte{0x2e}...)
  352. b = strconv.AppendInt(b, int64(t.Month()), 10)
  353. b = append(b, []byte{0x2e}...)
  354. b = strconv.AppendInt(b, int64(t.Year()), 10)
  355. return string(b)
  356. }
  357. // FmtDateLong returns the long date representation of 't' for 'be'
  358. func (be *be) FmtDateLong(t time.Time) string {
  359. b := make([]byte, 0, 32)
  360. b = strconv.AppendInt(b, int64(t.Day()), 10)
  361. b = append(b, []byte{0x20}...)
  362. b = append(b, be.monthsWide[t.Month()]...)
  363. b = append(b, []byte{0x20}...)
  364. b = strconv.AppendInt(b, int64(t.Year()), 10)
  365. return string(b)
  366. }
  367. // FmtDateFull returns the full date representation of 't' for 'be'
  368. func (be *be) FmtDateFull(t time.Time) string {
  369. b := make([]byte, 0, 32)
  370. b = append(b, be.daysWide[t.Weekday()]...)
  371. b = append(b, []byte{0x2c, 0x20}...)
  372. b = strconv.AppendInt(b, int64(t.Day()), 10)
  373. b = append(b, []byte{0x20}...)
  374. b = append(b, be.monthsWide[t.Month()]...)
  375. b = append(b, []byte{0x20}...)
  376. b = strconv.AppendInt(b, int64(t.Year()), 10)
  377. return string(b)
  378. }
  379. // FmtTimeShort returns the short time representation of 't' for 'be'
  380. func (be *be) FmtTimeShort(t time.Time) string {
  381. b := make([]byte, 0, 32)
  382. if t.Hour() < 10 {
  383. b = append(b, '0')
  384. }
  385. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  386. b = append(b, []byte{0x2e}...)
  387. if t.Minute() < 10 {
  388. b = append(b, '0')
  389. }
  390. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  391. return string(b)
  392. }
  393. // FmtTimeMedium returns the medium time representation of 't' for 'be'
  394. func (be *be) FmtTimeMedium(t time.Time) string {
  395. b := make([]byte, 0, 32)
  396. if t.Hour() < 10 {
  397. b = append(b, '0')
  398. }
  399. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  400. b = append(b, []byte{0x2e}...)
  401. if t.Minute() < 10 {
  402. b = append(b, '0')
  403. }
  404. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  405. b = append(b, []byte{0x2e}...)
  406. if t.Second() < 10 {
  407. b = append(b, '0')
  408. }
  409. b = strconv.AppendInt(b, int64(t.Second()), 10)
  410. return string(b)
  411. }
  412. // FmtTimeLong returns the long time representation of 't' for 'be'
  413. func (be *be) FmtTimeLong(t time.Time) string {
  414. b := make([]byte, 0, 32)
  415. if t.Hour() < 10 {
  416. b = append(b, '0')
  417. }
  418. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  419. b = append(b, []byte{0x2e}...)
  420. if t.Minute() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  424. b = append(b, []byte{0x2e}...)
  425. if t.Second() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Second()), 10)
  429. b = append(b, []byte{0x20}...)
  430. tz, _ := t.Zone()
  431. b = append(b, tz...)
  432. return string(b)
  433. }
  434. // FmtTimeFull returns the full time representation of 't' for 'be'
  435. func (be *be) FmtTimeFull(t time.Time) string {
  436. b := make([]byte, 0, 32)
  437. if t.Hour() < 10 {
  438. b = append(b, '0')
  439. }
  440. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  441. b = append(b, []byte{0x2e}...)
  442. if t.Minute() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  446. b = append(b, []byte{0x2e}...)
  447. if t.Second() < 10 {
  448. b = append(b, '0')
  449. }
  450. b = strconv.AppendInt(b, int64(t.Second()), 10)
  451. b = append(b, []byte{0x20}...)
  452. tz, _ := t.Zone()
  453. if btz, ok := be.timezones[tz]; ok {
  454. b = append(b, btz...)
  455. } else {
  456. b = append(b, tz...)
  457. }
  458. return string(b)
  459. }