kok.go 18 KB

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