kl.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. package kl
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type kl 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. monthsAbbreviated []string
  24. monthsNarrow []string
  25. monthsWide []string
  26. daysAbbreviated []string
  27. daysNarrow []string
  28. daysShort []string
  29. daysWide []string
  30. periodsAbbreviated []string
  31. periodsNarrow []string
  32. periodsShort []string
  33. periodsWide []string
  34. erasAbbreviated []string
  35. erasNarrow []string
  36. erasWide []string
  37. timezones map[string]string
  38. }
  39. // New returns a new instance of translator for the 'kl' locale
  40. func New() locales.Translator {
  41. return &kl{
  42. locale: "kl",
  43. pluralsCardinal: []locales.PluralRule{2, 6},
  44. pluralsOrdinal: nil,
  45. pluralsRange: nil,
  46. decimal: ",",
  47. group: ".",
  48. minus: "−",
  49. percent: "%",
  50. perMille: "‰",
  51. timeSeparator: ":",
  52. inifinity: "∞",
  53. 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", "kr.", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "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", "Nkr", "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", "Skr", "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", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
  54. percentSuffix: " ",
  55. monthsAbbreviated: []string{"", "jan", "feb", "mar", "apr", "maj", "jun", "jul", "aug", "sep", "okt", "nov", "dec"},
  56. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  57. monthsWide: []string{"", "januari", "februari", "martsi", "aprili", "maji", "juni", "juli", "augustusi", "septemberi", "oktoberi", "novemberi", "decemberi"},
  58. daysAbbreviated: []string{"sab", "ata", "mar", "pin", "sis", "tal", "arf"},
  59. daysNarrow: []string{"S", "A", "M", "P", "S", "T", "A"},
  60. daysShort: []string{"sab", "ata", "mar", "pin", "sis", "tal", "arf"},
  61. daysWide: []string{"sabaat", "ataasinngorneq", "marlunngorneq", "pingasunngorneq", "sisamanngorneq", "tallimanngorneq", "arfininngorneq"},
  62. periodsAbbreviated: []string{"u.t.", "u.k."},
  63. periodsWide: []string{"ulloqeqqata-tungaa", "ulloqeqqata-kingorna"},
  64. erasAbbreviated: []string{"Kr.in.si.", "Kr.in.king."},
  65. erasNarrow: []string{"Kr.s.", "Kr.k."},
  66. erasWide: []string{"Kristusip inunngornerata siornagut", "Kristusip inunngornerata kingornagut"},
  67. timezones: map[string]string{"BT": "BT", "TMT": "TMT", "UYT": "UYT", "AST": "AST", "NZDT": "NZDT", "MEZ": "MEZ", "CAT": "CAT", "HEEG": "HEEG", "COST": "COST", "SGT": "SGT", "CDT": "CDT", "JDT": "JDT", "ChST": "ChST", "CHADT": "CHADT", "GMT": "GMT", "AEDT": "AEDT", "IST": "IST", "SRT": "SRT", "UYST": "UYST", "CHAST": "CHAST", "AWDT": "AWDT", "HNPMX": "HNPMX", "WAT": "WAT", "WAST": "WAST", "WARST": "WARST", "HNPM": "HNPM", "EDT": "EDT", "EAT": "EAT", "HADT": "HADT", "HNCU": "HNCU", "PST": "PST", "HEOG": "HEOG", "HNNOMX": "HNNOMX", "MST": "MST", "NZST": "NZST", "EST": "EST", "ACWST": "ACWST", "MESZ": "MESZ", "AEST": "AEST", "OEZ": "OEZ", "AWST": "AWST", "AKST": "AKST", "ACDT": "ACDT", "ACWDT": "ACWDT", "HNOG": "HNOG", "HNT": "HNT", "VET": "VET", "GFT": "GFT", "ACST": "ACST", "CLST": "CLST", "GYT": "GYT", "HECU": "HECU", "PDT": "PDT", "LHDT": "LHDT", "WART": "WART", "ART": "ART", "HEPMX": "HEPMX", "WESZ": "WESZ", "BOT": "BOT", "HEPM": "HEPM", "HAST": "HAST", "WEZ": "WEZ", "WIB": "WIB", "WITA": "WITA", "CLT": "CLT", "LHST": "LHST", "HAT": "HAT", "MDT": "MDT", "OESZ": "OESZ", "ARST": "ARST", "ADT": "ADT", "HKT": "HKT", "∅∅∅": "∅∅∅", "ECT": "ECT", "MYT": "MYT", "AKDT": "AKDT", "HNEG": "HNEG", "TMST": "TMST", "CST": "CST", "WIT": "WIT", "COT": "COT", "SAST": "SAST", "JST": "JST", "HKST": "HKST", "HENOMX": "HENOMX"},
  68. }
  69. }
  70. // Locale returns the current translators string locale
  71. func (kl *kl) Locale() string {
  72. return kl.locale
  73. }
  74. // PluralsCardinal returns the list of cardinal plural rules associated with 'kl'
  75. func (kl *kl) PluralsCardinal() []locales.PluralRule {
  76. return kl.pluralsCardinal
  77. }
  78. // PluralsOrdinal returns the list of ordinal plural rules associated with 'kl'
  79. func (kl *kl) PluralsOrdinal() []locales.PluralRule {
  80. return kl.pluralsOrdinal
  81. }
  82. // PluralsRange returns the list of range plural rules associated with 'kl'
  83. func (kl *kl) PluralsRange() []locales.PluralRule {
  84. return kl.pluralsRange
  85. }
  86. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'kl'
  87. func (kl *kl) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  88. n := math.Abs(num)
  89. if n == 1 {
  90. return locales.PluralRuleOne
  91. }
  92. return locales.PluralRuleOther
  93. }
  94. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'kl'
  95. func (kl *kl) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  96. return locales.PluralRuleUnknown
  97. }
  98. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'kl'
  99. func (kl *kl) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  100. return locales.PluralRuleUnknown
  101. }
  102. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  103. func (kl *kl) MonthAbbreviated(month time.Month) string {
  104. return kl.monthsAbbreviated[month]
  105. }
  106. // MonthsAbbreviated returns the locales abbreviated months
  107. func (kl *kl) MonthsAbbreviated() []string {
  108. return kl.monthsAbbreviated[1:]
  109. }
  110. // MonthNarrow returns the locales narrow month given the 'month' provided
  111. func (kl *kl) MonthNarrow(month time.Month) string {
  112. return kl.monthsNarrow[month]
  113. }
  114. // MonthsNarrow returns the locales narrow months
  115. func (kl *kl) MonthsNarrow() []string {
  116. return kl.monthsNarrow[1:]
  117. }
  118. // MonthWide returns the locales wide month given the 'month' provided
  119. func (kl *kl) MonthWide(month time.Month) string {
  120. return kl.monthsWide[month]
  121. }
  122. // MonthsWide returns the locales wide months
  123. func (kl *kl) MonthsWide() []string {
  124. return kl.monthsWide[1:]
  125. }
  126. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  127. func (kl *kl) WeekdayAbbreviated(weekday time.Weekday) string {
  128. return kl.daysAbbreviated[weekday]
  129. }
  130. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  131. func (kl *kl) WeekdaysAbbreviated() []string {
  132. return kl.daysAbbreviated
  133. }
  134. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  135. func (kl *kl) WeekdayNarrow(weekday time.Weekday) string {
  136. return kl.daysNarrow[weekday]
  137. }
  138. // WeekdaysNarrow returns the locales narrow weekdays
  139. func (kl *kl) WeekdaysNarrow() []string {
  140. return kl.daysNarrow
  141. }
  142. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  143. func (kl *kl) WeekdayShort(weekday time.Weekday) string {
  144. return kl.daysShort[weekday]
  145. }
  146. // WeekdaysShort returns the locales short weekdays
  147. func (kl *kl) WeekdaysShort() []string {
  148. return kl.daysShort
  149. }
  150. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  151. func (kl *kl) WeekdayWide(weekday time.Weekday) string {
  152. return kl.daysWide[weekday]
  153. }
  154. // WeekdaysWide returns the locales wide weekdays
  155. func (kl *kl) WeekdaysWide() []string {
  156. return kl.daysWide
  157. }
  158. // Decimal returns the decimal point of number
  159. func (kl *kl) Decimal() string {
  160. return kl.decimal
  161. }
  162. // Group returns the group of number
  163. func (kl *kl) Group() string {
  164. return kl.group
  165. }
  166. // Group returns the minus sign of number
  167. func (kl *kl) Minus() string {
  168. return kl.minus
  169. }
  170. // FmtNumber returns 'num' with digits/precision of 'v' for 'kl' and handles both Whole and Real numbers based on 'v'
  171. func (kl *kl) FmtNumber(num float64, v uint64) string {
  172. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  173. l := len(s) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  174. count := 0
  175. inWhole := v == 0
  176. b := make([]byte, 0, l)
  177. for i := len(s) - 1; i >= 0; i-- {
  178. if s[i] == '.' {
  179. b = append(b, kl.decimal[0])
  180. inWhole = true
  181. continue
  182. }
  183. if inWhole {
  184. if count == 3 {
  185. b = append(b, kl.group[0])
  186. count = 1
  187. } else {
  188. count++
  189. }
  190. }
  191. b = append(b, s[i])
  192. }
  193. if num < 0 {
  194. for j := len(kl.minus) - 1; j >= 0; j-- {
  195. b = append(b, kl.minus[j])
  196. }
  197. }
  198. // reverse
  199. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  200. b[i], b[j] = b[j], b[i]
  201. }
  202. return string(b)
  203. }
  204. // FmtPercent returns 'num' with digits/precision of 'v' for 'kl' and handles both Whole and Real numbers based on 'v'
  205. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  206. func (kl *kl) FmtPercent(num float64, v uint64) string {
  207. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  208. l := len(s) + 7
  209. b := make([]byte, 0, l)
  210. for i := len(s) - 1; i >= 0; i-- {
  211. if s[i] == '.' {
  212. b = append(b, kl.decimal[0])
  213. continue
  214. }
  215. b = append(b, s[i])
  216. }
  217. if num < 0 {
  218. for j := len(kl.minus) - 1; j >= 0; j-- {
  219. b = append(b, kl.minus[j])
  220. }
  221. }
  222. // reverse
  223. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  224. b[i], b[j] = b[j], b[i]
  225. }
  226. b = append(b, kl.percentSuffix...)
  227. b = append(b, kl.percent...)
  228. return string(b)
  229. }
  230. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'kl'
  231. func (kl *kl) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  232. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  233. symbol := kl.currencies[currency]
  234. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  235. count := 0
  236. inWhole := v == 0
  237. b := make([]byte, 0, l)
  238. for i := len(s) - 1; i >= 0; i-- {
  239. if s[i] == '.' {
  240. b = append(b, kl.decimal[0])
  241. inWhole = true
  242. continue
  243. }
  244. if inWhole {
  245. if count == 3 {
  246. b = append(b, kl.group[0])
  247. count = 1
  248. } else {
  249. count++
  250. }
  251. }
  252. b = append(b, s[i])
  253. }
  254. for j := len(symbol) - 1; j >= 0; j-- {
  255. b = append(b, symbol[j])
  256. }
  257. if num < 0 {
  258. for j := len(kl.minus) - 1; j >= 0; j-- {
  259. b = append(b, kl.minus[j])
  260. }
  261. }
  262. // reverse
  263. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  264. b[i], b[j] = b[j], b[i]
  265. }
  266. if int(v) < 2 {
  267. if v == 0 {
  268. b = append(b, kl.decimal...)
  269. }
  270. for i := 0; i < 2-int(v); i++ {
  271. b = append(b, '0')
  272. }
  273. }
  274. return string(b)
  275. }
  276. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'kl'
  277. // in accounting notation.
  278. func (kl *kl) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  279. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  280. symbol := kl.currencies[currency]
  281. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  282. count := 0
  283. inWhole := v == 0
  284. b := make([]byte, 0, l)
  285. for i := len(s) - 1; i >= 0; i-- {
  286. if s[i] == '.' {
  287. b = append(b, kl.decimal[0])
  288. inWhole = true
  289. continue
  290. }
  291. if inWhole {
  292. if count == 3 {
  293. b = append(b, kl.group[0])
  294. count = 1
  295. } else {
  296. count++
  297. }
  298. }
  299. b = append(b, s[i])
  300. }
  301. if num < 0 {
  302. for j := len(symbol) - 1; j >= 0; j-- {
  303. b = append(b, symbol[j])
  304. }
  305. for j := len(kl.minus) - 1; j >= 0; j-- {
  306. b = append(b, kl.minus[j])
  307. }
  308. } else {
  309. for j := len(symbol) - 1; j >= 0; j-- {
  310. b = append(b, symbol[j])
  311. }
  312. }
  313. // reverse
  314. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  315. b[i], b[j] = b[j], b[i]
  316. }
  317. if int(v) < 2 {
  318. if v == 0 {
  319. b = append(b, kl.decimal...)
  320. }
  321. for i := 0; i < 2-int(v); i++ {
  322. b = append(b, '0')
  323. }
  324. }
  325. return string(b)
  326. }
  327. // FmtDateShort returns the short date representation of 't' for 'kl'
  328. func (kl *kl) FmtDateShort(t time.Time) string {
  329. b := make([]byte, 0, 32)
  330. if t.Year() > 0 {
  331. b = strconv.AppendInt(b, int64(t.Year()), 10)
  332. } else {
  333. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  334. }
  335. b = append(b, []byte{0x2d}...)
  336. if t.Month() < 10 {
  337. b = append(b, '0')
  338. }
  339. b = strconv.AppendInt(b, int64(t.Month()), 10)
  340. b = append(b, []byte{0x2d}...)
  341. if t.Day() < 10 {
  342. b = append(b, '0')
  343. }
  344. b = strconv.AppendInt(b, int64(t.Day()), 10)
  345. return string(b)
  346. }
  347. // FmtDateMedium returns the medium date representation of 't' for 'kl'
  348. func (kl *kl) FmtDateMedium(t time.Time) string {
  349. b := make([]byte, 0, 32)
  350. b = append(b, kl.monthsAbbreviated[t.Month()]...)
  351. b = append(b, []byte{0x20}...)
  352. if t.Day() < 10 {
  353. b = append(b, '0')
  354. }
  355. b = strconv.AppendInt(b, int64(t.Day()), 10)
  356. b = append(b, []byte{0x2c, 0x20}...)
  357. if t.Year() > 0 {
  358. b = strconv.AppendInt(b, int64(t.Year()), 10)
  359. } else {
  360. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  361. }
  362. return string(b)
  363. }
  364. // FmtDateLong returns the long date representation of 't' for 'kl'
  365. func (kl *kl) FmtDateLong(t time.Time) string {
  366. b := make([]byte, 0, 32)
  367. if t.Day() < 10 {
  368. b = append(b, '0')
  369. }
  370. b = strconv.AppendInt(b, int64(t.Day()), 10)
  371. b = append(b, []byte{0x20}...)
  372. b = append(b, kl.monthsWide[t.Month()]...)
  373. b = append(b, []byte{0x20}...)
  374. if t.Year() > 0 {
  375. b = strconv.AppendInt(b, int64(t.Year()), 10)
  376. } else {
  377. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  378. }
  379. return string(b)
  380. }
  381. // FmtDateFull returns the full date representation of 't' for 'kl'
  382. func (kl *kl) FmtDateFull(t time.Time) string {
  383. b := make([]byte, 0, 32)
  384. b = append(b, kl.daysWide[t.Weekday()]...)
  385. b = append(b, []byte{0x20}...)
  386. if t.Day() < 10 {
  387. b = append(b, '0')
  388. }
  389. b = strconv.AppendInt(b, int64(t.Day()), 10)
  390. b = append(b, []byte{0x20}...)
  391. b = append(b, kl.monthsWide[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. return string(b)
  399. }
  400. // FmtTimeShort returns the short time representation of 't' for 'kl'
  401. func (kl *kl) FmtTimeShort(t time.Time) string {
  402. b := make([]byte, 0, 32)
  403. if t.Hour() < 10 {
  404. b = append(b, '0')
  405. }
  406. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  407. b = append(b, []byte{0x2e}...)
  408. if t.Minute() < 10 {
  409. b = append(b, '0')
  410. }
  411. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  412. return string(b)
  413. }
  414. // FmtTimeMedium returns the medium time representation of 't' for 'kl'
  415. func (kl *kl) FmtTimeMedium(t time.Time) string {
  416. b := make([]byte, 0, 32)
  417. if t.Hour() < 10 {
  418. b = append(b, '0')
  419. }
  420. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  421. b = append(b, []byte{0x2e}...)
  422. if t.Minute() < 10 {
  423. b = append(b, '0')
  424. }
  425. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  426. b = append(b, []byte{0x2e}...)
  427. if t.Second() < 10 {
  428. b = append(b, '0')
  429. }
  430. b = strconv.AppendInt(b, int64(t.Second()), 10)
  431. return string(b)
  432. }
  433. // FmtTimeLong returns the long time representation of 't' for 'kl'
  434. func (kl *kl) FmtTimeLong(t time.Time) string {
  435. b := make([]byte, 0, 32)
  436. if t.Hour() < 10 {
  437. b = append(b, '0')
  438. }
  439. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  440. b = append(b, []byte{0x2e}...)
  441. if t.Minute() < 10 {
  442. b = append(b, '0')
  443. }
  444. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  445. b = append(b, []byte{0x2e}...)
  446. if t.Second() < 10 {
  447. b = append(b, '0')
  448. }
  449. b = strconv.AppendInt(b, int64(t.Second()), 10)
  450. b = append(b, []byte{0x20}...)
  451. tz, _ := t.Zone()
  452. b = append(b, tz...)
  453. return string(b)
  454. }
  455. // FmtTimeFull returns the full time representation of 't' for 'kl'
  456. func (kl *kl) FmtTimeFull(t time.Time) string {
  457. b := make([]byte, 0, 32)
  458. if t.Hour() < 10 {
  459. b = append(b, '0')
  460. }
  461. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  462. b = append(b, []byte{0x2e}...)
  463. if t.Minute() < 10 {
  464. b = append(b, '0')
  465. }
  466. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  467. b = append(b, []byte{0x2e}...)
  468. if t.Second() < 10 {
  469. b = append(b, '0')
  470. }
  471. b = strconv.AppendInt(b, int64(t.Second()), 10)
  472. b = append(b, []byte{0x20}...)
  473. tz, _ := t.Zone()
  474. if btz, ok := kl.timezones[tz]; ok {
  475. b = append(b, btz...)
  476. } else {
  477. b = append(b, tz...)
  478. }
  479. return string(b)
  480. }