ckb.go 19 KB

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