1package ckb 2 3import ( 4 "math" 5 "strconv" 6 "time" 7 8 "github.com/gohugoio/locales" 9 "github.com/gohugoio/locales/currency" 10) 11 12type ckb struct { 13 locale string 14 pluralsCardinal []locales.PluralRule 15 pluralsOrdinal []locales.PluralRule 16 pluralsRange []locales.PluralRule 17 decimal string 18 group string 19 minus string 20 percent string 21 percentSuffix string 22 perMille string 23 timeSeparator string 24 inifinity string 25 currencies []string // idx = enum of currency code 26 currencyPositiveSuffix string 27 currencyNegativeSuffix string 28 monthsAbbreviated []string 29 monthsNarrow []string 30 monthsWide []string 31 daysAbbreviated []string 32 daysNarrow []string 33 daysShort []string 34 daysWide []string 35 periodsAbbreviated []string 36 periodsNarrow []string 37 periodsShort []string 38 periodsWide []string 39 erasAbbreviated []string 40 erasNarrow []string 41 erasWide []string 42 timezones map[string]string 43} 44 45// New returns a new instance of translator for the 'ckb' locale 46func New() locales.Translator { 47 return &ckb{ 48 locale: "ckb", 49 pluralsCardinal: []locales.PluralRule{2, 6}, 50 pluralsOrdinal: nil, 51 pluralsRange: nil, 52 decimal: "٫", 53 group: "٬", 54 minus: "-", 55 percent: "٪", 56 perMille: "؉", 57 timeSeparator: ":", 58 inifinity: "∞", 59 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", "MRU", "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", "UYW", "UZS", "VEB", "VEF", "VES", "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"}, 60 percentSuffix: " ", 61 currencyPositiveSuffix: " ", 62 currencyNegativeSuffix: " ", 63 monthsAbbreviated: []string{"", "کانوونی دووەم", "شوبات", "ئازار", "نیسان", "ئایار", "حوزەیران", "تەمووز", "ئاب", "ئەیلوول", "تشرینی یەکەم", "تشرینی دووەم", "کانونی یەکەم"}, 64 monthsNarrow: []string{"", "ک", "ش", "ئ", "ن", "ئ", "ح", "ت", "ئ", "ئ", "ت", "ت", "ک"}, 65 monthsWide: []string{"", "کانوونی دووەم", "شوبات", "ئازار", "نیسان", "ئایار", "حوزەیران", "تەمووز", "ئاب", "ئەیلوول", "تشرینی یەکەم", "تشرینی دووەم", "کانونی یەکەم"}, 66 daysAbbreviated: []string{"یەکشەممە", "دووشەممە", "سێشەممە", "چوارشەممە", "پێنجشەممە", "ھەینی", "شەممە"}, 67 daysNarrow: []string{"ی", "د", "س", "چ", "پ", "ھ", "ش"}, 68 daysShort: []string{"١ش", "٢ش", "٣ش", "٤ش", "٥ش", "ھ", "ش"}, 69 daysWide: []string{"یەکشەممە", "دووشەممە", "سێشەممە", "چوارشەممە", "پێنجشەممە", "ھەینی", "شەممە"}, 70 periodsAbbreviated: []string{"ب.ن", "د.ن"}, 71 periodsNarrow: []string{"ب.ن", "د.ن"}, 72 periodsWide: []string{"ب.ن", "د.ن"}, 73 erasAbbreviated: []string{"پێش زایین", "زایینی"}, 74 erasNarrow: []string{"پ.ن", "ز"}, 75 erasWide: []string{"پێش زایین", "زایینی"}, 76 timezones: map[string]string{"ACDT": "ACDT", "ACST": "ACST", "ACWDT": "ACWDT", "ACWST": "ACWST", "ADT": "ADT", "AEDT": "AEDT", "AEST": "AEST", "AKDT": "AKDT", "AKST": "AKST", "ARST": "ARST", "ART": "ART", "AST": "AST", "AWDT": "AWDT", "AWST": "AWST", "BOT": "BOT", "BT": "BT", "CAT": "CAT", "CDT": "CDT", "CHADT": "CHADT", "CHAST": "CHAST", "CLST": "CLST", "CLT": "CLT", "COST": "COST", "COT": "COT", "CST": "CST", "ChST": "ChST", "EAT": "EAT", "ECT": "ECT", "EDT": "EDT", "EST": "EST", "GFT": "GFT", "GMT": "GMT", "GST": "GST", "GYT": "GYT", "HADT": "HADT", "HAST": "HAST", "HAT": "HAT", "HECU": "HECU", "HEEG": "HEEG", "HENOMX": "HENOMX", "HEOG": "HEOG", "HEPM": "HEPM", "HEPMX": "HEPMX", "HKST": "HKST", "HKT": "HKT", "HNCU": "HNCU", "HNEG": "HNEG", "HNNOMX": "HNNOMX", "HNOG": "HNOG", "HNPM": "HNPM", "HNPMX": "HNPMX", "HNT": "HNT", "IST": "IST", "JDT": "JDT", "JST": "JST", "LHDT": "LHDT", "LHST": "LHST", "MDT": "MDT", "MESZ": "MESZ", "MEZ": "MEZ", "MST": "MST", "MYT": "MYT", "NZDT": "NZDT", "NZST": "NZST", "OESZ": "OESZ", "OEZ": "OEZ", "PDT": "PDT", "PST": "PST", "SAST": "SAST", "SGT": "SGT", "SRT": "SRT", "TMST": "TMST", "TMT": "TMT", "UYST": "UYST", "UYT": "UYT", "VET": "VET", "WARST": "WARST", "WART": "WART", "WAST": "WAST", "WAT": "WAT", "WESZ": "WESZ", "WEZ": "WEZ", "WIB": "WIB", "WIT": "WIT", "WITA": "WITA", "∅∅∅": "∅∅∅"}, 77 } 78} 79 80// Locale returns the current translators string locale 81func (ckb *ckb) Locale() string { 82 return ckb.locale 83} 84 85// PluralsCardinal returns the list of cardinal plural rules associated with 'ckb' 86func (ckb *ckb) PluralsCardinal() []locales.PluralRule { 87 return ckb.pluralsCardinal 88} 89 90// PluralsOrdinal returns the list of ordinal plural rules associated with 'ckb' 91func (ckb *ckb) PluralsOrdinal() []locales.PluralRule { 92 return ckb.pluralsOrdinal 93} 94 95// PluralsRange returns the list of range plural rules associated with 'ckb' 96func (ckb *ckb) PluralsRange() []locales.PluralRule { 97 return ckb.pluralsRange 98} 99 100// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ckb' 101func (ckb *ckb) CardinalPluralRule(num float64, v uint64) locales.PluralRule { 102 103 n := math.Abs(num) 104 105 if n == 1 { 106 return locales.PluralRuleOne 107 } 108 109 return locales.PluralRuleOther 110} 111 112// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ckb' 113func (ckb *ckb) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 114 return locales.PluralRuleUnknown 115} 116 117// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ckb' 118func (ckb *ckb) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 119 return locales.PluralRuleUnknown 120} 121 122// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 123func (ckb *ckb) MonthAbbreviated(month time.Month) string { 124 return ckb.monthsAbbreviated[month] 125} 126 127// MonthsAbbreviated returns the locales abbreviated months 128func (ckb *ckb) MonthsAbbreviated() []string { 129 return ckb.monthsAbbreviated[1:] 130} 131 132// MonthNarrow returns the locales narrow month given the 'month' provided 133func (ckb *ckb) MonthNarrow(month time.Month) string { 134 return ckb.monthsNarrow[month] 135} 136 137// MonthsNarrow returns the locales narrow months 138func (ckb *ckb) MonthsNarrow() []string { 139 return ckb.monthsNarrow[1:] 140} 141 142// MonthWide returns the locales wide month given the 'month' provided 143func (ckb *ckb) MonthWide(month time.Month) string { 144 return ckb.monthsWide[month] 145} 146 147// MonthsWide returns the locales wide months 148func (ckb *ckb) MonthsWide() []string { 149 return ckb.monthsWide[1:] 150} 151 152// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 153func (ckb *ckb) WeekdayAbbreviated(weekday time.Weekday) string { 154 return ckb.daysAbbreviated[weekday] 155} 156 157// WeekdaysAbbreviated returns the locales abbreviated weekdays 158func (ckb *ckb) WeekdaysAbbreviated() []string { 159 return ckb.daysAbbreviated 160} 161 162// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 163func (ckb *ckb) WeekdayNarrow(weekday time.Weekday) string { 164 return ckb.daysNarrow[weekday] 165} 166 167// WeekdaysNarrow returns the locales narrow weekdays 168func (ckb *ckb) WeekdaysNarrow() []string { 169 return ckb.daysNarrow 170} 171 172// WeekdayShort returns the locales short weekday given the 'weekday' provided 173func (ckb *ckb) WeekdayShort(weekday time.Weekday) string { 174 return ckb.daysShort[weekday] 175} 176 177// WeekdaysShort returns the locales short weekdays 178func (ckb *ckb) WeekdaysShort() []string { 179 return ckb.daysShort 180} 181 182// WeekdayWide returns the locales wide weekday given the 'weekday' provided 183func (ckb *ckb) WeekdayWide(weekday time.Weekday) string { 184 return ckb.daysWide[weekday] 185} 186 187// WeekdaysWide returns the locales wide weekdays 188func (ckb *ckb) WeekdaysWide() []string { 189 return ckb.daysWide 190} 191 192// Decimal returns the decimal point of number 193func (ckb *ckb) Decimal() string { 194 return ckb.decimal 195} 196 197// Group returns the group of number 198func (ckb *ckb) Group() string { 199 return ckb.group 200} 201 202// Group returns the minus sign of number 203func (ckb *ckb) Minus() string { 204 return ckb.minus 205} 206 207// FmtNumber returns 'num' with digits/precision of 'v' for 'ckb' and handles both Whole and Real numbers based on 'v' 208func (ckb *ckb) FmtNumber(num float64, v uint64) string { 209 210 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 211 l := len(s) + 6 + 2*len(s[:len(s)-int(v)-1])/3 212 count := 0 213 inWhole := v == 0 214 b := make([]byte, 0, l) 215 216 for i := len(s) - 1; i >= 0; i-- { 217 218 if s[i] == '.' { 219 for j := len(ckb.decimal) - 1; j >= 0; j-- { 220 b = append(b, ckb.decimal[j]) 221 } 222 inWhole = true 223 continue 224 } 225 226 if inWhole { 227 if count == 3 { 228 for j := len(ckb.group) - 1; j >= 0; j-- { 229 b = append(b, ckb.group[j]) 230 } 231 count = 1 232 } else { 233 count++ 234 } 235 } 236 237 b = append(b, s[i]) 238 } 239 240 if num < 0 { 241 for j := len(ckb.minus) - 1; j >= 0; j-- { 242 b = append(b, ckb.minus[j]) 243 } 244 } 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 251 return string(b) 252} 253 254// FmtPercent returns 'num' with digits/precision of 'v' for 'ckb' and handles both Whole and Real numbers based on 'v' 255// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 256func (ckb *ckb) FmtPercent(num float64, v uint64) string { 257 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 258 l := len(s) + 10 259 b := make([]byte, 0, l) 260 261 for i := len(s) - 1; i >= 0; i-- { 262 263 if s[i] == '.' { 264 for j := len(ckb.decimal) - 1; j >= 0; j-- { 265 b = append(b, ckb.decimal[j]) 266 } 267 continue 268 } 269 270 b = append(b, s[i]) 271 } 272 273 if num < 0 { 274 for j := len(ckb.minus) - 1; j >= 0; j-- { 275 b = append(b, ckb.minus[j]) 276 } 277 } 278 279 // reverse 280 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 281 b[i], b[j] = b[j], b[i] 282 } 283 284 b = append(b, ckb.percentSuffix...) 285 286 b = append(b, ckb.percent...) 287 288 return string(b) 289} 290 291// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ckb' 292func (ckb *ckb) FmtCurrency(num float64, v uint64, currency currency.Type) string { 293 294 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 295 symbol := ckb.currencies[currency] 296 l := len(s) + len(symbol) + 8 + 2*len(s[:len(s)-int(v)-1])/3 297 count := 0 298 inWhole := v == 0 299 b := make([]byte, 0, l) 300 301 for i := len(s) - 1; i >= 0; i-- { 302 303 if s[i] == '.' { 304 for j := len(ckb.decimal) - 1; j >= 0; j-- { 305 b = append(b, ckb.decimal[j]) 306 } 307 inWhole = true 308 continue 309 } 310 311 if inWhole { 312 if count == 3 { 313 for j := len(ckb.group) - 1; j >= 0; j-- { 314 b = append(b, ckb.group[j]) 315 } 316 count = 1 317 } else { 318 count++ 319 } 320 } 321 322 b = append(b, s[i]) 323 } 324 325 if num < 0 { 326 for j := len(ckb.minus) - 1; j >= 0; j-- { 327 b = append(b, ckb.minus[j]) 328 } 329 } 330 331 // reverse 332 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 333 b[i], b[j] = b[j], b[i] 334 } 335 336 if int(v) < 2 { 337 338 if v == 0 { 339 b = append(b, ckb.decimal...) 340 } 341 342 for i := 0; i < 2-int(v); i++ { 343 b = append(b, '0') 344 } 345 } 346 347 b = append(b, ckb.currencyPositiveSuffix...) 348 349 b = append(b, symbol...) 350 351 return string(b) 352} 353 354// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ckb' 355// in accounting notation. 356func (ckb *ckb) FmtAccounting(num float64, v uint64, currency currency.Type) string { 357 358 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 359 symbol := ckb.currencies[currency] 360 l := len(s) + len(symbol) + 8 + 2*len(s[:len(s)-int(v)-1])/3 361 count := 0 362 inWhole := v == 0 363 b := make([]byte, 0, l) 364 365 for i := len(s) - 1; i >= 0; i-- { 366 367 if s[i] == '.' { 368 for j := len(ckb.decimal) - 1; j >= 0; j-- { 369 b = append(b, ckb.decimal[j]) 370 } 371 inWhole = true 372 continue 373 } 374 375 if inWhole { 376 if count == 3 { 377 for j := len(ckb.group) - 1; j >= 0; j-- { 378 b = append(b, ckb.group[j]) 379 } 380 count = 1 381 } else { 382 count++ 383 } 384 } 385 386 b = append(b, s[i]) 387 } 388 389 if num < 0 { 390 391 for j := len(ckb.minus) - 1; j >= 0; j-- { 392 b = append(b, ckb.minus[j]) 393 } 394 395 } 396 397 // reverse 398 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 399 b[i], b[j] = b[j], b[i] 400 } 401 402 if int(v) < 2 { 403 404 if v == 0 { 405 b = append(b, ckb.decimal...) 406 } 407 408 for i := 0; i < 2-int(v); i++ { 409 b = append(b, '0') 410 } 411 } 412 413 if num < 0 { 414 b = append(b, ckb.currencyNegativeSuffix...) 415 b = append(b, symbol...) 416 } else { 417 418 b = append(b, ckb.currencyPositiveSuffix...) 419 b = append(b, symbol...) 420 } 421 422 return string(b) 423} 424 425// FmtDateShort returns the short date representation of 't' for 'ckb' 426func (ckb *ckb) FmtDateShort(t time.Time) string { 427 428 b := make([]byte, 0, 32) 429 430 if t.Year() > 0 { 431 b = strconv.AppendInt(b, int64(t.Year()), 10) 432 } else { 433 b = strconv.AppendInt(b, int64(-t.Year()), 10) 434 } 435 436 b = append(b, []byte{0x2d}...) 437 438 if t.Month() < 10 { 439 b = append(b, '0') 440 } 441 442 b = strconv.AppendInt(b, int64(t.Month()), 10) 443 444 b = append(b, []byte{0x2d}...) 445 446 if t.Day() < 10 { 447 b = append(b, '0') 448 } 449 450 b = strconv.AppendInt(b, int64(t.Day()), 10) 451 452 return string(b) 453} 454 455// FmtDateMedium returns the medium date representation of 't' for 'ckb' 456func (ckb *ckb) FmtDateMedium(t time.Time) string { 457 458 b := make([]byte, 0, 32) 459 460 if t.Year() > 0 { 461 b = strconv.AppendInt(b, int64(t.Year()), 10) 462 } else { 463 b = strconv.AppendInt(b, int64(-t.Year()), 10) 464 } 465 466 b = append(b, []byte{0x20}...) 467 b = append(b, ckb.monthsAbbreviated[t.Month()]...) 468 b = append(b, []byte{0x20}...) 469 b = strconv.AppendInt(b, int64(t.Day()), 10) 470 471 return string(b) 472} 473 474// FmtDateLong returns the long date representation of 't' for 'ckb' 475func (ckb *ckb) FmtDateLong(t time.Time) string { 476 477 b := make([]byte, 0, 32) 478 479 b = strconv.AppendInt(b, int64(t.Day()), 10) 480 b = append(b, []byte{0xdb, 0x8c, 0x20}...) 481 b = append(b, ckb.monthsWide[t.Month()]...) 482 b = append(b, []byte{0xdb, 0x8c, 0x20}...) 483 484 if t.Year() > 0 { 485 b = strconv.AppendInt(b, int64(t.Year()), 10) 486 } else { 487 b = strconv.AppendInt(b, int64(-t.Year()), 10) 488 } 489 490 return string(b) 491} 492 493// FmtDateFull returns the full date representation of 't' for 'ckb' 494func (ckb *ckb) FmtDateFull(t time.Time) string { 495 496 b := make([]byte, 0, 32) 497 498 if t.Year() > 0 { 499 b = strconv.AppendInt(b, int64(t.Year()), 10) 500 } else { 501 b = strconv.AppendInt(b, int64(-t.Year()), 10) 502 } 503 504 b = append(b, []byte{0x20}...) 505 b = append(b, ckb.monthsWide[t.Month()]...) 506 b = append(b, []byte{0x20}...) 507 b = strconv.AppendInt(b, int64(t.Day()), 10) 508 b = append(b, []byte{0x2c, 0x20}...) 509 b = append(b, ckb.daysWide[t.Weekday()]...) 510 511 return string(b) 512} 513 514// FmtTimeShort returns the short time representation of 't' for 'ckb' 515func (ckb *ckb) FmtTimeShort(t time.Time) string { 516 517 b := make([]byte, 0, 32) 518 519 h := t.Hour() 520 521 if h > 12 { 522 h -= 12 523 } 524 525 b = strconv.AppendInt(b, int64(h), 10) 526 b = append(b, ckb.timeSeparator...) 527 528 if t.Minute() < 10 { 529 b = append(b, '0') 530 } 531 532 b = strconv.AppendInt(b, int64(t.Minute()), 10) 533 b = append(b, []byte{0x20}...) 534 535 if t.Hour() < 12 { 536 b = append(b, ckb.periodsAbbreviated[0]...) 537 } else { 538 b = append(b, ckb.periodsAbbreviated[1]...) 539 } 540 541 return string(b) 542} 543 544// FmtTimeMedium returns the medium time representation of 't' for 'ckb' 545func (ckb *ckb) FmtTimeMedium(t time.Time) string { 546 547 b := make([]byte, 0, 32) 548 549 h := t.Hour() 550 551 if h > 12 { 552 h -= 12 553 } 554 555 b = strconv.AppendInt(b, int64(h), 10) 556 b = append(b, ckb.timeSeparator...) 557 558 if t.Minute() < 10 { 559 b = append(b, '0') 560 } 561 562 b = strconv.AppendInt(b, int64(t.Minute()), 10) 563 b = append(b, ckb.timeSeparator...) 564 565 if t.Second() < 10 { 566 b = append(b, '0') 567 } 568 569 b = strconv.AppendInt(b, int64(t.Second()), 10) 570 b = append(b, []byte{0x20}...) 571 572 if t.Hour() < 12 { 573 b = append(b, ckb.periodsAbbreviated[0]...) 574 } else { 575 b = append(b, ckb.periodsAbbreviated[1]...) 576 } 577 578 return string(b) 579} 580 581// FmtTimeLong returns the long time representation of 't' for 'ckb' 582func (ckb *ckb) FmtTimeLong(t time.Time) string { 583 584 b := make([]byte, 0, 32) 585 586 h := t.Hour() 587 588 if h > 12 { 589 h -= 12 590 } 591 592 b = strconv.AppendInt(b, int64(h), 10) 593 b = append(b, ckb.timeSeparator...) 594 595 if t.Minute() < 10 { 596 b = append(b, '0') 597 } 598 599 b = strconv.AppendInt(b, int64(t.Minute()), 10) 600 b = append(b, ckb.timeSeparator...) 601 602 if t.Second() < 10 { 603 b = append(b, '0') 604 } 605 606 b = strconv.AppendInt(b, int64(t.Second()), 10) 607 b = append(b, []byte{0x20}...) 608 609 if t.Hour() < 12 { 610 b = append(b, ckb.periodsAbbreviated[0]...) 611 } else { 612 b = append(b, ckb.periodsAbbreviated[1]...) 613 } 614 615 b = append(b, []byte{0x20}...) 616 617 tz, _ := t.Zone() 618 b = append(b, tz...) 619 620 return string(b) 621} 622 623// FmtTimeFull returns the full time representation of 't' for 'ckb' 624func (ckb *ckb) FmtTimeFull(t time.Time) string { 625 626 b := make([]byte, 0, 32) 627 628 h := t.Hour() 629 630 if h > 12 { 631 h -= 12 632 } 633 634 b = strconv.AppendInt(b, int64(h), 10) 635 b = append(b, ckb.timeSeparator...) 636 637 if t.Minute() < 10 { 638 b = append(b, '0') 639 } 640 641 b = strconv.AppendInt(b, int64(t.Minute()), 10) 642 b = append(b, ckb.timeSeparator...) 643 644 if t.Second() < 10 { 645 b = append(b, '0') 646 } 647 648 b = strconv.AppendInt(b, int64(t.Second()), 10) 649 b = append(b, []byte{0x20}...) 650 651 if t.Hour() < 12 { 652 b = append(b, ckb.periodsAbbreviated[0]...) 653 } else { 654 b = append(b, ckb.periodsAbbreviated[1]...) 655 } 656 657 b = append(b, []byte{0x20}...) 658 659 tz, _ := t.Zone() 660 661 if btz, ok := ckb.timezones[tz]; ok { 662 b = append(b, btz...) 663 } else { 664 b = append(b, tz...) 665 } 666 667 return string(b) 668} 669