bem.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. package bem
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type bem 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. currencyNegativePrefix 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 'bem' locale
  41. func New() locales.Translator {
  42. return &bem{
  43. locale: "bem",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  47. timeSeparator: ":",
  48. currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "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", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CNY", "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", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "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", "MXN", "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", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "STN", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "K", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
  49. currencyNegativePrefix: "(",
  50. currencyNegativeSuffix: ")",
  51. monthsAbbreviated: []string{"", "Jan", "Feb", "Mac", "Epr", "Mei", "Jun", "Jul", "Oga", "Sep", "Okt", "Nov", "Dis"},
  52. monthsNarrow: []string{"", "J", "F", "M", "E", "M", "J", "J", "O", "S", "O", "N", "D"},
  53. monthsWide: []string{"", "Januari", "Februari", "Machi", "Epreo", "Mei", "Juni", "Julai", "Ogasti", "Septemba", "Oktoba", "Novemba", "Disemba"},
  54. daysWide: []string{"Pa Mulungu", "Palichimo", "Palichibuli", "Palichitatu", "Palichine", "Palichisano", "Pachibelushi"},
  55. periodsAbbreviated: []string{"uluchelo", "akasuba"},
  56. periodsWide: []string{"uluchelo", "akasuba"},
  57. erasAbbreviated: []string{"BC", "AD"},
  58. erasNarrow: []string{"", ""},
  59. erasWide: []string{"Before Yesu", "After Yesu"},
  60. timezones: map[string]string{"HADT": "HADT", "HECU": "HECU", "AWST": "AWST", "AWDT": "AWDT", "MDT": "MDT", "WIB": "WIB", "COST": "COST", "HAST": "HAST", "EST": "EST", "WART": "WART", "SGT": "SGT", "ACWDT": "ACWDT", "NZDT": "NZDT", "VET": "VET", "WAT": "WAT", "JST": "JST", "JDT": "JDT", "MEZ": "MEZ", "HENOMX": "HENOMX", "HNCU": "HNCU", "WEZ": "WEZ", "CHAST": "CHAST", "HEPMX": "HEPMX", "HEPM": "HEPM", "CLT": "CLT", "GMT": "GMT", "MST": "MST", "COT": "COT", "CHADT": "CHADT", "ACST": "ACST", "OESZ": "OESZ", "WAST": "WAST", "BOT": "BOT", "HEOG": "HEOG", "WARST": "WARST", "EAT": "EAT", "CDT": "CDT", "HNT": "HNT", "UYST": "UYST", "PDT": "PDT", "AKST": "AKST", "ACDT": "ACDT", "HNNOMX": "HNNOMX", "SRT": "SRT", "WESZ": "WESZ", "SAST": "SAST", "ARST": "ARST", "HNPM": "HNPM", "CLST": "CLST", "TMT": "TMT", "HNPMX": "HNPMX", "PST": "PST", "MESZ": "MESZ", "WITA": "WITA", "CAT": "CAT", "UYT": "UYT", "BT": "BT", "LHDT": "LHDT", "ART": "ART", "AEST": "AEST", "AST": "AST", "GFT": "GFT", "ECT": "ECT", "ACWST": "ACWST", "HEEG": "HEEG", "HNOG": "HNOG", "GYT": "GYT", "CST": "CST", "HKST": "HKST", "IST": "IST", "LHST": "LHST", "EDT": "EDT", "HKT": "HKT", "AEDT": "AEDT", "AKDT": "AKDT", "ChST": "ChST", "ADT": "ADT", "NZST": "NZST", "HNEG": "HNEG", "HAT": "HAT", "WIT": "WIT", "TMST": "TMST", "MYT": "MYT", "∅∅∅": "∅∅∅", "OEZ": "OEZ"},
  61. }
  62. }
  63. // Locale returns the current translators string locale
  64. func (bem *bem) Locale() string {
  65. return bem.locale
  66. }
  67. // PluralsCardinal returns the list of cardinal plural rules associated with 'bem'
  68. func (bem *bem) PluralsCardinal() []locales.PluralRule {
  69. return bem.pluralsCardinal
  70. }
  71. // PluralsOrdinal returns the list of ordinal plural rules associated with 'bem'
  72. func (bem *bem) PluralsOrdinal() []locales.PluralRule {
  73. return bem.pluralsOrdinal
  74. }
  75. // PluralsRange returns the list of range plural rules associated with 'bem'
  76. func (bem *bem) PluralsRange() []locales.PluralRule {
  77. return bem.pluralsRange
  78. }
  79. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'bem'
  80. func (bem *bem) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  81. n := math.Abs(num)
  82. if n == 1 {
  83. return locales.PluralRuleOne
  84. }
  85. return locales.PluralRuleOther
  86. }
  87. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'bem'
  88. func (bem *bem) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  89. return locales.PluralRuleUnknown
  90. }
  91. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'bem'
  92. func (bem *bem) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  93. return locales.PluralRuleUnknown
  94. }
  95. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  96. func (bem *bem) MonthAbbreviated(month time.Month) string {
  97. return bem.monthsAbbreviated[month]
  98. }
  99. // MonthsAbbreviated returns the locales abbreviated months
  100. func (bem *bem) MonthsAbbreviated() []string {
  101. return bem.monthsAbbreviated[1:]
  102. }
  103. // MonthNarrow returns the locales narrow month given the 'month' provided
  104. func (bem *bem) MonthNarrow(month time.Month) string {
  105. return bem.monthsNarrow[month]
  106. }
  107. // MonthsNarrow returns the locales narrow months
  108. func (bem *bem) MonthsNarrow() []string {
  109. return bem.monthsNarrow[1:]
  110. }
  111. // MonthWide returns the locales wide month given the 'month' provided
  112. func (bem *bem) MonthWide(month time.Month) string {
  113. return bem.monthsWide[month]
  114. }
  115. // MonthsWide returns the locales wide months
  116. func (bem *bem) MonthsWide() []string {
  117. return bem.monthsWide[1:]
  118. }
  119. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  120. func (bem *bem) WeekdayAbbreviated(weekday time.Weekday) string {
  121. return bem.daysAbbreviated[weekday]
  122. }
  123. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  124. func (bem *bem) WeekdaysAbbreviated() []string {
  125. return bem.daysAbbreviated
  126. }
  127. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  128. func (bem *bem) WeekdayNarrow(weekday time.Weekday) string {
  129. return bem.daysNarrow[weekday]
  130. }
  131. // WeekdaysNarrow returns the locales narrow weekdays
  132. func (bem *bem) WeekdaysNarrow() []string {
  133. return bem.daysNarrow
  134. }
  135. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  136. func (bem *bem) WeekdayShort(weekday time.Weekday) string {
  137. return bem.daysShort[weekday]
  138. }
  139. // WeekdaysShort returns the locales short weekdays
  140. func (bem *bem) WeekdaysShort() []string {
  141. return bem.daysShort
  142. }
  143. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  144. func (bem *bem) WeekdayWide(weekday time.Weekday) string {
  145. return bem.daysWide[weekday]
  146. }
  147. // WeekdaysWide returns the locales wide weekdays
  148. func (bem *bem) WeekdaysWide() []string {
  149. return bem.daysWide
  150. }
  151. // Decimal returns the decimal point of number
  152. func (bem *bem) Decimal() string {
  153. return bem.decimal
  154. }
  155. // Group returns the group of number
  156. func (bem *bem) Group() string {
  157. return bem.group
  158. }
  159. // Group returns the minus sign of number
  160. func (bem *bem) Minus() string {
  161. return bem.minus
  162. }
  163. // FmtNumber returns 'num' with digits/precision of 'v' for 'bem' and handles both Whole and Real numbers based on 'v'
  164. func (bem *bem) FmtNumber(num float64, v uint64) string {
  165. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  166. }
  167. // FmtPercent returns 'num' with digits/precision of 'v' for 'bem' and handles both Whole and Real numbers based on 'v'
  168. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  169. func (bem *bem) FmtPercent(num float64, v uint64) string {
  170. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  171. }
  172. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'bem'
  173. func (bem *bem) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  174. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  175. symbol := bem.currencies[currency]
  176. l := len(s) + len(symbol) + 0
  177. count := 0
  178. inWhole := v == 0
  179. b := make([]byte, 0, l)
  180. for i := len(s) - 1; i >= 0; i-- {
  181. if s[i] == '.' {
  182. b = append(b, bem.decimal[0])
  183. inWhole = true
  184. continue
  185. }
  186. if inWhole {
  187. if count == 3 {
  188. b = append(b, bem.group[0])
  189. count = 1
  190. } else {
  191. count++
  192. }
  193. }
  194. b = append(b, s[i])
  195. }
  196. for j := len(symbol) - 1; j >= 0; j-- {
  197. b = append(b, symbol[j])
  198. }
  199. if num < 0 {
  200. b = append(b, bem.minus[0])
  201. }
  202. // reverse
  203. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  204. b[i], b[j] = b[j], b[i]
  205. }
  206. if int(v) < 2 {
  207. if v == 0 {
  208. b = append(b, bem.decimal...)
  209. }
  210. for i := 0; i < 2-int(v); i++ {
  211. b = append(b, '0')
  212. }
  213. }
  214. return string(b)
  215. }
  216. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'bem'
  217. // in accounting notation.
  218. func (bem *bem) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  219. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  220. symbol := bem.currencies[currency]
  221. l := len(s) + len(symbol) + 2
  222. count := 0
  223. inWhole := v == 0
  224. b := make([]byte, 0, l)
  225. for i := len(s) - 1; i >= 0; i-- {
  226. if s[i] == '.' {
  227. b = append(b, bem.decimal[0])
  228. inWhole = true
  229. continue
  230. }
  231. if inWhole {
  232. if count == 3 {
  233. b = append(b, bem.group[0])
  234. count = 1
  235. } else {
  236. count++
  237. }
  238. }
  239. b = append(b, s[i])
  240. }
  241. if num < 0 {
  242. for j := len(symbol) - 1; j >= 0; j-- {
  243. b = append(b, symbol[j])
  244. }
  245. b = append(b, bem.currencyNegativePrefix[0])
  246. } else {
  247. for j := len(symbol) - 1; j >= 0; j-- {
  248. b = append(b, symbol[j])
  249. }
  250. }
  251. // reverse
  252. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  253. b[i], b[j] = b[j], b[i]
  254. }
  255. if int(v) < 2 {
  256. if v == 0 {
  257. b = append(b, bem.decimal...)
  258. }
  259. for i := 0; i < 2-int(v); i++ {
  260. b = append(b, '0')
  261. }
  262. }
  263. if num < 0 {
  264. b = append(b, bem.currencyNegativeSuffix...)
  265. }
  266. return string(b)
  267. }
  268. // FmtDateShort returns the short date representation of 't' for 'bem'
  269. func (bem *bem) FmtDateShort(t time.Time) string {
  270. b := make([]byte, 0, 32)
  271. if t.Day() < 10 {
  272. b = append(b, '0')
  273. }
  274. b = strconv.AppendInt(b, int64(t.Day()), 10)
  275. b = append(b, []byte{0x2f}...)
  276. if t.Month() < 10 {
  277. b = append(b, '0')
  278. }
  279. b = strconv.AppendInt(b, int64(t.Month()), 10)
  280. b = append(b, []byte{0x2f}...)
  281. if t.Year() > 0 {
  282. b = strconv.AppendInt(b, int64(t.Year()), 10)
  283. } else {
  284. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  285. }
  286. return string(b)
  287. }
  288. // FmtDateMedium returns the medium date representation of 't' for 'bem'
  289. func (bem *bem) FmtDateMedium(t time.Time) string {
  290. b := make([]byte, 0, 32)
  291. b = strconv.AppendInt(b, int64(t.Day()), 10)
  292. b = append(b, []byte{0x20}...)
  293. b = append(b, bem.monthsAbbreviated[t.Month()]...)
  294. b = append(b, []byte{0x20}...)
  295. if t.Year() > 0 {
  296. b = strconv.AppendInt(b, int64(t.Year()), 10)
  297. } else {
  298. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  299. }
  300. return string(b)
  301. }
  302. // FmtDateLong returns the long date representation of 't' for 'bem'
  303. func (bem *bem) FmtDateLong(t time.Time) string {
  304. b := make([]byte, 0, 32)
  305. b = strconv.AppendInt(b, int64(t.Day()), 10)
  306. b = append(b, []byte{0x20}...)
  307. b = append(b, bem.monthsWide[t.Month()]...)
  308. b = append(b, []byte{0x20}...)
  309. if t.Year() > 0 {
  310. b = strconv.AppendInt(b, int64(t.Year()), 10)
  311. } else {
  312. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  313. }
  314. return string(b)
  315. }
  316. // FmtDateFull returns the full date representation of 't' for 'bem'
  317. func (bem *bem) FmtDateFull(t time.Time) string {
  318. b := make([]byte, 0, 32)
  319. b = append(b, bem.daysWide[t.Weekday()]...)
  320. b = append(b, []byte{0x2c, 0x20}...)
  321. b = strconv.AppendInt(b, int64(t.Day()), 10)
  322. b = append(b, []byte{0x20}...)
  323. b = append(b, bem.monthsWide[t.Month()]...)
  324. b = append(b, []byte{0x20}...)
  325. if t.Year() > 0 {
  326. b = strconv.AppendInt(b, int64(t.Year()), 10)
  327. } else {
  328. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  329. }
  330. return string(b)
  331. }
  332. // FmtTimeShort returns the short time representation of 't' for 'bem'
  333. func (bem *bem) FmtTimeShort(t time.Time) string {
  334. b := make([]byte, 0, 32)
  335. h := t.Hour()
  336. if h > 12 {
  337. h -= 12
  338. }
  339. b = strconv.AppendInt(b, int64(h), 10)
  340. b = append(b, bem.timeSeparator...)
  341. if t.Minute() < 10 {
  342. b = append(b, '0')
  343. }
  344. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  345. b = append(b, []byte{0x20}...)
  346. if t.Hour() < 12 {
  347. b = append(b, bem.periodsAbbreviated[0]...)
  348. } else {
  349. b = append(b, bem.periodsAbbreviated[1]...)
  350. }
  351. return string(b)
  352. }
  353. // FmtTimeMedium returns the medium time representation of 't' for 'bem'
  354. func (bem *bem) FmtTimeMedium(t time.Time) string {
  355. b := make([]byte, 0, 32)
  356. h := t.Hour()
  357. if h > 12 {
  358. h -= 12
  359. }
  360. b = strconv.AppendInt(b, int64(h), 10)
  361. b = append(b, bem.timeSeparator...)
  362. if t.Minute() < 10 {
  363. b = append(b, '0')
  364. }
  365. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  366. b = append(b, bem.timeSeparator...)
  367. if t.Second() < 10 {
  368. b = append(b, '0')
  369. }
  370. b = strconv.AppendInt(b, int64(t.Second()), 10)
  371. b = append(b, []byte{0x20}...)
  372. if t.Hour() < 12 {
  373. b = append(b, bem.periodsAbbreviated[0]...)
  374. } else {
  375. b = append(b, bem.periodsAbbreviated[1]...)
  376. }
  377. return string(b)
  378. }
  379. // FmtTimeLong returns the long time representation of 't' for 'bem'
  380. func (bem *bem) FmtTimeLong(t time.Time) string {
  381. b := make([]byte, 0, 32)
  382. h := t.Hour()
  383. if h > 12 {
  384. h -= 12
  385. }
  386. b = strconv.AppendInt(b, int64(h), 10)
  387. b = append(b, bem.timeSeparator...)
  388. if t.Minute() < 10 {
  389. b = append(b, '0')
  390. }
  391. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  392. b = append(b, bem.timeSeparator...)
  393. if t.Second() < 10 {
  394. b = append(b, '0')
  395. }
  396. b = strconv.AppendInt(b, int64(t.Second()), 10)
  397. b = append(b, []byte{0x20}...)
  398. if t.Hour() < 12 {
  399. b = append(b, bem.periodsAbbreviated[0]...)
  400. } else {
  401. b = append(b, bem.periodsAbbreviated[1]...)
  402. }
  403. b = append(b, []byte{0x20}...)
  404. tz, _ := t.Zone()
  405. b = append(b, tz...)
  406. return string(b)
  407. }
  408. // FmtTimeFull returns the full time representation of 't' for 'bem'
  409. func (bem *bem) FmtTimeFull(t time.Time) string {
  410. b := make([]byte, 0, 32)
  411. h := t.Hour()
  412. if h > 12 {
  413. h -= 12
  414. }
  415. b = strconv.AppendInt(b, int64(h), 10)
  416. b = append(b, bem.timeSeparator...)
  417. if t.Minute() < 10 {
  418. b = append(b, '0')
  419. }
  420. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  421. b = append(b, bem.timeSeparator...)
  422. if t.Second() < 10 {
  423. b = append(b, '0')
  424. }
  425. b = strconv.AppendInt(b, int64(t.Second()), 10)
  426. b = append(b, []byte{0x20}...)
  427. if t.Hour() < 12 {
  428. b = append(b, bem.periodsAbbreviated[0]...)
  429. } else {
  430. b = append(b, bem.periodsAbbreviated[1]...)
  431. }
  432. b = append(b, []byte{0x20}...)
  433. tz, _ := t.Zone()
  434. if btz, ok := bem.timezones[tz]; ok {
  435. b = append(b, btz...)
  436. } else {
  437. b = append(b, tz...)
  438. }
  439. return string(b)
  440. }