cu.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package cu
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type cu 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 'cu' locale
  42. func New() locales.Translator {
  43. return &cu{
  44. locale: "cu",
  45. pluralsCardinal: nil,
  46. pluralsOrdinal: nil,
  47. pluralsRange: nil,
  48. decimal: ",",
  49. group: " ",
  50. minus: "-",
  51. percent: "%",
  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", "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", "₸", "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", "₽", "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", "₴", "UAK", "UGS", "UGX", "$", "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. percentSuffix: " ",
  56. currencyPositiveSuffix: " ",
  57. currencyNegativeSuffix: " ",
  58. monthsAbbreviated: []string{"", "і҆аⷩ҇", "феⷡ҇", "маⷬ҇", "а҆пⷬ҇", "маꙵ", "і҆ꙋⷩ҇", "і҆ꙋⷧ҇", "а҆́ѵⷢ҇", "сеⷫ҇", "ѻ҆кⷮ", "ноеⷨ", "деⷦ҇"},
  59. monthsNarrow: []string{"", "І҆", "Ф", "М", "А҆", "М", "І҆", "І҆", "А҆", "С", "Ѻ҆", "Н", "Д"},
  60. monthsWide: []string{"", "і҆аннꙋа́рїа", "феврꙋа́рїа", "ма́рта", "а҆прі́ллїа", "ма́їа", "і҆ꙋ́нїа", "і҆ꙋ́лїа", "а҆́ѵгꙋста", "септе́мврїа", "ѻ҆ктѡ́врїа", "ное́мврїа", "деке́мврїа"},
  61. daysAbbreviated: []string{"ндⷧ҇ѧ", "пнⷣе", "втоⷬ҇", "срⷣе", "чеⷦ҇", "пѧⷦ҇", "сꙋⷠ҇"},
  62. daysNarrow: []string{"Н", "П", "В", "С", "Ч", "П", "С"},
  63. daysShort: []string{"ндⷧ҇ѧ", "пнⷣе", "втоⷬ҇", "срⷣе", "чеⷦ҇", "пѧⷦ҇", "сꙋⷠ҇"},
  64. daysWide: []string{"недѣ́лѧ", "понедѣ́льникъ", "вто́рникъ", "среда̀", "четверто́къ", "пѧто́къ", "сꙋббѡ́та"},
  65. periodsAbbreviated: []string{"ДП", "ПП"},
  66. periodsNarrow: []string{"ДП", "ПП"},
  67. periodsWide: []string{"ДП", "ПП"},
  68. erasAbbreviated: []string{"", ""},
  69. erasNarrow: []string{"", ""},
  70. erasWide: []string{"пре́дъ р.\u00a0х.", "по р.\u00a0х."},
  71. timezones: map[string]string{"SAST": "SAST", "UYST": "UYST", "ACWST": "ACWST", "HEOG": "HEOG", "AWST": "AWST", "WITA": "WITA", "ACWDT": "ACWDT", "HAT": "HAT", "GMT": "сре́днее вре́мѧ по грі́нꙋичꙋ", "MST": "MST", "HNT": "HNT", "ART": "ART", "AEST": "AEST", "NZDT": "NZDT", "TMST": "TMST", "CST": "среднеамерїка́нское зи́мнее вре́мѧ", "ADT": "а҆тланті́ческое лѣ́тнее вре́мѧ", "WEZ": "западноєѵрѡпе́йское зи́мнее вре́мѧ", "CHAST": "CHAST", "IST": "IST", "AKDT": "AKDT", "WIB": "WIB", "JDT": "JDT", "TMT": "TMT", "WIT": "WIT", "PST": "тихоѻкеа́нское зи́мнее вре́мѧ", "AWDT": "AWDT", "∅∅∅": "∅∅∅", "ACST": "ACST", "ACDT": "ACDT", "WARST": "WARST", "HENOMX": "HENOMX", "HAST": "HAST", "MESZ": "среднеєѵрѡпе́йское лѣ́тнее вре́мѧ", "CLT": "CLT", "HEEG": "HEEG", "MDT": "MDT", "AST": "а҆тланті́ческое зи́мнее вре́мѧ", "GFT": "GFT", "ECT": "ECT", "HEPMX": "HEPMX", "WESZ": "западноєѵрѡпе́йское лѣ́тнее вре́мѧ", "AEDT": "AEDT", "HKST": "HKST", "HEPM": "HEPM", "LHST": "LHST", "OEZ": "восточноєѵрѡпе́йское зи́мнее вре́мѧ", "WART": "WART", "BT": "BT", "HNPM": "HNPM", "HNEG": "HNEG", "OESZ": "восточноєѵрѡпе́йское лѣ́тнее вре́мѧ", "HNNOMX": "HNNOMX", "SGT": "SGT", "EST": "восточноамерїка́нское зи́мнее вре́мѧ", "HNPMX": "HNPMX", "PDT": "тихоѻкеа́нское лѣ́тнее вре́мѧ", "HKT": "HKT", "LHDT": "LHDT", "CHADT": "CHADT", "COT": "COT", "EDT": "восточноамерїка́нское лѣ́тнее вре́мѧ", "EAT": "EAT", "HECU": "HECU", "AKST": "AKST", "MYT": "MYT", "UYT": "UYT", "CLST": "CLST", "JST": "JST", "ChST": "ChST", "COST": "COST", "GYT": "GYT", "ARST": "ARST", "NZST": "NZST", "WAT": "WAT", "CDT": "среднеамерїка́нское лѣ́тнее вре́мѧ", "MEZ": "среднеєѵрѡпе́йское зи́мнее вре́мѧ", "BOT": "BOT", "CAT": "CAT", "WAST": "WAST", "HNCU": "HNCU", "HADT": "HADT", "VET": "VET", "SRT": "SRT", "HNOG": "HNOG"},
  72. }
  73. }
  74. // Locale returns the current translators string locale
  75. func (cu *cu) Locale() string {
  76. return cu.locale
  77. }
  78. // PluralsCardinal returns the list of cardinal plural rules associated with 'cu'
  79. func (cu *cu) PluralsCardinal() []locales.PluralRule {
  80. return cu.pluralsCardinal
  81. }
  82. // PluralsOrdinal returns the list of ordinal plural rules associated with 'cu'
  83. func (cu *cu) PluralsOrdinal() []locales.PluralRule {
  84. return cu.pluralsOrdinal
  85. }
  86. // PluralsRange returns the list of range plural rules associated with 'cu'
  87. func (cu *cu) PluralsRange() []locales.PluralRule {
  88. return cu.pluralsRange
  89. }
  90. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'cu'
  91. func (cu *cu) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  92. return locales.PluralRuleUnknown
  93. }
  94. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'cu'
  95. func (cu *cu) 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 'cu'
  99. func (cu *cu) 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 (cu *cu) MonthAbbreviated(month time.Month) string {
  104. return cu.monthsAbbreviated[month]
  105. }
  106. // MonthsAbbreviated returns the locales abbreviated months
  107. func (cu *cu) MonthsAbbreviated() []string {
  108. return cu.monthsAbbreviated[1:]
  109. }
  110. // MonthNarrow returns the locales narrow month given the 'month' provided
  111. func (cu *cu) MonthNarrow(month time.Month) string {
  112. return cu.monthsNarrow[month]
  113. }
  114. // MonthsNarrow returns the locales narrow months
  115. func (cu *cu) MonthsNarrow() []string {
  116. return cu.monthsNarrow[1:]
  117. }
  118. // MonthWide returns the locales wide month given the 'month' provided
  119. func (cu *cu) MonthWide(month time.Month) string {
  120. return cu.monthsWide[month]
  121. }
  122. // MonthsWide returns the locales wide months
  123. func (cu *cu) MonthsWide() []string {
  124. return cu.monthsWide[1:]
  125. }
  126. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  127. func (cu *cu) WeekdayAbbreviated(weekday time.Weekday) string {
  128. return cu.daysAbbreviated[weekday]
  129. }
  130. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  131. func (cu *cu) WeekdaysAbbreviated() []string {
  132. return cu.daysAbbreviated
  133. }
  134. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  135. func (cu *cu) WeekdayNarrow(weekday time.Weekday) string {
  136. return cu.daysNarrow[weekday]
  137. }
  138. // WeekdaysNarrow returns the locales narrow weekdays
  139. func (cu *cu) WeekdaysNarrow() []string {
  140. return cu.daysNarrow
  141. }
  142. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  143. func (cu *cu) WeekdayShort(weekday time.Weekday) string {
  144. return cu.daysShort[weekday]
  145. }
  146. // WeekdaysShort returns the locales short weekdays
  147. func (cu *cu) WeekdaysShort() []string {
  148. return cu.daysShort
  149. }
  150. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  151. func (cu *cu) WeekdayWide(weekday time.Weekday) string {
  152. return cu.daysWide[weekday]
  153. }
  154. // WeekdaysWide returns the locales wide weekdays
  155. func (cu *cu) WeekdaysWide() []string {
  156. return cu.daysWide
  157. }
  158. // FmtNumber returns 'num' with digits/precision of 'v' for 'cu' and handles both Whole and Real numbers based on 'v'
  159. func (cu *cu) FmtNumber(num float64, v uint64) string {
  160. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  161. l := len(s) + 2 + 2*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, cu.decimal[0])
  168. inWhole = true
  169. continue
  170. }
  171. if inWhole {
  172. if count == 3 {
  173. for j := len(cu.group) - 1; j >= 0; j-- {
  174. b = append(b, cu.group[j])
  175. }
  176. count = 1
  177. } else {
  178. count++
  179. }
  180. }
  181. b = append(b, s[i])
  182. }
  183. if num < 0 {
  184. b = append(b, cu.minus[0])
  185. }
  186. // reverse
  187. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  188. b[i], b[j] = b[j], b[i]
  189. }
  190. return string(b)
  191. }
  192. // FmtPercent returns 'num' with digits/precision of 'v' for 'cu' and handles both Whole and Real numbers based on 'v'
  193. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  194. func (cu *cu) FmtPercent(num float64, v uint64) string {
  195. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  196. l := len(s) + 5
  197. b := make([]byte, 0, l)
  198. for i := len(s) - 1; i >= 0; i-- {
  199. if s[i] == '.' {
  200. b = append(b, cu.decimal[0])
  201. continue
  202. }
  203. b = append(b, s[i])
  204. }
  205. if num < 0 {
  206. b = append(b, cu.minus[0])
  207. }
  208. // reverse
  209. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  210. b[i], b[j] = b[j], b[i]
  211. }
  212. b = append(b, cu.percentSuffix...)
  213. b = append(b, cu.percent...)
  214. return string(b)
  215. }
  216. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'cu'
  217. func (cu *cu) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  218. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  219. symbol := cu.currencies[currency]
  220. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  221. count := 0
  222. inWhole := v == 0
  223. b := make([]byte, 0, l)
  224. for i := len(s) - 1; i >= 0; i-- {
  225. if s[i] == '.' {
  226. b = append(b, cu.decimal[0])
  227. inWhole = true
  228. continue
  229. }
  230. if inWhole {
  231. if count == 3 {
  232. for j := len(cu.group) - 1; j >= 0; j-- {
  233. b = append(b, cu.group[j])
  234. }
  235. count = 1
  236. } else {
  237. count++
  238. }
  239. }
  240. b = append(b, s[i])
  241. }
  242. if num < 0 {
  243. b = append(b, cu.minus[0])
  244. }
  245. // reverse
  246. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  247. b[i], b[j] = b[j], b[i]
  248. }
  249. if int(v) < 2 {
  250. if v == 0 {
  251. b = append(b, cu.decimal...)
  252. }
  253. for i := 0; i < 2-int(v); i++ {
  254. b = append(b, '0')
  255. }
  256. }
  257. b = append(b, cu.currencyPositiveSuffix...)
  258. b = append(b, symbol...)
  259. return string(b)
  260. }
  261. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'cu'
  262. // in accounting notation.
  263. func (cu *cu) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  264. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  265. symbol := cu.currencies[currency]
  266. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  267. count := 0
  268. inWhole := v == 0
  269. b := make([]byte, 0, l)
  270. for i := len(s) - 1; i >= 0; i-- {
  271. if s[i] == '.' {
  272. b = append(b, cu.decimal[0])
  273. inWhole = true
  274. continue
  275. }
  276. if inWhole {
  277. if count == 3 {
  278. for j := len(cu.group) - 1; j >= 0; j-- {
  279. b = append(b, cu.group[j])
  280. }
  281. count = 1
  282. } else {
  283. count++
  284. }
  285. }
  286. b = append(b, s[i])
  287. }
  288. if num < 0 {
  289. b = append(b, cu.minus[0])
  290. }
  291. // reverse
  292. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  293. b[i], b[j] = b[j], b[i]
  294. }
  295. if int(v) < 2 {
  296. if v == 0 {
  297. b = append(b, cu.decimal...)
  298. }
  299. for i := 0; i < 2-int(v); i++ {
  300. b = append(b, '0')
  301. }
  302. }
  303. if num < 0 {
  304. b = append(b, cu.currencyNegativeSuffix...)
  305. b = append(b, symbol...)
  306. } else {
  307. b = append(b, cu.currencyPositiveSuffix...)
  308. b = append(b, symbol...)
  309. }
  310. return string(b)
  311. }
  312. // FmtDateShort returns the short date representation of 't' for 'cu'
  313. func (cu *cu) FmtDateShort(t time.Time) string {
  314. b := make([]byte, 0, 32)
  315. if t.Year() > 0 {
  316. b = strconv.AppendInt(b, int64(t.Year()), 10)
  317. } else {
  318. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  319. }
  320. b = append(b, []byte{0x2e}...)
  321. if t.Month() < 10 {
  322. b = append(b, '0')
  323. }
  324. b = strconv.AppendInt(b, int64(t.Month()), 10)
  325. b = append(b, []byte{0x2e}...)
  326. if t.Day() < 10 {
  327. b = append(b, '0')
  328. }
  329. b = strconv.AppendInt(b, int64(t.Day()), 10)
  330. return string(b)
  331. }
  332. // FmtDateMedium returns the medium date representation of 't' for 'cu'
  333. func (cu *cu) FmtDateMedium(t time.Time) string {
  334. b := make([]byte, 0, 32)
  335. if t.Year() > 0 {
  336. b = strconv.AppendInt(b, int64(t.Year()), 10)
  337. } else {
  338. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  339. }
  340. b = append(b, []byte{0x20}...)
  341. b = append(b, cu.monthsAbbreviated[t.Month()]...)
  342. b = append(b, []byte{0x20}...)
  343. b = strconv.AppendInt(b, int64(t.Day()), 10)
  344. return string(b)
  345. }
  346. // FmtDateLong returns the long date representation of 't' for 'cu'
  347. func (cu *cu) FmtDateLong(t time.Time) string {
  348. b := make([]byte, 0, 32)
  349. if t.Year() > 0 {
  350. b = strconv.AppendInt(b, int64(t.Year()), 10)
  351. } else {
  352. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  353. }
  354. b = append(b, []byte{0x20}...)
  355. b = append(b, cu.monthsWide[t.Month()]...)
  356. b = append(b, []byte{0x20}...)
  357. b = strconv.AppendInt(b, int64(t.Day()), 10)
  358. return string(b)
  359. }
  360. // FmtDateFull returns the full date representation of 't' for 'cu'
  361. func (cu *cu) FmtDateFull(t time.Time) string {
  362. b := make([]byte, 0, 32)
  363. b = append(b, cu.daysWide[t.Weekday()]...)
  364. b = append(b, []byte{0x2c, 0x20}...)
  365. b = strconv.AppendInt(b, int64(t.Day()), 10)
  366. b = append(b, []byte{0x20}...)
  367. b = append(b, cu.monthsWide[t.Month()]...)
  368. b = append(b, []byte{0x20, 0xd0, 0xbb}...)
  369. b = append(b, []byte{0x2e, 0x20}...)
  370. if t.Year() > 0 {
  371. b = strconv.AppendInt(b, int64(t.Year()), 10)
  372. } else {
  373. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  374. }
  375. b = append(b, []byte{0x2e}...)
  376. return string(b)
  377. }
  378. // FmtTimeShort returns the short time representation of 't' for 'cu'
  379. func (cu *cu) FmtTimeShort(t time.Time) string {
  380. b := make([]byte, 0, 32)
  381. if t.Hour() < 10 {
  382. b = append(b, '0')
  383. }
  384. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  385. b = append(b, cu.timeSeparator...)
  386. if t.Minute() < 10 {
  387. b = append(b, '0')
  388. }
  389. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  390. return string(b)
  391. }
  392. // FmtTimeMedium returns the medium time representation of 't' for 'cu'
  393. func (cu *cu) FmtTimeMedium(t time.Time) string {
  394. b := make([]byte, 0, 32)
  395. if t.Hour() < 10 {
  396. b = append(b, '0')
  397. }
  398. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  399. b = append(b, cu.timeSeparator...)
  400. if t.Minute() < 10 {
  401. b = append(b, '0')
  402. }
  403. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  404. b = append(b, cu.timeSeparator...)
  405. if t.Second() < 10 {
  406. b = append(b, '0')
  407. }
  408. b = strconv.AppendInt(b, int64(t.Second()), 10)
  409. return string(b)
  410. }
  411. // FmtTimeLong returns the long time representation of 't' for 'cu'
  412. func (cu *cu) FmtTimeLong(t time.Time) string {
  413. b := make([]byte, 0, 32)
  414. if t.Hour() < 10 {
  415. b = append(b, '0')
  416. }
  417. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  418. b = append(b, cu.timeSeparator...)
  419. if t.Minute() < 10 {
  420. b = append(b, '0')
  421. }
  422. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  423. b = append(b, cu.timeSeparator...)
  424. if t.Second() < 10 {
  425. b = append(b, '0')
  426. }
  427. b = strconv.AppendInt(b, int64(t.Second()), 10)
  428. b = append(b, []byte{0x20}...)
  429. tz, _ := t.Zone()
  430. b = append(b, tz...)
  431. return string(b)
  432. }
  433. // FmtTimeFull returns the full time representation of 't' for 'cu'
  434. func (cu *cu) FmtTimeFull(t time.Time) string {
  435. b := make([]byte, 0, 32)
  436. if t.Hour() < 10 {
  437. b = append(b, '0')
  438. }
  439. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  440. b = append(b, cu.timeSeparator...)
  441. if t.Minute() < 10 {
  442. b = append(b, '0')
  443. }
  444. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  445. b = append(b, cu.timeSeparator...)
  446. if t.Second() < 10 {
  447. b = append(b, '0')
  448. }
  449. b = strconv.AppendInt(b, int64(t.Second()), 10)
  450. b = append(b, []byte{0x20}...)
  451. tz, _ := t.Zone()
  452. if btz, ok := cu.timezones[tz]; ok {
  453. b = append(b, btz...)
  454. } else {
  455. b = append(b, tz...)
  456. }
  457. return string(b)
  458. }