kea.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. package kea
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type kea 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. currencyPositiveSuffix string
  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 'kea' locale
  42. func New() locales.Translator {
  43. return &kea{
  44. locale: "kea",
  45. pluralsCardinal: []locales.PluralRule{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", "AU$", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "৳", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "$", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "\u200b", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "$", "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", "JP¥", "KES", "KGS", "៛", "KMF", "KPW", "KRH", "KRO", "₩", "KWD", "KYD", "₸", "₭", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "₮", "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", "₱", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "$", "SCR", "SDD", "SDG", "SDP", "SEK", "$", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "STN", "SUR", "SVC", "SYP", "SZL", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "₺", "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. currencyPositiveSuffix: " ",
  57. currencyNegativePrefix: "(",
  58. currencyNegativeSuffix: " )",
  59. monthsAbbreviated: []string{"", "Jan", "Feb", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Otu", "Nuv", "Diz"},
  60. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  61. monthsWide: []string{"", "Janeru", "Febreru", "Marsu", "Abril", "Maiu", "Junhu", "Julhu", "Agostu", "Setenbru", "Otubru", "Nuvenbru", "Dizenbru"},
  62. daysAbbreviated: []string{"dum", "sig", "ter", "kua", "kin", "ses", "sab"},
  63. daysNarrow: []string{"D", "S", "T", "K", "K", "S", "S"},
  64. daysShort: []string{"du", "si", "te", "ku", "ki", "se", "sa"},
  65. daysWide: []string{"dumingu", "sigunda-fera", "tersa-fera", "kuarta-fera", "kinta-fera", "sesta-fera", "sabadu"},
  66. periodsAbbreviated: []string{"am", "pm"},
  67. periodsNarrow: []string{"a", "p"},
  68. periodsWide: []string{"am", "pm"},
  69. erasAbbreviated: []string{"AK", "DK"},
  70. erasNarrow: []string{"", ""},
  71. erasWide: []string{"Antis di Kristu", "Dispos di Kristu"},
  72. timezones: map[string]string{"BT": "BT", "SRT": "SRT", "WIT": "WIT", "OESZ": "Ora di Verãu di Europa Oriental", "MDT": "Ora di Verãu di Montanha", "MEZ": "Ora Padrãu di Europa Sentral", "HENOMX": "HENOMX", "OEZ": "Ora Padrãu di Europa Oriental", "HADT": "HADT", "CDT": "Ora Sentral di Verãu", "HEPMX": "HEPMX", "HNOG": "HNOG", "ACWST": "Ora Padrãu di Australia Sentru-Osidental", "HNEG": "HNEG", "CAT": "Ora di Afrika Sentral", "COT": "COT", "COST": "COST", "UYT": "UYT", "WEZ": "Ora Padrãu di Europa Osidental", "ACDT": "Ora di Verãu di Australia Sentral", "LHDT": "LHDT", "HAT": "HAT", "CLST": "CLST", "HNCU": "HNCU", "PDT": "Ora di Pasifiku di Verãu", "HEEG": "HEEG", "EST": "Ora Oriental Padrãu", "LHST": "LHST", "HAST": "HAST", "BOT": "BOT", "HKT": "HKT", "HKST": "HKST", "IST": "IST", "VET": "VET", "CST": "Ora Sentral Padrãu", "AWDT": "Ora di Verãu di Australia Osidental", "HNPMX": "HNPMX", "SAST": "Ora di Sul di Afrika", "TMST": "TMST", "GMT": "GMT", "CHAST": "CHAST", "ACWDT": "Ora di Verãu di Australia Sentru-Osidental", "NZDT": "NZDT", "WART": "WART", "GYT": "GYT", "CHADT": "CHADT", "WIB": "WIB", "MYT": "MYT", "WARST": "WARST", "HNT": "HNT", "WITA": "WITA", "EAT": "Ora di Afrika Oriental", "AWST": "Ora Padrãu di Australia Osidental", "AST": "Ora Padrãu di Atlantiku", "∅∅∅": "∅∅∅", "AKST": "AKST", "ECT": "ECT", "HNPM": "HNPM", "HECU": "HECU", "WAT": "Ora Padrãu di Afrika Osidental", "JST": "JST", "NZST": "NZST", "EDT": "Ora Oriental di Verãu", "MESZ": "Ora di Verãu di Europa Sentral", "HEPM": "HEPM", "ART": "ART", "AEDT": "Ora di Verãu di Australia Oriental", "GFT": "GFT", "AKDT": "AKDT", "ACST": "Ora Padrãu di Australia Sentral", "HEOG": "HEOG", "HNNOMX": "HNNOMX", "PST": "Ora di Pasifiku Padrãu", "ADT": "Ora di Verãu di Atlantiku", "CLT": "CLT", "JDT": "JDT", "MST": "Ora di Montanha Padrãu", "ChST": "ChST", "AEST": "Ora Padrãu di Australia Oriental", "WESZ": "Ora di Verãu di Europa Osidental", "SGT": "SGT", "TMT": "TMT", "ARST": "ARST", "UYST": "UYST", "WAST": "Ora di Verão di Afrika Osidental"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (kea *kea) Locale() string {
  77. return kea.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'kea'
  80. func (kea *kea) PluralsCardinal() []locales.PluralRule {
  81. return kea.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'kea'
  84. func (kea *kea) PluralsOrdinal() []locales.PluralRule {
  85. return kea.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'kea'
  88. func (kea *kea) PluralsRange() []locales.PluralRule {
  89. return kea.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'kea'
  92. func (kea *kea) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. return locales.PluralRuleOther
  94. }
  95. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'kea'
  96. func (kea *kea) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  97. return locales.PluralRuleUnknown
  98. }
  99. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'kea'
  100. func (kea *kea) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  101. return locales.PluralRuleUnknown
  102. }
  103. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  104. func (kea *kea) MonthAbbreviated(month time.Month) string {
  105. return kea.monthsAbbreviated[month]
  106. }
  107. // MonthsAbbreviated returns the locales abbreviated months
  108. func (kea *kea) MonthsAbbreviated() []string {
  109. return kea.monthsAbbreviated[1:]
  110. }
  111. // MonthNarrow returns the locales narrow month given the 'month' provided
  112. func (kea *kea) MonthNarrow(month time.Month) string {
  113. return kea.monthsNarrow[month]
  114. }
  115. // MonthsNarrow returns the locales narrow months
  116. func (kea *kea) MonthsNarrow() []string {
  117. return kea.monthsNarrow[1:]
  118. }
  119. // MonthWide returns the locales wide month given the 'month' provided
  120. func (kea *kea) MonthWide(month time.Month) string {
  121. return kea.monthsWide[month]
  122. }
  123. // MonthsWide returns the locales wide months
  124. func (kea *kea) MonthsWide() []string {
  125. return kea.monthsWide[1:]
  126. }
  127. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  128. func (kea *kea) WeekdayAbbreviated(weekday time.Weekday) string {
  129. return kea.daysAbbreviated[weekday]
  130. }
  131. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  132. func (kea *kea) WeekdaysAbbreviated() []string {
  133. return kea.daysAbbreviated
  134. }
  135. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  136. func (kea *kea) WeekdayNarrow(weekday time.Weekday) string {
  137. return kea.daysNarrow[weekday]
  138. }
  139. // WeekdaysNarrow returns the locales narrow weekdays
  140. func (kea *kea) WeekdaysNarrow() []string {
  141. return kea.daysNarrow
  142. }
  143. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  144. func (kea *kea) WeekdayShort(weekday time.Weekday) string {
  145. return kea.daysShort[weekday]
  146. }
  147. // WeekdaysShort returns the locales short weekdays
  148. func (kea *kea) WeekdaysShort() []string {
  149. return kea.daysShort
  150. }
  151. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  152. func (kea *kea) WeekdayWide(weekday time.Weekday) string {
  153. return kea.daysWide[weekday]
  154. }
  155. // WeekdaysWide returns the locales wide weekdays
  156. func (kea *kea) WeekdaysWide() []string {
  157. return kea.daysWide
  158. }
  159. // Decimal returns the decimal point of number
  160. func (kea *kea) Decimal() string {
  161. return kea.decimal
  162. }
  163. // Group returns the group of number
  164. func (kea *kea) Group() string {
  165. return kea.group
  166. }
  167. // Group returns the minus sign of number
  168. func (kea *kea) Minus() string {
  169. return kea.minus
  170. }
  171. // FmtNumber returns 'num' with digits/precision of 'v' for 'kea' and handles both Whole and Real numbers based on 'v'
  172. func (kea *kea) FmtNumber(num float64, v uint64) string {
  173. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  174. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  175. count := 0
  176. inWhole := v == 0
  177. b := make([]byte, 0, l)
  178. for i := len(s) - 1; i >= 0; i-- {
  179. if s[i] == '.' {
  180. b = append(b, kea.decimal[0])
  181. inWhole = true
  182. continue
  183. }
  184. if inWhole {
  185. if count == 3 {
  186. for j := len(kea.group) - 1; j >= 0; j-- {
  187. b = append(b, kea.group[j])
  188. }
  189. count = 1
  190. } else {
  191. count++
  192. }
  193. }
  194. b = append(b, s[i])
  195. }
  196. if num < 0 {
  197. b = append(b, kea.minus[0])
  198. }
  199. // reverse
  200. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  201. b[i], b[j] = b[j], b[i]
  202. }
  203. return string(b)
  204. }
  205. // FmtPercent returns 'num' with digits/precision of 'v' for 'kea' and handles both Whole and Real numbers based on 'v'
  206. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  207. func (kea *kea) FmtPercent(num float64, v uint64) string {
  208. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  209. l := len(s) + 3
  210. b := make([]byte, 0, l)
  211. for i := len(s) - 1; i >= 0; i-- {
  212. if s[i] == '.' {
  213. b = append(b, kea.decimal[0])
  214. continue
  215. }
  216. b = append(b, s[i])
  217. }
  218. if num < 0 {
  219. b = append(b, kea.minus[0])
  220. }
  221. // reverse
  222. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  223. b[i], b[j] = b[j], b[i]
  224. }
  225. b = append(b, kea.percent...)
  226. return string(b)
  227. }
  228. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'kea'
  229. func (kea *kea) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  230. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  231. symbol := kea.currencies[currency]
  232. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  233. count := 0
  234. inWhole := v == 0
  235. b := make([]byte, 0, l)
  236. for i := len(s) - 1; i >= 0; i-- {
  237. if s[i] == '.' {
  238. b = append(b, kea.decimal[0])
  239. inWhole = true
  240. continue
  241. }
  242. if inWhole {
  243. if count == 3 {
  244. for j := len(kea.group) - 1; j >= 0; j-- {
  245. b = append(b, kea.group[j])
  246. }
  247. count = 1
  248. } else {
  249. count++
  250. }
  251. }
  252. b = append(b, s[i])
  253. }
  254. if num < 0 {
  255. b = append(b, kea.minus[0])
  256. }
  257. // reverse
  258. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  259. b[i], b[j] = b[j], b[i]
  260. }
  261. if int(v) < 2 {
  262. if v == 0 {
  263. b = append(b, kea.decimal...)
  264. }
  265. for i := 0; i < 2-int(v); i++ {
  266. b = append(b, '0')
  267. }
  268. }
  269. b = append(b, kea.currencyPositiveSuffix...)
  270. b = append(b, symbol...)
  271. return string(b)
  272. }
  273. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'kea'
  274. // in accounting notation.
  275. func (kea *kea) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  276. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  277. symbol := kea.currencies[currency]
  278. l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  279. count := 0
  280. inWhole := v == 0
  281. b := make([]byte, 0, l)
  282. for i := len(s) - 1; i >= 0; i-- {
  283. if s[i] == '.' {
  284. b = append(b, kea.decimal[0])
  285. inWhole = true
  286. continue
  287. }
  288. if inWhole {
  289. if count == 3 {
  290. for j := len(kea.group) - 1; j >= 0; j-- {
  291. b = append(b, kea.group[j])
  292. }
  293. count = 1
  294. } else {
  295. count++
  296. }
  297. }
  298. b = append(b, s[i])
  299. }
  300. if num < 0 {
  301. b = append(b, kea.currencyNegativePrefix[0])
  302. }
  303. // reverse
  304. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  305. b[i], b[j] = b[j], b[i]
  306. }
  307. if int(v) < 2 {
  308. if v == 0 {
  309. b = append(b, kea.decimal...)
  310. }
  311. for i := 0; i < 2-int(v); i++ {
  312. b = append(b, '0')
  313. }
  314. }
  315. if num < 0 {
  316. b = append(b, kea.currencyNegativeSuffix...)
  317. b = append(b, symbol...)
  318. } else {
  319. b = append(b, kea.currencyPositiveSuffix...)
  320. b = append(b, symbol...)
  321. }
  322. return string(b)
  323. }
  324. // FmtDateShort returns the short date representation of 't' for 'kea'
  325. func (kea *kea) FmtDateShort(t time.Time) string {
  326. b := make([]byte, 0, 32)
  327. b = strconv.AppendInt(b, int64(t.Day()), 10)
  328. b = append(b, []byte{0x2f}...)
  329. b = strconv.AppendInt(b, int64(t.Month()), 10)
  330. b = append(b, []byte{0x2f}...)
  331. if t.Year() > 0 {
  332. b = strconv.AppendInt(b, int64(t.Year()), 10)
  333. } else {
  334. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  335. }
  336. return string(b)
  337. }
  338. // FmtDateMedium returns the medium date representation of 't' for 'kea'
  339. func (kea *kea) FmtDateMedium(t time.Time) string {
  340. b := make([]byte, 0, 32)
  341. b = strconv.AppendInt(b, int64(t.Day()), 10)
  342. b = append(b, []byte{0x20}...)
  343. b = append(b, kea.monthsAbbreviated[t.Month()]...)
  344. b = append(b, []byte{0x20}...)
  345. if t.Year() > 0 {
  346. b = strconv.AppendInt(b, int64(t.Year()), 10)
  347. } else {
  348. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  349. }
  350. return string(b)
  351. }
  352. // FmtDateLong returns the long date representation of 't' for 'kea'
  353. func (kea *kea) FmtDateLong(t time.Time) string {
  354. b := make([]byte, 0, 32)
  355. b = strconv.AppendInt(b, int64(t.Day()), 10)
  356. b = append(b, []byte{0x20, 0x64, 0x69}...)
  357. b = append(b, []byte{0x20}...)
  358. b = append(b, kea.monthsWide[t.Month()]...)
  359. b = append(b, []byte{0x20, 0x64, 0x69}...)
  360. b = append(b, []byte{0x20}...)
  361. if t.Year() > 0 {
  362. b = strconv.AppendInt(b, int64(t.Year()), 10)
  363. } else {
  364. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  365. }
  366. return string(b)
  367. }
  368. // FmtDateFull returns the full date representation of 't' for 'kea'
  369. func (kea *kea) FmtDateFull(t time.Time) string {
  370. b := make([]byte, 0, 32)
  371. b = append(b, kea.daysWide[t.Weekday()]...)
  372. b = append(b, []byte{0x2c, 0x20}...)
  373. b = strconv.AppendInt(b, int64(t.Day()), 10)
  374. b = append(b, []byte{0x20, 0x64, 0x69}...)
  375. b = append(b, []byte{0x20}...)
  376. b = append(b, kea.monthsWide[t.Month()]...)
  377. b = append(b, []byte{0x20, 0x64, 0x69}...)
  378. b = append(b, []byte{0x20}...)
  379. if t.Year() > 0 {
  380. b = strconv.AppendInt(b, int64(t.Year()), 10)
  381. } else {
  382. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  383. }
  384. return string(b)
  385. }
  386. // FmtTimeShort returns the short time representation of 't' for 'kea'
  387. func (kea *kea) FmtTimeShort(t time.Time) string {
  388. b := make([]byte, 0, 32)
  389. if t.Hour() < 10 {
  390. b = append(b, '0')
  391. }
  392. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  393. b = append(b, kea.timeSeparator...)
  394. if t.Minute() < 10 {
  395. b = append(b, '0')
  396. }
  397. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  398. return string(b)
  399. }
  400. // FmtTimeMedium returns the medium time representation of 't' for 'kea'
  401. func (kea *kea) FmtTimeMedium(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, kea.timeSeparator...)
  408. if t.Minute() < 10 {
  409. b = append(b, '0')
  410. }
  411. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  412. b = append(b, kea.timeSeparator...)
  413. if t.Second() < 10 {
  414. b = append(b, '0')
  415. }
  416. b = strconv.AppendInt(b, int64(t.Second()), 10)
  417. return string(b)
  418. }
  419. // FmtTimeLong returns the long time representation of 't' for 'kea'
  420. func (kea *kea) FmtTimeLong(t time.Time) string {
  421. b := make([]byte, 0, 32)
  422. if t.Hour() < 10 {
  423. b = append(b, '0')
  424. }
  425. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  426. b = append(b, kea.timeSeparator...)
  427. if t.Minute() < 10 {
  428. b = append(b, '0')
  429. }
  430. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  431. b = append(b, kea.timeSeparator...)
  432. if t.Second() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Second()), 10)
  436. b = append(b, []byte{0x20}...)
  437. tz, _ := t.Zone()
  438. b = append(b, tz...)
  439. return string(b)
  440. }
  441. // FmtTimeFull returns the full time representation of 't' for 'kea'
  442. func (kea *kea) FmtTimeFull(t time.Time) string {
  443. b := make([]byte, 0, 32)
  444. if t.Hour() < 10 {
  445. b = append(b, '0')
  446. }
  447. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  448. b = append(b, kea.timeSeparator...)
  449. if t.Minute() < 10 {
  450. b = append(b, '0')
  451. }
  452. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  453. b = append(b, kea.timeSeparator...)
  454. if t.Second() < 10 {
  455. b = append(b, '0')
  456. }
  457. b = strconv.AppendInt(b, int64(t.Second()), 10)
  458. b = append(b, []byte{0x20}...)
  459. tz, _ := t.Zone()
  460. if btz, ok := kea.timezones[tz]; ok {
  461. b = append(b, btz...)
  462. } else {
  463. b = append(b, tz...)
  464. }
  465. return string(b)
  466. }