bas.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. package bas
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type bas 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. currencyPositiveSuffix 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 'bas' locale
  42. func New() locales.Translator {
  43. return &bas{
  44. locale: "bas",
  45. pluralsCardinal: nil,
  46. pluralsOrdinal: nil,
  47. pluralsRange: nil,
  48. decimal: ",",
  49. group: " ",
  50. timeSeparator: ":",
  51. 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", "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", "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", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
  52. percentSuffix: " ",
  53. currencyPositiveSuffix: " ",
  54. currencyNegativeSuffix: " ",
  55. monthsAbbreviated: []string{"", "kɔn", "mac", "mat", "mto", "mpu", "hil", "nje", "hik", "dip", "bio", "may", "liɓ"},
  56. monthsNarrow: []string{"", "k", "m", "m", "m", "m", "h", "n", "h", "d", "b", "m", "l"},
  57. monthsWide: []string{"", "Kɔndɔŋ", "Màcɛ̂l", "Màtùmb", "Màtop", "M̀puyɛ", "Hìlòndɛ̀", "Njèbà", "Hìkaŋ", "Dìpɔ̀s", "Bìòôm", "Màyɛsèp", "Lìbuy li ńyèe"},
  58. daysAbbreviated: []string{"nɔy", "nja", "uum", "ŋge", "mbɔ", "kɔɔ", "jon"},
  59. daysNarrow: []string{"n", "n", "u", "ŋ", "m", "k", "j"},
  60. daysWide: []string{"ŋgwà nɔ̂y", "ŋgwà njaŋgumba", "ŋgwà ûm", "ŋgwà ŋgê", "ŋgwà mbɔk", "ŋgwà kɔɔ", "ŋgwà jôn"},
  61. periodsAbbreviated: []string{"I bikɛ̂glà", "I ɓugajɔp"},
  62. periodsWide: []string{"I bikɛ̂glà", "I ɓugajɔp"},
  63. erasAbbreviated: []string{"b.Y.K", "m.Y.K"},
  64. erasNarrow: []string{"", ""},
  65. erasWide: []string{"bisū bi Yesù Krǐstò", "i mbūs Yesù Krǐstò"},
  66. timezones: map[string]string{"MESZ": "MESZ", "SAST": "SAST", "WARST": "WARST", "VET": "VET", "NZDT": "NZDT", "JDT": "JDT", "ACST": "ACST", "WAT": "WAT", "HECU": "HECU", "HNPMX": "HNPMX", "HKST": "HKST", "AST": "AST", "EST": "EST", "MST": "MST", "ART": "ART", "HNT": "HNT", "HKT": "HKT", "CHADT": "CHADT", "COST": "COST", "HENOMX": "HENOMX", "CST": "CST", "MEZ": "MEZ", "JST": "JST", "CLST": "CLST", "GMT": "GMT", "SRT": "SRT", "HNOG": "HNOG", "HAT": "HAT", "AWST": "AWST", "WITA": "WITA", "HEPM": "HEPM", "GYT": "GYT", "HADT": "HADT", "HEOG": "HEOG", "AKST": "AKST", "AEST": "AEST", "CHAST": "CHAST", "CLT": "CLT", "∅∅∅": "∅∅∅", "WAST": "WAST", "UYST": "UYST", "HAST": "HAST", "ACWST": "ACWST", "AEDT": "AEDT", "LHST": "LHST", "HNNOMX": "HNNOMX", "HEPMX": "HEPMX", "BT": "BT", "ARST": "ARST", "ChST": "ChST", "ECT": "ECT", "WESZ": "WESZ", "AWDT": "AWDT", "BOT": "BOT", "NZST": "NZST", "GFT": "GFT", "OEZ": "OEZ", "MYT": "MYT", "UYT": "UYT", "MDT": "MDT", "WIB": "WIB", "HNPM": "HNPM", "HNEG": "HNEG", "OESZ": "OESZ", "SGT": "SGT", "EDT": "EDT", "WIT": "WIT", "PST": "PST", "IST": "IST", "WART": "WART", "CDT": "CDT", "TMT": "TMT", "HEEG": "HEEG", "EAT": "EAT", "COT": "COT", "PDT": "PDT", "WEZ": "WEZ", "ACWDT": "ACWDT", "LHDT": "LHDT", "TMST": "TMST", "ACDT": "ACDT", "CAT": "CAT", "HNCU": "HNCU", "ADT": "ADT", "AKDT": "AKDT"},
  67. }
  68. }
  69. // Locale returns the current translators string locale
  70. func (bas *bas) Locale() string {
  71. return bas.locale
  72. }
  73. // PluralsCardinal returns the list of cardinal plural rules associated with 'bas'
  74. func (bas *bas) PluralsCardinal() []locales.PluralRule {
  75. return bas.pluralsCardinal
  76. }
  77. // PluralsOrdinal returns the list of ordinal plural rules associated with 'bas'
  78. func (bas *bas) PluralsOrdinal() []locales.PluralRule {
  79. return bas.pluralsOrdinal
  80. }
  81. // PluralsRange returns the list of range plural rules associated with 'bas'
  82. func (bas *bas) PluralsRange() []locales.PluralRule {
  83. return bas.pluralsRange
  84. }
  85. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'bas'
  86. func (bas *bas) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  87. return locales.PluralRuleUnknown
  88. }
  89. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'bas'
  90. func (bas *bas) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. return locales.PluralRuleUnknown
  92. }
  93. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'bas'
  94. func (bas *bas) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  95. return locales.PluralRuleUnknown
  96. }
  97. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  98. func (bas *bas) MonthAbbreviated(month time.Month) string {
  99. return bas.monthsAbbreviated[month]
  100. }
  101. // MonthsAbbreviated returns the locales abbreviated months
  102. func (bas *bas) MonthsAbbreviated() []string {
  103. return bas.monthsAbbreviated[1:]
  104. }
  105. // MonthNarrow returns the locales narrow month given the 'month' provided
  106. func (bas *bas) MonthNarrow(month time.Month) string {
  107. return bas.monthsNarrow[month]
  108. }
  109. // MonthsNarrow returns the locales narrow months
  110. func (bas *bas) MonthsNarrow() []string {
  111. return bas.monthsNarrow[1:]
  112. }
  113. // MonthWide returns the locales wide month given the 'month' provided
  114. func (bas *bas) MonthWide(month time.Month) string {
  115. return bas.monthsWide[month]
  116. }
  117. // MonthsWide returns the locales wide months
  118. func (bas *bas) MonthsWide() []string {
  119. return bas.monthsWide[1:]
  120. }
  121. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  122. func (bas *bas) WeekdayAbbreviated(weekday time.Weekday) string {
  123. return bas.daysAbbreviated[weekday]
  124. }
  125. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  126. func (bas *bas) WeekdaysAbbreviated() []string {
  127. return bas.daysAbbreviated
  128. }
  129. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  130. func (bas *bas) WeekdayNarrow(weekday time.Weekday) string {
  131. return bas.daysNarrow[weekday]
  132. }
  133. // WeekdaysNarrow returns the locales narrow weekdays
  134. func (bas *bas) WeekdaysNarrow() []string {
  135. return bas.daysNarrow
  136. }
  137. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  138. func (bas *bas) WeekdayShort(weekday time.Weekday) string {
  139. return bas.daysShort[weekday]
  140. }
  141. // WeekdaysShort returns the locales short weekdays
  142. func (bas *bas) WeekdaysShort() []string {
  143. return bas.daysShort
  144. }
  145. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  146. func (bas *bas) WeekdayWide(weekday time.Weekday) string {
  147. return bas.daysWide[weekday]
  148. }
  149. // WeekdaysWide returns the locales wide weekdays
  150. func (bas *bas) WeekdaysWide() []string {
  151. return bas.daysWide
  152. }
  153. // FmtNumber returns 'num' with digits/precision of 'v' for 'bas' and handles both Whole and Real numbers based on 'v'
  154. func (bas *bas) FmtNumber(num float64, v uint64) string {
  155. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  156. l := len(s) + 1 + 2*len(s[:len(s)-int(v)-1])/3
  157. count := 0
  158. inWhole := v == 0
  159. b := make([]byte, 0, l)
  160. for i := len(s) - 1; i >= 0; i-- {
  161. if s[i] == '.' {
  162. b = append(b, bas.decimal[0])
  163. inWhole = true
  164. continue
  165. }
  166. if inWhole {
  167. if count == 3 {
  168. for j := len(bas.group) - 1; j >= 0; j-- {
  169. b = append(b, bas.group[j])
  170. }
  171. count = 1
  172. } else {
  173. count++
  174. }
  175. }
  176. b = append(b, s[i])
  177. }
  178. if num < 0 {
  179. b = append(b, bas.minus[0])
  180. }
  181. // reverse
  182. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  183. b[i], b[j] = b[j], b[i]
  184. }
  185. return string(b)
  186. }
  187. // FmtPercent returns 'num' with digits/precision of 'v' for 'bas' and handles both Whole and Real numbers based on 'v'
  188. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  189. func (bas *bas) FmtPercent(num float64, v uint64) string {
  190. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  191. l := len(s) + 3
  192. b := make([]byte, 0, l)
  193. for i := len(s) - 1; i >= 0; i-- {
  194. if s[i] == '.' {
  195. b = append(b, bas.decimal[0])
  196. continue
  197. }
  198. b = append(b, s[i])
  199. }
  200. if num < 0 {
  201. b = append(b, bas.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. b = append(b, bas.percentSuffix...)
  208. b = append(b, bas.percent...)
  209. return string(b)
  210. }
  211. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'bas'
  212. func (bas *bas) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  213. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  214. symbol := bas.currencies[currency]
  215. l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
  216. count := 0
  217. inWhole := v == 0
  218. b := make([]byte, 0, l)
  219. for i := len(s) - 1; i >= 0; i-- {
  220. if s[i] == '.' {
  221. b = append(b, bas.decimal[0])
  222. inWhole = true
  223. continue
  224. }
  225. if inWhole {
  226. if count == 3 {
  227. for j := len(bas.group) - 1; j >= 0; j-- {
  228. b = append(b, bas.group[j])
  229. }
  230. count = 1
  231. } else {
  232. count++
  233. }
  234. }
  235. b = append(b, s[i])
  236. }
  237. if num < 0 {
  238. b = append(b, bas.minus[0])
  239. }
  240. // reverse
  241. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  242. b[i], b[j] = b[j], b[i]
  243. }
  244. if int(v) < 2 {
  245. if v == 0 {
  246. b = append(b, bas.decimal...)
  247. }
  248. for i := 0; i < 2-int(v); i++ {
  249. b = append(b, '0')
  250. }
  251. }
  252. b = append(b, bas.currencyPositiveSuffix...)
  253. b = append(b, symbol...)
  254. return string(b)
  255. }
  256. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'bas'
  257. // in accounting notation.
  258. func (bas *bas) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  259. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  260. symbol := bas.currencies[currency]
  261. l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
  262. count := 0
  263. inWhole := v == 0
  264. b := make([]byte, 0, l)
  265. for i := len(s) - 1; i >= 0; i-- {
  266. if s[i] == '.' {
  267. b = append(b, bas.decimal[0])
  268. inWhole = true
  269. continue
  270. }
  271. if inWhole {
  272. if count == 3 {
  273. for j := len(bas.group) - 1; j >= 0; j-- {
  274. b = append(b, bas.group[j])
  275. }
  276. count = 1
  277. } else {
  278. count++
  279. }
  280. }
  281. b = append(b, s[i])
  282. }
  283. if num < 0 {
  284. b = append(b, bas.minus[0])
  285. }
  286. // reverse
  287. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  288. b[i], b[j] = b[j], b[i]
  289. }
  290. if int(v) < 2 {
  291. if v == 0 {
  292. b = append(b, bas.decimal...)
  293. }
  294. for i := 0; i < 2-int(v); i++ {
  295. b = append(b, '0')
  296. }
  297. }
  298. if num < 0 {
  299. b = append(b, bas.currencyNegativeSuffix...)
  300. b = append(b, symbol...)
  301. } else {
  302. b = append(b, bas.currencyPositiveSuffix...)
  303. b = append(b, symbol...)
  304. }
  305. return string(b)
  306. }
  307. // FmtDateShort returns the short date representation of 't' for 'bas'
  308. func (bas *bas) FmtDateShort(t time.Time) string {
  309. b := make([]byte, 0, 32)
  310. b = strconv.AppendInt(b, int64(t.Day()), 10)
  311. b = append(b, []byte{0x2f}...)
  312. b = strconv.AppendInt(b, int64(t.Month()), 10)
  313. b = append(b, []byte{0x2f}...)
  314. if t.Year() > 0 {
  315. b = strconv.AppendInt(b, int64(t.Year()), 10)
  316. } else {
  317. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  318. }
  319. return string(b)
  320. }
  321. // FmtDateMedium returns the medium date representation of 't' for 'bas'
  322. func (bas *bas) FmtDateMedium(t time.Time) string {
  323. b := make([]byte, 0, 32)
  324. b = strconv.AppendInt(b, int64(t.Day()), 10)
  325. b = append(b, []byte{0x20}...)
  326. b = append(b, bas.monthsAbbreviated[t.Month()]...)
  327. b = append(b, []byte{0x2c, 0x20}...)
  328. if t.Year() > 0 {
  329. b = strconv.AppendInt(b, int64(t.Year()), 10)
  330. } else {
  331. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  332. }
  333. return string(b)
  334. }
  335. // FmtDateLong returns the long date representation of 't' for 'bas'
  336. func (bas *bas) FmtDateLong(t time.Time) string {
  337. b := make([]byte, 0, 32)
  338. b = strconv.AppendInt(b, int64(t.Day()), 10)
  339. b = append(b, []byte{0x20}...)
  340. b = append(b, bas.monthsWide[t.Month()]...)
  341. b = append(b, []byte{0x20}...)
  342. if t.Year() > 0 {
  343. b = strconv.AppendInt(b, int64(t.Year()), 10)
  344. } else {
  345. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  346. }
  347. return string(b)
  348. }
  349. // FmtDateFull returns the full date representation of 't' for 'bas'
  350. func (bas *bas) FmtDateFull(t time.Time) string {
  351. b := make([]byte, 0, 32)
  352. b = append(b, bas.daysWide[t.Weekday()]...)
  353. b = append(b, []byte{0x20}...)
  354. b = strconv.AppendInt(b, int64(t.Day()), 10)
  355. b = append(b, []byte{0x20}...)
  356. b = append(b, bas.monthsWide[t.Month()]...)
  357. b = append(b, []byte{0x20}...)
  358. if t.Year() > 0 {
  359. b = strconv.AppendInt(b, int64(t.Year()), 10)
  360. } else {
  361. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  362. }
  363. return string(b)
  364. }
  365. // FmtTimeShort returns the short time representation of 't' for 'bas'
  366. func (bas *bas) FmtTimeShort(t time.Time) string {
  367. b := make([]byte, 0, 32)
  368. if t.Hour() < 10 {
  369. b = append(b, '0')
  370. }
  371. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  372. b = append(b, bas.timeSeparator...)
  373. if t.Minute() < 10 {
  374. b = append(b, '0')
  375. }
  376. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  377. return string(b)
  378. }
  379. // FmtTimeMedium returns the medium time representation of 't' for 'bas'
  380. func (bas *bas) FmtTimeMedium(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, bas.timeSeparator...)
  387. if t.Minute() < 10 {
  388. b = append(b, '0')
  389. }
  390. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  391. b = append(b, bas.timeSeparator...)
  392. if t.Second() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Second()), 10)
  396. return string(b)
  397. }
  398. // FmtTimeLong returns the long time representation of 't' for 'bas'
  399. func (bas *bas) FmtTimeLong(t time.Time) string {
  400. b := make([]byte, 0, 32)
  401. if t.Hour() < 10 {
  402. b = append(b, '0')
  403. }
  404. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  405. b = append(b, bas.timeSeparator...)
  406. if t.Minute() < 10 {
  407. b = append(b, '0')
  408. }
  409. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  410. b = append(b, bas.timeSeparator...)
  411. if t.Second() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Second()), 10)
  415. b = append(b, []byte{0x20}...)
  416. tz, _ := t.Zone()
  417. b = append(b, tz...)
  418. return string(b)
  419. }
  420. // FmtTimeFull returns the full time representation of 't' for 'bas'
  421. func (bas *bas) FmtTimeFull(t time.Time) string {
  422. b := make([]byte, 0, 32)
  423. if t.Hour() < 10 {
  424. b = append(b, '0')
  425. }
  426. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  427. b = append(b, bas.timeSeparator...)
  428. if t.Minute() < 10 {
  429. b = append(b, '0')
  430. }
  431. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  432. b = append(b, bas.timeSeparator...)
  433. if t.Second() < 10 {
  434. b = append(b, '0')
  435. }
  436. b = strconv.AppendInt(b, int64(t.Second()), 10)
  437. b = append(b, []byte{0x20}...)
  438. tz, _ := t.Zone()
  439. if btz, ok := bas.timezones[tz]; ok {
  440. b = append(b, btz...)
  441. } else {
  442. b = append(b, tz...)
  443. }
  444. return string(b)
  445. }