kl.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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 ", "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 ", "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 ", "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{"HAT": "HAT", "ARST": "ARST", "AWDT": "AWDT", "CHAST": "CHAST", "AKDT": "AKDT", "PDT": "PDT", "ChST": "ChST", "HNT": "HNT", "EAT": "EAT", "ACST": "ACST", "ACDT": "ACDT", "∅∅∅": "∅∅∅", "HKST": "HKST", "UYT": "UYT", "UYST": "UYST", "VET": "VET", "AST": "AST", "HADT": "HADT", "COT": "COT", "ADT": "ADT", "HAST": "HAST", "MDT": "MDT", "CLT": "CLT", "WESZ": "WESZ", "ACWST": "ACWST", "AEDT": "AEDT", "GMT": "GMT", "ACWDT": "ACWDT", "OEZ": "OEZ", "JDT": "JDT", "AKST": "AKST", "LHST": "LHST", "CAT": "CAT", "WIB": "WIB", "TMST": "TMST", "PST": "PST", "WART": "WART", "MEZ": "MEZ", "MESZ": "MESZ", "ART": "ART", "BOT": "BOT", "CHADT": "CHADT", "AEST": "AEST", "NZDT": "NZDT", "SGT": "SGT", "WAT": "WAT", "WIT": "WIT", "IST": "IST", "GFT": "GFT", "MST": "MST", "MYT": "MYT", "EST": "EST", "ECT": "ECT", "WARST": "WARST", "TMT": "TMT", "JST": "JST", "GYT": "GYT", "COST": "COST", "WAST": "WAST", "AWST": "AWST", "CLST": "CLST", "SAST": "SAST", "HKT": "HKT", "SRT": "SRT", "CDT": "CDT", "WEZ": "WEZ", "EDT": "EDT", "WITA": "WITA", "LHDT": "LHDT", "OESZ": "OESZ", "CST": "CST", "NZST": "NZST", "BT": "BT"},
  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. // FmtNumber returns 'num' with digits/precision of 'v' for 'kl' and handles both Whole and Real numbers based on 'v'
  159. func (kl *kl) FmtNumber(num float64, v uint64) string {
  160. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  161. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  162. count := 0
  163. inWhole := v == 0
  164. b := make([]byte, 0, l)
  165. for i := len(s) - 1; i >= 0; i-- {
  166. if s[i] == '.' {
  167. b = append(b, kl.decimal[0])
  168. inWhole = true
  169. continue
  170. }
  171. if inWhole {
  172. if count == 3 {
  173. b = append(b, kl.group[0])
  174. count = 1
  175. } else {
  176. count++
  177. }
  178. }
  179. b = append(b, s[i])
  180. }
  181. if num < 0 {
  182. b = append(b, kl.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 'kl' 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 (kl *kl) 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, kl.decimal[0])
  199. continue
  200. }
  201. b = append(b, s[i])
  202. }
  203. if num < 0 {
  204. b = append(b, kl.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, kl.percentSuffix...)
  211. b = append(b, kl.percent...)
  212. return string(b)
  213. }
  214. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'kl'
  215. func (kl *kl) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  216. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  217. symbol := kl.currencies[currency]
  218. l := len(s) + len(symbol) + 2 + 1*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, kl.decimal[0])
  225. inWhole = true
  226. continue
  227. }
  228. if inWhole {
  229. if count == 3 {
  230. b = append(b, kl.group[0])
  231. count = 1
  232. } else {
  233. count++
  234. }
  235. }
  236. b = append(b, s[i])
  237. }
  238. for j := len(symbol) - 1; j >= 0; j-- {
  239. b = append(b, symbol[j])
  240. }
  241. if num < 0 {
  242. b = append(b, kl.minus[0])
  243. }
  244. // reverse
  245. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  246. b[i], b[j] = b[j], b[i]
  247. }
  248. if int(v) < 2 {
  249. if v == 0 {
  250. b = append(b, kl.decimal...)
  251. }
  252. for i := 0; i < 2-int(v); i++ {
  253. b = append(b, '0')
  254. }
  255. }
  256. return string(b)
  257. }
  258. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'kl'
  259. // in accounting notation.
  260. func (kl *kl) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  261. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  262. symbol := kl.currencies[currency]
  263. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  264. count := 0
  265. inWhole := v == 0
  266. b := make([]byte, 0, l)
  267. for i := len(s) - 1; i >= 0; i-- {
  268. if s[i] == '.' {
  269. b = append(b, kl.decimal[0])
  270. inWhole = true
  271. continue
  272. }
  273. if inWhole {
  274. if count == 3 {
  275. b = append(b, kl.group[0])
  276. count = 1
  277. } else {
  278. count++
  279. }
  280. }
  281. b = append(b, s[i])
  282. }
  283. if num < 0 {
  284. for j := len(symbol) - 1; j >= 0; j-- {
  285. b = append(b, symbol[j])
  286. }
  287. b = append(b, kl.minus[0])
  288. } else {
  289. for j := len(symbol) - 1; j >= 0; j-- {
  290. b = append(b, symbol[j])
  291. }
  292. }
  293. // reverse
  294. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  295. b[i], b[j] = b[j], b[i]
  296. }
  297. if int(v) < 2 {
  298. if v == 0 {
  299. b = append(b, kl.decimal...)
  300. }
  301. for i := 0; i < 2-int(v); i++ {
  302. b = append(b, '0')
  303. }
  304. }
  305. return string(b)
  306. }
  307. // FmtDateShort returns the short date representation of 't' for 'kl'
  308. func (kl *kl) FmtDateShort(t time.Time) string {
  309. b := make([]byte, 0, 32)
  310. b = strconv.AppendInt(b, int64(t.Year()), 10)
  311. b = append(b, []byte{0x2d}...)
  312. if t.Month() < 10 {
  313. b = append(b, '0')
  314. }
  315. b = strconv.AppendInt(b, int64(t.Month()), 10)
  316. b = append(b, []byte{0x2d}...)
  317. if t.Day() < 10 {
  318. b = append(b, '0')
  319. }
  320. b = strconv.AppendInt(b, int64(t.Day()), 10)
  321. return string(b)
  322. }
  323. // FmtDateMedium returns the medium date representation of 't' for 'kl'
  324. func (kl *kl) FmtDateMedium(t time.Time) string {
  325. b := make([]byte, 0, 32)
  326. b = append(b, kl.monthsAbbreviated[t.Month()]...)
  327. b = append(b, []byte{0x20}...)
  328. if t.Day() < 10 {
  329. b = append(b, '0')
  330. }
  331. b = strconv.AppendInt(b, int64(t.Day()), 10)
  332. b = append(b, []byte{0x2c, 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 'kl'
  337. func (kl *kl) FmtDateLong(t time.Time) string {
  338. b := make([]byte, 0, 32)
  339. if t.Day() < 10 {
  340. b = append(b, '0')
  341. }
  342. b = strconv.AppendInt(b, int64(t.Day()), 10)
  343. b = append(b, []byte{0x20}...)
  344. b = append(b, kl.monthsWide[t.Month()]...)
  345. b = append(b, []byte{0x20}...)
  346. b = strconv.AppendInt(b, int64(t.Year()), 10)
  347. return string(b)
  348. }
  349. // FmtDateFull returns the full date representation of 't' for 'kl'
  350. func (kl *kl) FmtDateFull(t time.Time) string {
  351. b := make([]byte, 0, 32)
  352. b = append(b, kl.daysWide[t.Weekday()]...)
  353. b = append(b, []byte{0x20}...)
  354. if t.Day() < 10 {
  355. b = append(b, '0')
  356. }
  357. b = strconv.AppendInt(b, int64(t.Day()), 10)
  358. b = append(b, []byte{0x20}...)
  359. b = append(b, kl.monthsWide[t.Month()]...)
  360. b = append(b, []byte{0x20}...)
  361. b = strconv.AppendInt(b, int64(t.Year()), 10)
  362. return string(b)
  363. }
  364. // FmtTimeShort returns the short time representation of 't' for 'kl'
  365. func (kl *kl) FmtTimeShort(t time.Time) string {
  366. b := make([]byte, 0, 32)
  367. h := t.Hour()
  368. if h > 12 {
  369. h -= 12
  370. }
  371. b = strconv.AppendInt(b, int64(h), 10)
  372. b = append(b, kl.timeSeparator...)
  373. if t.Minute() < 10 {
  374. b = append(b, '0')
  375. }
  376. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  377. b = append(b, []byte{0x20}...)
  378. if t.Hour() < 12 {
  379. b = append(b, kl.periodsAbbreviated[0]...)
  380. } else {
  381. b = append(b, kl.periodsAbbreviated[1]...)
  382. }
  383. return string(b)
  384. }
  385. // FmtTimeMedium returns the medium time representation of 't' for 'kl'
  386. func (kl *kl) FmtTimeMedium(t time.Time) string {
  387. b := make([]byte, 0, 32)
  388. h := t.Hour()
  389. if h > 12 {
  390. h -= 12
  391. }
  392. b = strconv.AppendInt(b, int64(h), 10)
  393. b = append(b, kl.timeSeparator...)
  394. if t.Minute() < 10 {
  395. b = append(b, '0')
  396. }
  397. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  398. b = append(b, kl.timeSeparator...)
  399. if t.Second() < 10 {
  400. b = append(b, '0')
  401. }
  402. b = strconv.AppendInt(b, int64(t.Second()), 10)
  403. b = append(b, []byte{0x20}...)
  404. if t.Hour() < 12 {
  405. b = append(b, kl.periodsAbbreviated[0]...)
  406. } else {
  407. b = append(b, kl.periodsAbbreviated[1]...)
  408. }
  409. return string(b)
  410. }
  411. // FmtTimeLong returns the long time representation of 't' for 'kl'
  412. func (kl *kl) FmtTimeLong(t time.Time) string {
  413. b := make([]byte, 0, 32)
  414. h := t.Hour()
  415. if h > 12 {
  416. h -= 12
  417. }
  418. b = strconv.AppendInt(b, int64(h), 10)
  419. b = append(b, kl.timeSeparator...)
  420. if t.Minute() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  424. b = append(b, kl.timeSeparator...)
  425. if t.Second() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Second()), 10)
  429. b = append(b, []byte{0x20}...)
  430. if t.Hour() < 12 {
  431. b = append(b, kl.periodsAbbreviated[0]...)
  432. } else {
  433. b = append(b, kl.periodsAbbreviated[1]...)
  434. }
  435. b = append(b, []byte{0x20}...)
  436. tz, _ := t.Zone()
  437. b = append(b, tz...)
  438. return string(b)
  439. }
  440. // FmtTimeFull returns the full time representation of 't' for 'kl'
  441. func (kl *kl) FmtTimeFull(t time.Time) string {
  442. b := make([]byte, 0, 32)
  443. h := t.Hour()
  444. if h > 12 {
  445. h -= 12
  446. }
  447. b = strconv.AppendInt(b, int64(h), 10)
  448. b = append(b, kl.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, kl.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. if t.Hour() < 12 {
  460. b = append(b, kl.periodsAbbreviated[0]...)
  461. } else {
  462. b = append(b, kl.periodsAbbreviated[1]...)
  463. }
  464. b = append(b, []byte{0x20}...)
  465. tz, _ := t.Zone()
  466. if btz, ok := kl.timezones[tz]; ok {
  467. b = append(b, btz...)
  468. } else {
  469. b = append(b, tz...)
  470. }
  471. return string(b)
  472. }