cu.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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", "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", "₸", "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", "STN", "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{"пре́дъ р.\u00a0х.", "ѿ р. х."},
  69. erasNarrow: []string{"", ""},
  70. erasWide: []string{"пре́дъ р.\u00a0х.", "по р.\u00a0х."},
  71. timezones: map[string]string{"NZDT": "NZDT", "WART": "WART", "MDT": "MDT", "SRT": "SRT", "GMT": "сре́днее вре́мѧ по грі́нꙋичꙋ", "HEPMX": "HEPMX", "AWDT": "AWDT", "JDT": "JDT", "WARST": "WARST", "HNPMX": "HNPMX", "CDT": "среднеамерїка́нское лѣ́тнее вре́мѧ", "BT": "BT", "AKDT": "AKDT", "ACWST": "ACWST", "HEPM": "HEPM", "AKST": "AKST", "HEOG": "HEOG", "CLT": "CLT", "UYT": "UYT", "AWST": "AWST", "ADT": "а҆тланті́ческое лѣ́тнее вре́мѧ", "AEST": "AEST", "WIB": "WIB", "IST": "IST", "HNT": "HNT", "AEDT": "AEDT", "HEEG": "HEEG", "EAT": "EAT", "HNOG": "HNOG", "MST": "MST", "UYST": "UYST", "ECT": "ECT", "ACST": "ACST", "ACDT": "ACDT", "ACWDT": "ACWDT", "WEZ": "западноєѵрѡпе́йское зи́мнее вре́мѧ", "EST": "восточноамерїка́нское зи́мнее вре́мѧ", "WITA": "WITA", "HNPM": "HNPM", "WIT": "WIT", "TMST": "TMST", "CLST": "CLST", "COT": "COT", "HKT": "HKT", "OEZ": "восточноєѵрѡпе́йское зи́мнее вре́мѧ", "AST": "а҆тланті́ческое зи́мнее вре́мѧ", "WAT": "WAT", "MYT": "MYT", "HENOMX": "HENOMX", "CAT": "CAT", "OESZ": "восточноєѵрѡпе́йское лѣ́тнее вре́мѧ", "HNCU": "HNCU", "BOT": "BOT", "EDT": "восточноамерїка́нское лѣ́тнее вре́мѧ", "LHDT": "LHDT", "HNEG": "HNEG", "LHST": "LHST", "COST": "COST", "CHADT": "CHADT", "CST": "среднеамерїка́нское зи́мнее вре́мѧ", "PST": "тихоѻкеа́нское зи́мнее вре́мѧ", "GFT": "GFT", "NZST": "NZST", "∅∅∅": "∅∅∅", "HADT": "HADT", "JST": "JST", "TMT": "TMT", "HECU": "HECU", "HKST": "HKST", "MESZ": "среднеєѵрѡпе́йское лѣ́тнее вре́мѧ", "HAT": "HAT", "HAST": "HAST", "ART": "ART", "ARST": "ARST", "GYT": "GYT", "WESZ": "западноєѵрѡпе́йское лѣ́тнее вре́мѧ", "SGT": "SGT", "VET": "VET", "HNNOMX": "HNNOMX", "ChST": "ChST", "CHAST": "CHAST", "PDT": "тихоѻкеа́нское лѣ́тнее вре́мѧ", "SAST": "SAST", "WAST": "WAST", "MEZ": "среднеєѵрѡпе́йское зи́мнее вре́мѧ"},
  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. // Decimal returns the decimal point of number
  159. func (cu *cu) Decimal() string {
  160. return cu.decimal
  161. }
  162. // Group returns the group of number
  163. func (cu *cu) Group() string {
  164. return cu.group
  165. }
  166. // Group returns the minus sign of number
  167. func (cu *cu) Minus() string {
  168. return cu.minus
  169. }
  170. // FmtNumber returns 'num' with digits/precision of 'v' for 'cu' and handles both Whole and Real numbers based on 'v'
  171. func (cu *cu) FmtNumber(num float64, v uint64) string {
  172. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  173. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  174. count := 0
  175. inWhole := v == 0
  176. b := make([]byte, 0, l)
  177. for i := len(s) - 1; i >= 0; i-- {
  178. if s[i] == '.' {
  179. b = append(b, cu.decimal[0])
  180. inWhole = true
  181. continue
  182. }
  183. if inWhole {
  184. if count == 3 {
  185. for j := len(cu.group) - 1; j >= 0; j-- {
  186. b = append(b, cu.group[j])
  187. }
  188. count = 1
  189. } else {
  190. count++
  191. }
  192. }
  193. b = append(b, s[i])
  194. }
  195. if num < 0 {
  196. b = append(b, cu.minus[0])
  197. }
  198. // reverse
  199. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  200. b[i], b[j] = b[j], b[i]
  201. }
  202. return string(b)
  203. }
  204. // FmtPercent returns 'num' with digits/precision of 'v' for 'cu' and handles both Whole and Real numbers based on 'v'
  205. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  206. func (cu *cu) FmtPercent(num float64, v uint64) string {
  207. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  208. l := len(s) + 5
  209. b := make([]byte, 0, l)
  210. for i := len(s) - 1; i >= 0; i-- {
  211. if s[i] == '.' {
  212. b = append(b, cu.decimal[0])
  213. continue
  214. }
  215. b = append(b, s[i])
  216. }
  217. if num < 0 {
  218. b = append(b, cu.minus[0])
  219. }
  220. // reverse
  221. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  222. b[i], b[j] = b[j], b[i]
  223. }
  224. b = append(b, cu.percentSuffix...)
  225. b = append(b, cu.percent...)
  226. return string(b)
  227. }
  228. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'cu'
  229. func (cu *cu) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  230. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  231. symbol := cu.currencies[currency]
  232. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  233. count := 0
  234. inWhole := v == 0
  235. b := make([]byte, 0, l)
  236. for i := len(s) - 1; i >= 0; i-- {
  237. if s[i] == '.' {
  238. b = append(b, cu.decimal[0])
  239. inWhole = true
  240. continue
  241. }
  242. if inWhole {
  243. if count == 3 {
  244. for j := len(cu.group) - 1; j >= 0; j-- {
  245. b = append(b, cu.group[j])
  246. }
  247. count = 1
  248. } else {
  249. count++
  250. }
  251. }
  252. b = append(b, s[i])
  253. }
  254. if num < 0 {
  255. b = append(b, cu.minus[0])
  256. }
  257. // reverse
  258. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  259. b[i], b[j] = b[j], b[i]
  260. }
  261. if int(v) < 2 {
  262. if v == 0 {
  263. b = append(b, cu.decimal...)
  264. }
  265. for i := 0; i < 2-int(v); i++ {
  266. b = append(b, '0')
  267. }
  268. }
  269. b = append(b, cu.currencyPositiveSuffix...)
  270. b = append(b, symbol...)
  271. return string(b)
  272. }
  273. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'cu'
  274. // in accounting notation.
  275. func (cu *cu) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  276. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  277. symbol := cu.currencies[currency]
  278. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  279. count := 0
  280. inWhole := v == 0
  281. b := make([]byte, 0, l)
  282. for i := len(s) - 1; i >= 0; i-- {
  283. if s[i] == '.' {
  284. b = append(b, cu.decimal[0])
  285. inWhole = true
  286. continue
  287. }
  288. if inWhole {
  289. if count == 3 {
  290. for j := len(cu.group) - 1; j >= 0; j-- {
  291. b = append(b, cu.group[j])
  292. }
  293. count = 1
  294. } else {
  295. count++
  296. }
  297. }
  298. b = append(b, s[i])
  299. }
  300. if num < 0 {
  301. b = append(b, cu.minus[0])
  302. }
  303. // reverse
  304. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  305. b[i], b[j] = b[j], b[i]
  306. }
  307. if int(v) < 2 {
  308. if v == 0 {
  309. b = append(b, cu.decimal...)
  310. }
  311. for i := 0; i < 2-int(v); i++ {
  312. b = append(b, '0')
  313. }
  314. }
  315. if num < 0 {
  316. b = append(b, cu.currencyNegativeSuffix...)
  317. b = append(b, symbol...)
  318. } else {
  319. b = append(b, cu.currencyPositiveSuffix...)
  320. b = append(b, symbol...)
  321. }
  322. return string(b)
  323. }
  324. // FmtDateShort returns the short date representation of 't' for 'cu'
  325. func (cu *cu) FmtDateShort(t time.Time) string {
  326. b := make([]byte, 0, 32)
  327. if t.Year() > 0 {
  328. b = strconv.AppendInt(b, int64(t.Year()), 10)
  329. } else {
  330. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  331. }
  332. b = append(b, []byte{0x2e}...)
  333. if t.Month() < 10 {
  334. b = append(b, '0')
  335. }
  336. b = strconv.AppendInt(b, int64(t.Month()), 10)
  337. b = append(b, []byte{0x2e}...)
  338. if t.Day() < 10 {
  339. b = append(b, '0')
  340. }
  341. b = strconv.AppendInt(b, int64(t.Day()), 10)
  342. return string(b)
  343. }
  344. // FmtDateMedium returns the medium date representation of 't' for 'cu'
  345. func (cu *cu) FmtDateMedium(t time.Time) string {
  346. b := make([]byte, 0, 32)
  347. if t.Year() > 0 {
  348. b = strconv.AppendInt(b, int64(t.Year()), 10)
  349. } else {
  350. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  351. }
  352. b = append(b, []byte{0x20}...)
  353. b = append(b, cu.monthsAbbreviated[t.Month()]...)
  354. b = append(b, []byte{0x20}...)
  355. b = strconv.AppendInt(b, int64(t.Day()), 10)
  356. return string(b)
  357. }
  358. // FmtDateLong returns the long date representation of 't' for 'cu'
  359. func (cu *cu) FmtDateLong(t time.Time) string {
  360. b := make([]byte, 0, 32)
  361. if t.Year() > 0 {
  362. b = strconv.AppendInt(b, int64(t.Year()), 10)
  363. } else {
  364. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  365. }
  366. b = append(b, []byte{0x20}...)
  367. b = append(b, cu.monthsWide[t.Month()]...)
  368. b = append(b, []byte{0x20}...)
  369. b = strconv.AppendInt(b, int64(t.Day()), 10)
  370. return string(b)
  371. }
  372. // FmtDateFull returns the full date representation of 't' for 'cu'
  373. func (cu *cu) FmtDateFull(t time.Time) string {
  374. b := make([]byte, 0, 32)
  375. b = append(b, cu.daysWide[t.Weekday()]...)
  376. b = append(b, []byte{0x2c, 0x20}...)
  377. b = strconv.AppendInt(b, int64(t.Day()), 10)
  378. b = append(b, []byte{0x20}...)
  379. b = append(b, cu.monthsWide[t.Month()]...)
  380. b = append(b, []byte{0x20, 0xd0, 0xbb}...)
  381. b = append(b, []byte{0x2e, 0x20}...)
  382. if t.Year() > 0 {
  383. b = strconv.AppendInt(b, int64(t.Year()), 10)
  384. } else {
  385. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  386. }
  387. b = append(b, []byte{0x2e}...)
  388. return string(b)
  389. }
  390. // FmtTimeShort returns the short time representation of 't' for 'cu'
  391. func (cu *cu) FmtTimeShort(t time.Time) string {
  392. b := make([]byte, 0, 32)
  393. if t.Hour() < 10 {
  394. b = append(b, '0')
  395. }
  396. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  397. b = append(b, cu.timeSeparator...)
  398. if t.Minute() < 10 {
  399. b = append(b, '0')
  400. }
  401. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  402. return string(b)
  403. }
  404. // FmtTimeMedium returns the medium time representation of 't' for 'cu'
  405. func (cu *cu) FmtTimeMedium(t time.Time) string {
  406. b := make([]byte, 0, 32)
  407. if t.Hour() < 10 {
  408. b = append(b, '0')
  409. }
  410. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  411. b = append(b, cu.timeSeparator...)
  412. if t.Minute() < 10 {
  413. b = append(b, '0')
  414. }
  415. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  416. b = append(b, cu.timeSeparator...)
  417. if t.Second() < 10 {
  418. b = append(b, '0')
  419. }
  420. b = strconv.AppendInt(b, int64(t.Second()), 10)
  421. return string(b)
  422. }
  423. // FmtTimeLong returns the long time representation of 't' for 'cu'
  424. func (cu *cu) FmtTimeLong(t time.Time) string {
  425. b := make([]byte, 0, 32)
  426. if t.Hour() < 10 {
  427. b = append(b, '0')
  428. }
  429. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  430. b = append(b, cu.timeSeparator...)
  431. if t.Minute() < 10 {
  432. b = append(b, '0')
  433. }
  434. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  435. b = append(b, cu.timeSeparator...)
  436. if t.Second() < 10 {
  437. b = append(b, '0')
  438. }
  439. b = strconv.AppendInt(b, int64(t.Second()), 10)
  440. b = append(b, []byte{0x20}...)
  441. tz, _ := t.Zone()
  442. b = append(b, tz...)
  443. return string(b)
  444. }
  445. // FmtTimeFull returns the full time representation of 't' for 'cu'
  446. func (cu *cu) FmtTimeFull(t time.Time) string {
  447. b := make([]byte, 0, 32)
  448. if t.Hour() < 10 {
  449. b = append(b, '0')
  450. }
  451. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  452. b = append(b, cu.timeSeparator...)
  453. if t.Minute() < 10 {
  454. b = append(b, '0')
  455. }
  456. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  457. b = append(b, cu.timeSeparator...)
  458. if t.Second() < 10 {
  459. b = append(b, '0')
  460. }
  461. b = strconv.AppendInt(b, int64(t.Second()), 10)
  462. b = append(b, []byte{0x20}...)
  463. tz, _ := t.Zone()
  464. if btz, ok := cu.timezones[tz]; ok {
  465. b = append(b, btz...)
  466. } else {
  467. b = append(b, tz...)
  468. }
  469. return string(b)
  470. }