kok.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. package kok
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type kok 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. currencyPositivePrefix string
  23. currencyNegativePrefix string
  24. monthsAbbreviated []string
  25. monthsNarrow []string
  26. monthsWide []string
  27. daysAbbreviated []string
  28. daysNarrow []string
  29. daysShort []string
  30. daysWide []string
  31. periodsAbbreviated []string
  32. periodsNarrow []string
  33. periodsShort []string
  34. periodsWide []string
  35. erasAbbreviated []string
  36. erasNarrow []string
  37. erasWide []string
  38. timezones map[string]string
  39. }
  40. // New returns a new instance of translator for the 'kok' locale
  41. func New() locales.Translator {
  42. return &kok{
  43. locale: "kok",
  44. pluralsCardinal: nil,
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  47. decimal: ".",
  48. group: ",",
  49. minus: "-",
  50. percent: "%",
  51. perMille: "‰",
  52. timeSeparator: ":",
  53. inifinity: "∞",
  54. 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", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "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", "€", "FIM", "FJD", "FKP", "FRF", "£", "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", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JP¥", "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", "STN", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "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"},
  55. currencyPositivePrefix: " ",
  56. currencyNegativePrefix: " ",
  57. monthsAbbreviated: []string{"", "जानेवारी", "फेब्रुवारी", "मार्च", "एप्रिल", "मे", "जून", "जुलाय", "आगोस्त", "सप्टेंबर", "ऑक्टोबर", "नोव्हेंबर", "डिसेंबर"},
  58. monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  59. monthsWide: []string{"", "जानेवारी", "फेब्रुवारी", "मार्च", "एप्रिल", "मे", "जून", "जुलाय", "आगोस्त", "सप्टेंबर", "ऑक्टोबर", "नोव्हेंबर", "डिसेंबर"},
  60. daysAbbreviated: []string{"आयतार", "सोमार", "मंगळार", "बुधवार", "गुरुवार", "शुक्रार", "शेनवार"},
  61. daysNarrow: []string{"आ", "सो", "मं", "बु", "गु", "शु", "शे"},
  62. daysShort: []string{"आय", "सोम", "मंगळ", "बुध", "गुरु", "शुक्र", "शेन"},
  63. daysWide: []string{"आयतार", "सोमार", "मंगळार", "बुधवार", "गुरुवार", "शुक्रार", "शेनवार"},
  64. periodsAbbreviated: []string{"म.पू.", "म.नं."},
  65. periodsNarrow: []string{"म.पू.", "म.नं."},
  66. periodsWide: []string{"म.पू.", "म.नं."},
  67. erasAbbreviated: []string{"क्रिस्तपूर्व", "क्रिस्तशखा"},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"क्रिस्तपूर्व", "क्रिस्तशखा"},
  70. timezones: map[string]string{"WIT": "WIT", "TMT": "TMT", "CST": "CST", "AEST": "AEST", "WART": "WART", "HNT": "HNT", "MDT": "MDT", "CLT": "CLT", "BOT": "BOT", "SRT": "SRT", "AST": "AST", "EDT": "EDT", "LHDT": "LHDT", "COT": "COT", "JST": "JST", "ACWDT": "ACWDT", "IST": "भारतीय समय", "CAT": "CAT", "OEZ": "OEZ", "HNEG": "HNEG", "ChST": "ChST", "CDT": "CDT", "ACDT": "ACDT", "HEOG": "HEOG", "MST": "MST", "CLST": "CLST", "HADT": "HADT", "ART": "ART", "SGT": "SGT", "GYT": "GYT", "UYT": "UYT", "HECU": "HECU", "WAT": "WAT", "MEZ": "MEZ", "COST": "COST", "WAST": "WAST", "AKDT": "AKDT", "NZDT": "NZDT", "ECT": "ECT", "AKST": "AKST", "ACWST": "ACWST", "ARST": "ARST", "UYST": "UYST", "GMT": "GMT", "ADT": "ADT", "HEEG": "HEEG", "HNOG": "HNOG", "PST": "PST", "PDT": "PDT", "WIB": "WIB", "MYT": "MYT", "WARST": "WARST", "HEPMX": "HEPMX", "WESZ": "WESZ", "EST": "EST", "AEDT": "AEDT", "GFT": "GFT", "HKT": "HKT", "HNNOMX": "HNNOMX", "OESZ": "OESZ", "HNPMX": "HNPMX", "AWST": "AWST", "AWDT": "AWDT", "WEZ": "WEZ", "BT": "BT", "HKST": "HKST", "MESZ": "MESZ", "HNPM": "HNPM", "WITA": "WITA", "ACST": "ACST", "NZST": "NZST", "LHST": "LHST", "VET": "VET", "HEPM": "HEPM", "HENOMX": "HENOMX", "EAT": "EAT", "JDT": "JDT", "SAST": "SAST", "∅∅∅": "∅∅∅", "HAT": "HAT", "HAST": "HAST", "CHAST": "CHAST", "TMST": "TMST", "HNCU": "HNCU", "CHADT": "CHADT"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (kok *kok) Locale() string {
  75. return kok.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'kok'
  78. func (kok *kok) PluralsCardinal() []locales.PluralRule {
  79. return kok.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'kok'
  82. func (kok *kok) PluralsOrdinal() []locales.PluralRule {
  83. return kok.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'kok'
  86. func (kok *kok) PluralsRange() []locales.PluralRule {
  87. return kok.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'kok'
  90. func (kok *kok) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. return locales.PluralRuleUnknown
  92. }
  93. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'kok'
  94. func (kok *kok) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  95. return locales.PluralRuleUnknown
  96. }
  97. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'kok'
  98. func (kok *kok) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  99. return locales.PluralRuleUnknown
  100. }
  101. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  102. func (kok *kok) MonthAbbreviated(month time.Month) string {
  103. return kok.monthsAbbreviated[month]
  104. }
  105. // MonthsAbbreviated returns the locales abbreviated months
  106. func (kok *kok) MonthsAbbreviated() []string {
  107. return kok.monthsAbbreviated[1:]
  108. }
  109. // MonthNarrow returns the locales narrow month given the 'month' provided
  110. func (kok *kok) MonthNarrow(month time.Month) string {
  111. return kok.monthsNarrow[month]
  112. }
  113. // MonthsNarrow returns the locales narrow months
  114. func (kok *kok) MonthsNarrow() []string {
  115. return kok.monthsNarrow[1:]
  116. }
  117. // MonthWide returns the locales wide month given the 'month' provided
  118. func (kok *kok) MonthWide(month time.Month) string {
  119. return kok.monthsWide[month]
  120. }
  121. // MonthsWide returns the locales wide months
  122. func (kok *kok) MonthsWide() []string {
  123. return kok.monthsWide[1:]
  124. }
  125. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  126. func (kok *kok) WeekdayAbbreviated(weekday time.Weekday) string {
  127. return kok.daysAbbreviated[weekday]
  128. }
  129. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  130. func (kok *kok) WeekdaysAbbreviated() []string {
  131. return kok.daysAbbreviated
  132. }
  133. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  134. func (kok *kok) WeekdayNarrow(weekday time.Weekday) string {
  135. return kok.daysNarrow[weekday]
  136. }
  137. // WeekdaysNarrow returns the locales narrow weekdays
  138. func (kok *kok) WeekdaysNarrow() []string {
  139. return kok.daysNarrow
  140. }
  141. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  142. func (kok *kok) WeekdayShort(weekday time.Weekday) string {
  143. return kok.daysShort[weekday]
  144. }
  145. // WeekdaysShort returns the locales short weekdays
  146. func (kok *kok) WeekdaysShort() []string {
  147. return kok.daysShort
  148. }
  149. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  150. func (kok *kok) WeekdayWide(weekday time.Weekday) string {
  151. return kok.daysWide[weekday]
  152. }
  153. // WeekdaysWide returns the locales wide weekdays
  154. func (kok *kok) WeekdaysWide() []string {
  155. return kok.daysWide
  156. }
  157. // Decimal returns the decimal point of number
  158. func (kok *kok) Decimal() string {
  159. return kok.decimal
  160. }
  161. // Group returns the group of number
  162. func (kok *kok) Group() string {
  163. return kok.group
  164. }
  165. // Group returns the minus sign of number
  166. func (kok *kok) Minus() string {
  167. return kok.minus
  168. }
  169. // FmtNumber returns 'num' with digits/precision of 'v' for 'kok' and handles both Whole and Real numbers based on 'v'
  170. func (kok *kok) FmtNumber(num float64, v uint64) string {
  171. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  172. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  173. count := 0
  174. inWhole := v == 0
  175. inSecondary := false
  176. groupThreshold := 3
  177. b := make([]byte, 0, l)
  178. for i := len(s) - 1; i >= 0; i-- {
  179. if s[i] == '.' {
  180. b = append(b, kok.decimal[0])
  181. inWhole = true
  182. continue
  183. }
  184. if inWhole {
  185. if count == groupThreshold {
  186. b = append(b, kok.group[0])
  187. count = 1
  188. if !inSecondary {
  189. inSecondary = true
  190. groupThreshold = 2
  191. }
  192. } else {
  193. count++
  194. }
  195. }
  196. b = append(b, s[i])
  197. }
  198. if num < 0 {
  199. b = append(b, kok.minus[0])
  200. }
  201. // reverse
  202. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  203. b[i], b[j] = b[j], b[i]
  204. }
  205. return string(b)
  206. }
  207. // FmtPercent returns 'num' with digits/precision of 'v' for 'kok' and handles both Whole and Real numbers based on 'v'
  208. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  209. func (kok *kok) FmtPercent(num float64, v uint64) string {
  210. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  211. l := len(s) + 3
  212. b := make([]byte, 0, l)
  213. for i := len(s) - 1; i >= 0; i-- {
  214. if s[i] == '.' {
  215. b = append(b, kok.decimal[0])
  216. continue
  217. }
  218. b = append(b, s[i])
  219. }
  220. if num < 0 {
  221. b = append(b, kok.minus[0])
  222. }
  223. // reverse
  224. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  225. b[i], b[j] = b[j], b[i]
  226. }
  227. b = append(b, kok.percent...)
  228. return string(b)
  229. }
  230. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'kok'
  231. func (kok *kok) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  232. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  233. symbol := kok.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. inSecondary := false
  238. groupThreshold := 3
  239. b := make([]byte, 0, l)
  240. for i := len(s) - 1; i >= 0; i-- {
  241. if s[i] == '.' {
  242. b = append(b, kok.decimal[0])
  243. inWhole = true
  244. continue
  245. }
  246. if inWhole {
  247. if count == groupThreshold {
  248. b = append(b, kok.group[0])
  249. count = 1
  250. if !inSecondary {
  251. inSecondary = true
  252. groupThreshold = 2
  253. }
  254. } else {
  255. count++
  256. }
  257. }
  258. b = append(b, s[i])
  259. }
  260. for j := len(symbol) - 1; j >= 0; j-- {
  261. b = append(b, symbol[j])
  262. }
  263. for j := len(kok.currencyPositivePrefix) - 1; j >= 0; j-- {
  264. b = append(b, kok.currencyPositivePrefix[j])
  265. }
  266. if num < 0 {
  267. b = append(b, kok.minus[0])
  268. }
  269. // reverse
  270. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  271. b[i], b[j] = b[j], b[i]
  272. }
  273. if int(v) < 2 {
  274. if v == 0 {
  275. b = append(b, kok.decimal...)
  276. }
  277. for i := 0; i < 2-int(v); i++ {
  278. b = append(b, '0')
  279. }
  280. }
  281. return string(b)
  282. }
  283. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'kok'
  284. // in accounting notation.
  285. func (kok *kok) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  286. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  287. symbol := kok.currencies[currency]
  288. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  289. count := 0
  290. inWhole := v == 0
  291. inSecondary := false
  292. groupThreshold := 3
  293. b := make([]byte, 0, l)
  294. for i := len(s) - 1; i >= 0; i-- {
  295. if s[i] == '.' {
  296. b = append(b, kok.decimal[0])
  297. inWhole = true
  298. continue
  299. }
  300. if inWhole {
  301. if count == groupThreshold {
  302. b = append(b, kok.group[0])
  303. count = 1
  304. if !inSecondary {
  305. inSecondary = true
  306. groupThreshold = 2
  307. }
  308. } else {
  309. count++
  310. }
  311. }
  312. b = append(b, s[i])
  313. }
  314. if num < 0 {
  315. for j := len(symbol) - 1; j >= 0; j-- {
  316. b = append(b, symbol[j])
  317. }
  318. for j := len(kok.currencyNegativePrefix) - 1; j >= 0; j-- {
  319. b = append(b, kok.currencyNegativePrefix[j])
  320. }
  321. b = append(b, kok.minus[0])
  322. } else {
  323. for j := len(symbol) - 1; j >= 0; j-- {
  324. b = append(b, symbol[j])
  325. }
  326. for j := len(kok.currencyPositivePrefix) - 1; j >= 0; j-- {
  327. b = append(b, kok.currencyPositivePrefix[j])
  328. }
  329. }
  330. // reverse
  331. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  332. b[i], b[j] = b[j], b[i]
  333. }
  334. if int(v) < 2 {
  335. if v == 0 {
  336. b = append(b, kok.decimal...)
  337. }
  338. for i := 0; i < 2-int(v); i++ {
  339. b = append(b, '0')
  340. }
  341. }
  342. return string(b)
  343. }
  344. // FmtDateShort returns the short date representation of 't' for 'kok'
  345. func (kok *kok) FmtDateShort(t time.Time) string {
  346. b := make([]byte, 0, 32)
  347. b = strconv.AppendInt(b, int64(t.Day()), 10)
  348. b = append(b, []byte{0x2d}...)
  349. b = strconv.AppendInt(b, int64(t.Month()), 10)
  350. b = append(b, []byte{0x2d}...)
  351. if t.Year() > 9 {
  352. b = append(b, strconv.Itoa(t.Year())[2:]...)
  353. } else {
  354. b = append(b, strconv.Itoa(t.Year())[1:]...)
  355. }
  356. return string(b)
  357. }
  358. // FmtDateMedium returns the medium date representation of 't' for 'kok'
  359. func (kok *kok) FmtDateMedium(t time.Time) string {
  360. b := make([]byte, 0, 32)
  361. if t.Day() < 10 {
  362. b = append(b, '0')
  363. }
  364. b = strconv.AppendInt(b, int64(t.Day()), 10)
  365. b = append(b, []byte{0x2d}...)
  366. if t.Month() < 10 {
  367. b = append(b, '0')
  368. }
  369. b = strconv.AppendInt(b, int64(t.Month()), 10)
  370. b = append(b, []byte{0x2d}...)
  371. if t.Year() > 0 {
  372. b = strconv.AppendInt(b, int64(t.Year()), 10)
  373. } else {
  374. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  375. }
  376. return string(b)
  377. }
  378. // FmtDateLong returns the long date representation of 't' for 'kok'
  379. func (kok *kok) FmtDateLong(t time.Time) string {
  380. b := make([]byte, 0, 32)
  381. b = strconv.AppendInt(b, int64(t.Day()), 10)
  382. b = append(b, []byte{0x20}...)
  383. b = append(b, kok.monthsWide[t.Month()]...)
  384. b = append(b, []byte{0x20}...)
  385. if t.Year() > 0 {
  386. b = strconv.AppendInt(b, int64(t.Year()), 10)
  387. } else {
  388. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  389. }
  390. return string(b)
  391. }
  392. // FmtDateFull returns the full date representation of 't' for 'kok'
  393. func (kok *kok) FmtDateFull(t time.Time) string {
  394. b := make([]byte, 0, 32)
  395. b = append(b, kok.daysWide[t.Weekday()]...)
  396. b = append(b, []byte{0x20}...)
  397. b = strconv.AppendInt(b, int64(t.Day()), 10)
  398. b = append(b, []byte{0x20}...)
  399. b = append(b, kok.monthsWide[t.Month()]...)
  400. b = append(b, []byte{0x20}...)
  401. if t.Year() > 0 {
  402. b = strconv.AppendInt(b, int64(t.Year()), 10)
  403. } else {
  404. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  405. }
  406. return string(b)
  407. }
  408. // FmtTimeShort returns the short time representation of 't' for 'kok'
  409. func (kok *kok) FmtTimeShort(t time.Time) string {
  410. b := make([]byte, 0, 32)
  411. h := t.Hour()
  412. if h > 12 {
  413. h -= 12
  414. }
  415. b = strconv.AppendInt(b, int64(h), 10)
  416. b = append(b, kok.timeSeparator...)
  417. if t.Minute() < 10 {
  418. b = append(b, '0')
  419. }
  420. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  421. b = append(b, []byte{0x20}...)
  422. if t.Hour() < 12 {
  423. b = append(b, kok.periodsAbbreviated[0]...)
  424. } else {
  425. b = append(b, kok.periodsAbbreviated[1]...)
  426. }
  427. return string(b)
  428. }
  429. // FmtTimeMedium returns the medium time representation of 't' for 'kok'
  430. func (kok *kok) FmtTimeMedium(t time.Time) string {
  431. b := make([]byte, 0, 32)
  432. h := t.Hour()
  433. if h > 12 {
  434. h -= 12
  435. }
  436. b = strconv.AppendInt(b, int64(h), 10)
  437. b = append(b, kok.timeSeparator...)
  438. if t.Minute() < 10 {
  439. b = append(b, '0')
  440. }
  441. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  442. b = append(b, kok.timeSeparator...)
  443. if t.Second() < 10 {
  444. b = append(b, '0')
  445. }
  446. b = strconv.AppendInt(b, int64(t.Second()), 10)
  447. b = append(b, []byte{0x20}...)
  448. if t.Hour() < 12 {
  449. b = append(b, kok.periodsAbbreviated[0]...)
  450. } else {
  451. b = append(b, kok.periodsAbbreviated[1]...)
  452. }
  453. return string(b)
  454. }
  455. // FmtTimeLong returns the long time representation of 't' for 'kok'
  456. func (kok *kok) FmtTimeLong(t time.Time) string {
  457. b := make([]byte, 0, 32)
  458. h := t.Hour()
  459. if h > 12 {
  460. h -= 12
  461. }
  462. b = strconv.AppendInt(b, int64(h), 10)
  463. b = append(b, kok.timeSeparator...)
  464. if t.Minute() < 10 {
  465. b = append(b, '0')
  466. }
  467. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  468. b = append(b, kok.timeSeparator...)
  469. if t.Second() < 10 {
  470. b = append(b, '0')
  471. }
  472. b = strconv.AppendInt(b, int64(t.Second()), 10)
  473. b = append(b, []byte{0x20}...)
  474. if t.Hour() < 12 {
  475. b = append(b, kok.periodsAbbreviated[0]...)
  476. } else {
  477. b = append(b, kok.periodsAbbreviated[1]...)
  478. }
  479. b = append(b, []byte{0x20}...)
  480. tz, _ := t.Zone()
  481. b = append(b, tz...)
  482. return string(b)
  483. }
  484. // FmtTimeFull returns the full time representation of 't' for 'kok'
  485. func (kok *kok) FmtTimeFull(t time.Time) string {
  486. b := make([]byte, 0, 32)
  487. h := t.Hour()
  488. if h > 12 {
  489. h -= 12
  490. }
  491. b = strconv.AppendInt(b, int64(h), 10)
  492. b = append(b, kok.timeSeparator...)
  493. if t.Minute() < 10 {
  494. b = append(b, '0')
  495. }
  496. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  497. b = append(b, kok.timeSeparator...)
  498. if t.Second() < 10 {
  499. b = append(b, '0')
  500. }
  501. b = strconv.AppendInt(b, int64(t.Second()), 10)
  502. b = append(b, []byte{0x20}...)
  503. if t.Hour() < 12 {
  504. b = append(b, kok.periodsAbbreviated[0]...)
  505. } else {
  506. b = append(b, kok.periodsAbbreviated[1]...)
  507. }
  508. b = append(b, []byte{0x20}...)
  509. tz, _ := t.Zone()
  510. if btz, ok := kok.timezones[tz]; ok {
  511. b = append(b, btz...)
  512. } else {
  513. b = append(b, tz...)
  514. }
  515. return string(b)
  516. }