tk.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. package tk
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type tk 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 'tk' locale
  42. func New() locales.Translator {
  43. return &tk{
  44. locale: "tk",
  45. pluralsCardinal: []locales.PluralRule{2, 6},
  46. pluralsOrdinal: nil,
  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 ", "R$", "BRN ", "BRR ", "BRZ ", "BSD", "BTN", "BUK ", "BWP", "BYB ", "BYR", "BZD", "CA$", "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", "EUR", "FIM ", "FJD", "FKP", "FRF ", "GBP", "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", "JP¥", "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", "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", "NT$", "TZS", "UAH", "UAK ", "UGS ", "UGX", "US$", "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. currencyPositiveSuffix: " ",
  58. currencyNegativeSuffix: " ",
  59. monthsAbbreviated: []string{"", "ýan", "few", "mart", "apr", "maý", "iýun", "iýul", "awg", "sen", "okt", "noý", "dek"},
  60. monthsNarrow: []string{"", "Ý", "F", "M", "A", "M", "I", "I", "A", "S", "O", "N", "D"},
  61. monthsWide: []string{"", "ýanwar", "fewral", "mart", "aprel", "maý", "iýun", "iýul", "awgust", "sentýabr", "oktýabr", "noýabr", "dekabr"},
  62. daysAbbreviated: []string{"ýb", "db", "sb", "çb", "pb", "an", "şb"},
  63. daysNarrow: []string{"Ý", "D", "S", "Ç", "P", "A", "Ş"},
  64. daysWide: []string{"ýekşenbe", "duşenbe", "sişenbe", "çarşenbe", "penşenbe", "anna", "şenbe"},
  65. timezones: map[string]string{"WESZ": "Günbatar Ýewropa, tomusky wagt", "ACWST": "Merkezi Awstraliýa, günbatar tarap, standart wagt", "WAT": "Günbatar Afrika, standart wagt", "BT": "Butan", "WIT": "Gündogar Indoneziýa", "TMT": "Türkmenistan, standart wagt", "CLT": "Çili, standart wagt", "AEDT": "Gündogar Awstraliýa, tomusky wagt", "ACST": "Merkezi Awstraliýa, standart wagt", "BOT": "Boliwiýa", "CHADT": "Çatem, tomusky wagt", "LHDT": "Lord-Hau, tomusky wagt", "WAST": "Günbatar Afrika, tomusky wagt", "GMT": "Grinwiç boýunça orta wagt", "PDT": "Ýuwaş umman, tomusky wagt", "AWDT": "Günbatar Awstraliýa, tomusky wagt", "SRT": "Surinam", "UYT": "Urugwaý, standart wagt", "EDT": "Günorta Amerika, tomusky wagt", "COST": "Kolumbiýa, tomusky wagt", "AST": "Atlantika, standart wagt", "HAT": "Nýufaundlend, tomusky wagt", "TMST": "Türkmenistan, tomusky wagt", "JDT": "Ýaponiýa, tomusky wagt", "HADT": "Gawaý-Aleut, tomusky wagt", "WART": "Günbatar Argentina, standart wagt", "AKST": "Alýaska, standart wagt", "LHST": "Lord-Hau, standart wagt", "NZDT": "Täze Zelandiýa, tomusky wagt", "JST": "Ýaponiýa, standart wagt", "CHAST": "Çatem, standart wagt", "CAT": "Merkezi Afrika", "EST": "Günorta Amerika, standart wagt", "SGT": "Singapur, standart wagt", "WIB": "Günbatar Indoneziýa", "OEZ": "Gündogar Ýewropa, standart wagt", "∅∅∅": "Amazonka, tomusky wagt", "SAST": "Günorta Afrika, standart wagt", "HNT": "Nýufaundlend, standart wagt", "ACDT": "Merkezi Awstraliýa, tomusky wagt", "VET": "Wenesuela", "AWST": "Günbatar Awstraliýa, standart wagt", "NZST": "Täze Zelandiýa, standart wagt", "OESZ": "Gündogar Ýewropa, tomusky wagt", "MYT": "Malaýziýa", "AKDT": "Alýaska, tomusky wagt", "ART": "Argentina, standart wagt", "CLST": "Çili, tomusky wagt", "ACWDT": "Merkezi Awstraliýa, günbatar tarap, tomusky wagt", "WITA": "Merkezi Indoneziýa", "EAT": "Gündogar Afrika", "MST": "MST", "WARST": "Günbatar Argentina, tomusky wagt", "GFT": "Fransuz Gwiana", "PST": "Ýuwaş umman, standart wagt", "COT": "Kolumbiýa, standart wagt", "CDT": "Merkezi Amerika, tomusky wagt", "AEST": "Gündogar Awstraliýa, standart wagt", "MEZ": "Merkezi Ýewropa, standart wagt", "UYST": "Urugwaý, tomusky wagt", "WEZ": "Günbatar Ýewropa, standart wagt", "HKT": "Gonkong, standart wagt", "GYT": "Gaýana", "CST": "Merkezi Amerika, standart wagt", "MESZ": "Merkezi Ýewropa, tomusky wagt", "HAST": "Gawaý-Aleut, standart wagt", "MDT": "MDT", "ARST": "Argentina, tomusky wagt", "ECT": "Ekwador", "HKST": "Gonkong, tomusky wagt", "IST": "Hindistan", "ChST": "Çamorro", "ADT": "Atlantika, tomusky wagt"},
  66. }
  67. }
  68. // Locale returns the current translators string locale
  69. func (tk *tk) Locale() string {
  70. return tk.locale
  71. }
  72. // PluralsCardinal returns the list of cardinal plural rules associated with 'tk'
  73. func (tk *tk) PluralsCardinal() []locales.PluralRule {
  74. return tk.pluralsCardinal
  75. }
  76. // PluralsOrdinal returns the list of ordinal plural rules associated with 'tk'
  77. func (tk *tk) PluralsOrdinal() []locales.PluralRule {
  78. return tk.pluralsOrdinal
  79. }
  80. // PluralsRange returns the list of range plural rules associated with 'tk'
  81. func (tk *tk) PluralsRange() []locales.PluralRule {
  82. return tk.pluralsRange
  83. }
  84. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'tk'
  85. func (tk *tk) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  86. n := math.Abs(num)
  87. if n == 1 {
  88. return locales.PluralRuleOne
  89. }
  90. return locales.PluralRuleOther
  91. }
  92. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'tk'
  93. func (tk *tk) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  94. return locales.PluralRuleUnknown
  95. }
  96. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'tk'
  97. func (tk *tk) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  98. return locales.PluralRuleUnknown
  99. }
  100. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  101. func (tk *tk) MonthAbbreviated(month time.Month) string {
  102. return tk.monthsAbbreviated[month]
  103. }
  104. // MonthsAbbreviated returns the locales abbreviated months
  105. func (tk *tk) MonthsAbbreviated() []string {
  106. return tk.monthsAbbreviated[1:]
  107. }
  108. // MonthNarrow returns the locales narrow month given the 'month' provided
  109. func (tk *tk) MonthNarrow(month time.Month) string {
  110. return tk.monthsNarrow[month]
  111. }
  112. // MonthsNarrow returns the locales narrow months
  113. func (tk *tk) MonthsNarrow() []string {
  114. return tk.monthsNarrow[1:]
  115. }
  116. // MonthWide returns the locales wide month given the 'month' provided
  117. func (tk *tk) MonthWide(month time.Month) string {
  118. return tk.monthsWide[month]
  119. }
  120. // MonthsWide returns the locales wide months
  121. func (tk *tk) MonthsWide() []string {
  122. return tk.monthsWide[1:]
  123. }
  124. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  125. func (tk *tk) WeekdayAbbreviated(weekday time.Weekday) string {
  126. return tk.daysAbbreviated[weekday]
  127. }
  128. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  129. func (tk *tk) WeekdaysAbbreviated() []string {
  130. return tk.daysAbbreviated
  131. }
  132. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  133. func (tk *tk) WeekdayNarrow(weekday time.Weekday) string {
  134. return tk.daysNarrow[weekday]
  135. }
  136. // WeekdaysNarrow returns the locales narrow weekdays
  137. func (tk *tk) WeekdaysNarrow() []string {
  138. return tk.daysNarrow
  139. }
  140. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  141. func (tk *tk) WeekdayShort(weekday time.Weekday) string {
  142. return tk.daysShort[weekday]
  143. }
  144. // WeekdaysShort returns the locales short weekdays
  145. func (tk *tk) WeekdaysShort() []string {
  146. return tk.daysShort
  147. }
  148. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  149. func (tk *tk) WeekdayWide(weekday time.Weekday) string {
  150. return tk.daysWide[weekday]
  151. }
  152. // WeekdaysWide returns the locales wide weekdays
  153. func (tk *tk) WeekdaysWide() []string {
  154. return tk.daysWide
  155. }
  156. // FmtNumber returns 'num' with digits/precision of 'v' for 'tk' and handles both Whole and Real numbers based on 'v'
  157. func (tk *tk) FmtNumber(num float64, v uint64) string {
  158. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  159. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  160. count := 0
  161. inWhole := v == 0
  162. b := make([]byte, 0, l)
  163. for i := len(s) - 1; i >= 0; i-- {
  164. if s[i] == '.' {
  165. b = append(b, tk.decimal[0])
  166. inWhole = true
  167. continue
  168. }
  169. if inWhole {
  170. if count == 3 {
  171. for j := len(tk.group) - 1; j >= 0; j-- {
  172. b = append(b, tk.group[j])
  173. }
  174. count = 1
  175. } else {
  176. count++
  177. }
  178. }
  179. b = append(b, s[i])
  180. }
  181. if num < 0 {
  182. b = append(b, tk.minus[0])
  183. }
  184. // reverse
  185. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  186. b[i], b[j] = b[j], b[i]
  187. }
  188. return string(b)
  189. }
  190. // FmtPercent returns 'num' with digits/precision of 'v' for 'tk' and handles both Whole and Real numbers based on 'v'
  191. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  192. func (tk *tk) FmtPercent(num float64, v uint64) string {
  193. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  194. l := len(s) + 5
  195. b := make([]byte, 0, l)
  196. for i := len(s) - 1; i >= 0; i-- {
  197. if s[i] == '.' {
  198. b = append(b, tk.decimal[0])
  199. continue
  200. }
  201. b = append(b, s[i])
  202. }
  203. if num < 0 {
  204. b = append(b, tk.minus[0])
  205. }
  206. // reverse
  207. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  208. b[i], b[j] = b[j], b[i]
  209. }
  210. b = append(b, tk.percentSuffix...)
  211. b = append(b, tk.percent...)
  212. return string(b)
  213. }
  214. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'tk'
  215. func (tk *tk) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  216. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  217. symbol := tk.currencies[currency]
  218. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  219. count := 0
  220. inWhole := v == 0
  221. b := make([]byte, 0, l)
  222. for i := len(s) - 1; i >= 0; i-- {
  223. if s[i] == '.' {
  224. b = append(b, tk.decimal[0])
  225. inWhole = true
  226. continue
  227. }
  228. if inWhole {
  229. if count == 3 {
  230. for j := len(tk.group) - 1; j >= 0; j-- {
  231. b = append(b, tk.group[j])
  232. }
  233. count = 1
  234. } else {
  235. count++
  236. }
  237. }
  238. b = append(b, s[i])
  239. }
  240. if num < 0 {
  241. b = append(b, tk.minus[0])
  242. }
  243. // reverse
  244. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  245. b[i], b[j] = b[j], b[i]
  246. }
  247. if int(v) < 2 {
  248. if v == 0 {
  249. b = append(b, tk.decimal...)
  250. }
  251. for i := 0; i < 2-int(v); i++ {
  252. b = append(b, '0')
  253. }
  254. }
  255. b = append(b, tk.currencyPositiveSuffix...)
  256. b = append(b, symbol...)
  257. return string(b)
  258. }
  259. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'tk'
  260. // in accounting notation.
  261. func (tk *tk) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  262. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  263. symbol := tk.currencies[currency]
  264. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  265. count := 0
  266. inWhole := v == 0
  267. b := make([]byte, 0, l)
  268. for i := len(s) - 1; i >= 0; i-- {
  269. if s[i] == '.' {
  270. b = append(b, tk.decimal[0])
  271. inWhole = true
  272. continue
  273. }
  274. if inWhole {
  275. if count == 3 {
  276. for j := len(tk.group) - 1; j >= 0; j-- {
  277. b = append(b, tk.group[j])
  278. }
  279. count = 1
  280. } else {
  281. count++
  282. }
  283. }
  284. b = append(b, s[i])
  285. }
  286. if num < 0 {
  287. b = append(b, tk.minus[0])
  288. }
  289. // reverse
  290. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  291. b[i], b[j] = b[j], b[i]
  292. }
  293. if int(v) < 2 {
  294. if v == 0 {
  295. b = append(b, tk.decimal...)
  296. }
  297. for i := 0; i < 2-int(v); i++ {
  298. b = append(b, '0')
  299. }
  300. }
  301. if num < 0 {
  302. b = append(b, tk.currencyNegativeSuffix...)
  303. b = append(b, symbol...)
  304. } else {
  305. b = append(b, tk.currencyPositiveSuffix...)
  306. b = append(b, symbol...)
  307. }
  308. return string(b)
  309. }
  310. // FmtDateShort returns the short date representation of 't' for 'tk'
  311. func (tk *tk) FmtDateShort(t time.Time) string {
  312. b := make([]byte, 0, 32)
  313. if t.Day() < 10 {
  314. b = append(b, '0')
  315. }
  316. b = strconv.AppendInt(b, int64(t.Day()), 10)
  317. b = append(b, []byte{0x2e}...)
  318. if t.Month() < 10 {
  319. b = append(b, '0')
  320. }
  321. b = strconv.AppendInt(b, int64(t.Month()), 10)
  322. b = append(b, []byte{0x2e}...)
  323. b = strconv.AppendInt(b, int64(t.Year()), 10)
  324. return string(b)
  325. }
  326. // FmtDateMedium returns the medium date representation of 't' for 'tk'
  327. func (tk *tk) FmtDateMedium(t time.Time) string {
  328. b := make([]byte, 0, 32)
  329. b = strconv.AppendInt(b, int64(t.Day()), 10)
  330. b = append(b, []byte{0x20}...)
  331. b = append(b, tk.monthsAbbreviated[t.Month()]...)
  332. b = append(b, []byte{0x20}...)
  333. b = strconv.AppendInt(b, int64(t.Year()), 10)
  334. return string(b)
  335. }
  336. // FmtDateLong returns the long date representation of 't' for 'tk'
  337. func (tk *tk) FmtDateLong(t time.Time) string {
  338. b := make([]byte, 0, 32)
  339. b = strconv.AppendInt(b, int64(t.Day()), 10)
  340. b = append(b, []byte{0x20}...)
  341. b = append(b, tk.monthsWide[t.Month()]...)
  342. b = append(b, []byte{0x20}...)
  343. b = strconv.AppendInt(b, int64(t.Year()), 10)
  344. return string(b)
  345. }
  346. // FmtDateFull returns the full date representation of 't' for 'tk'
  347. func (tk *tk) FmtDateFull(t time.Time) string {
  348. b := make([]byte, 0, 32)
  349. b = strconv.AppendInt(b, int64(t.Day()), 10)
  350. b = append(b, []byte{0x20}...)
  351. b = append(b, tk.monthsWide[t.Month()]...)
  352. b = append(b, []byte{0x20}...)
  353. b = strconv.AppendInt(b, int64(t.Year()), 10)
  354. b = append(b, []byte{0x20}...)
  355. b = append(b, tk.daysWide[t.Weekday()]...)
  356. return string(b)
  357. }
  358. // FmtTimeShort returns the short time representation of 't' for 'tk'
  359. func (tk *tk) FmtTimeShort(t time.Time) string {
  360. b := make([]byte, 0, 32)
  361. if t.Hour() < 10 {
  362. b = append(b, '0')
  363. }
  364. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  365. b = append(b, tk.timeSeparator...)
  366. if t.Minute() < 10 {
  367. b = append(b, '0')
  368. }
  369. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  370. return string(b)
  371. }
  372. // FmtTimeMedium returns the medium time representation of 't' for 'tk'
  373. func (tk *tk) FmtTimeMedium(t time.Time) string {
  374. b := make([]byte, 0, 32)
  375. if t.Hour() < 10 {
  376. b = append(b, '0')
  377. }
  378. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  379. b = append(b, tk.timeSeparator...)
  380. if t.Minute() < 10 {
  381. b = append(b, '0')
  382. }
  383. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  384. b = append(b, tk.timeSeparator...)
  385. if t.Second() < 10 {
  386. b = append(b, '0')
  387. }
  388. b = strconv.AppendInt(b, int64(t.Second()), 10)
  389. return string(b)
  390. }
  391. // FmtTimeLong returns the long time representation of 't' for 'tk'
  392. func (tk *tk) FmtTimeLong(t time.Time) string {
  393. b := make([]byte, 0, 32)
  394. if t.Hour() < 10 {
  395. b = append(b, '0')
  396. }
  397. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  398. b = append(b, tk.timeSeparator...)
  399. if t.Minute() < 10 {
  400. b = append(b, '0')
  401. }
  402. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  403. b = append(b, tk.timeSeparator...)
  404. if t.Second() < 10 {
  405. b = append(b, '0')
  406. }
  407. b = strconv.AppendInt(b, int64(t.Second()), 10)
  408. b = append(b, []byte{0x20}...)
  409. tz, _ := t.Zone()
  410. b = append(b, tz...)
  411. return string(b)
  412. }
  413. // FmtTimeFull returns the full time representation of 't' for 'tk'
  414. func (tk *tk) FmtTimeFull(t time.Time) string {
  415. b := make([]byte, 0, 32)
  416. if t.Hour() < 10 {
  417. b = append(b, '0')
  418. }
  419. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  420. b = append(b, tk.timeSeparator...)
  421. if t.Minute() < 10 {
  422. b = append(b, '0')
  423. }
  424. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  425. b = append(b, tk.timeSeparator...)
  426. if t.Second() < 10 {
  427. b = append(b, '0')
  428. }
  429. b = strconv.AppendInt(b, int64(t.Second()), 10)
  430. b = append(b, []byte{0x20}...)
  431. tz, _ := t.Zone()
  432. if btz, ok := tk.timezones[tz]; ok {
  433. b = append(b, btz...)
  434. } else {
  435. b = append(b, tz...)
  436. }
  437. return string(b)
  438. }