cs.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. package cs
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type cs 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 'cs' locale
  42. func New() locales.Translator {
  43. return &cs{
  44. locale: "cs",
  45. pluralsCardinal: []locales.PluralRule{2, 4, 5, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: []locales.PluralRule{2, 4, 5, 6},
  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", "AU$", "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", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNX", "CN¥", "COP", "COU", "CRC", "CSD", "Kčs", "CUC", "CUP", "CVE", "CYP", "Kč", "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", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JP¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "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", "MX$", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZ$", "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", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "ECU", "XFO", "XFU", "CFA", "XPD", "CFPF", "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{"", "led", "úno", "bře", "dub", "kvě", "čvn", "čvc", "srp", "zář", "říj", "lis", "pro"},
  60. monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  61. monthsWide: []string{"", "ledna", "února", "března", "dubna", "května", "června", "července", "srpna", "září", "října", "listopadu", "prosince"},
  62. daysAbbreviated: []string{"ne", "po", "út", "st", "čt", "pá", "so"},
  63. daysNarrow: []string{"N", "P", "Ú", "S", "Č", "P", "S"},
  64. daysShort: []string{"ne", "po", "út", "st", "čt", "pá", "so"},
  65. daysWide: []string{"neděle", "pondělí", "úterý", "středa", "čtvrtek", "pátek", "sobota"},
  66. periodsAbbreviated: []string{"dop.", "odp."},
  67. periodsNarrow: []string{"dop.", "odp."},
  68. periodsWide: []string{"dop.", "odp."},
  69. erasAbbreviated: []string{"př. n. l.", "n. l."},
  70. erasNarrow: []string{"př.n.l.", "n.l."},
  71. erasWide: []string{"př. n. l.", "n. l."},
  72. timezones: map[string]string{"UYST": "Uruguayský letní čas", "PDT": "Severoamerický pacifický letní čas", "∅∅∅": "Brasilijský letní čas", "COT": "Kolumbijský standardní čas", "ACWDT": "Středozápadní australský letní čas", "GYT": "Guyanský čas", "EAT": "Východoafrický čas", "TMT": "Turkmenský standardní čas", "CST": "Severoamerický centrální standardní čas", "ChST": "Chamorrský čas", "BT": "Bhútánský čas", "VET": "Venezuelský čas", "AEST": "Východoaustralský standardní čas", "ARST": "Argentinský letní čas", "BOT": "Bolivijský čas", "MEZ": "Středoevropský standardní čas", "SGT": "Singapurský čas", "TMST": "Turkmenský letní čas", "CHADT": "Chathamský letní čas", "ECT": "Ekvádorský čas", "CDT": "Severoamerický centrální letní čas", "HNT": "Newfoundlandský standardní čas", "SRT": "Surinamský čas", "SAST": "Jihoafrický čas", "WITA": "Středoindonéský čas", "MDT": "Severoamerický horský letní čas", "GMT": "Greenwichský střední čas", "ACST": "Středoaustralský standardní čas", "COST": "Kolumbijský letní čas", "ART": "Argentinský standardní čas", "WARST": "Západoargentinský letní čas", "ACWST": "Středozápadní australský standardní čas", "JDT": "Japonský letní čas", "OEZ": "Východoevropský standardní čas", "OESZ": "Východoevropský letní čas", "MESZ": "Středoevropský letní čas", "HADT": "Havajsko-aleutský letní čas", "AKST": "Aljašský standardní čas", "MYT": "Malajský čas", "CLT": "Chilský standardní čas", "HAT": "Newfoundlandský letní čas", "WEZ": "Západoevropský standardní čas", "ACDT": "Středoaustralský letní čas", "HKT": "Hongkongský standardní čas", "HAST": "Havajsko-aleutský standardní čas", "PST": "Severoamerický pacifický standardní čas", "NZDT": "Novozélandský letní čas", "WIT": "Východoindonéský čas", "LHDT": "Letní čas ostrova lorda Howa", "UYT": "Uruguayský standardní čas", "WESZ": "Západoevropský letní čas", "CLST": "Chilský letní čas", "HKST": "Hongkongský letní čas", "WART": "Západoargentinský standardní čas", "AEDT": "Východoaustralský letní čas", "MST": "Severoamerický horský standardní čas", "AWST": "Západoaustralský standardní čas", "AWDT": "Západoaustralský letní čas", "CHAST": "Chathamský standardní čas", "ADT": "Atlantický letní čas", "WAT": "Západoafrický standardní čas", "LHST": "Standardní čas ostrova lorda Howa", "JST": "Japonský standardní čas", "GFT": "Francouzskoguyanský čas", "WIB": "Západoindonéský čas", "AST": "Atlantický standardní čas", "IST": "Indický čas", "CAT": "Středoafrický čas", "AKDT": "Aljašský letní čas", "WAST": "Západoafrický letní čas", "EST": "Severoamerický východní standardní čas", "EDT": "Severoamerický východní letní čas", "NZST": "Novozélandský standardní čas"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (cs *cs) Locale() string {
  77. return cs.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'cs'
  80. func (cs *cs) PluralsCardinal() []locales.PluralRule {
  81. return cs.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'cs'
  84. func (cs *cs) PluralsOrdinal() []locales.PluralRule {
  85. return cs.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'cs'
  88. func (cs *cs) PluralsRange() []locales.PluralRule {
  89. return cs.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'cs'
  92. func (cs *cs) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. i := int64(n)
  95. if i == 1 && v == 0 {
  96. return locales.PluralRuleOne
  97. } else if i >= 2 && i <= 4 && v == 0 {
  98. return locales.PluralRuleFew
  99. } else if v != 0 {
  100. return locales.PluralRuleMany
  101. }
  102. return locales.PluralRuleOther
  103. }
  104. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'cs'
  105. func (cs *cs) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  106. return locales.PluralRuleOther
  107. }
  108. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'cs'
  109. func (cs *cs) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  110. start := cs.CardinalPluralRule(num1, v1)
  111. end := cs.CardinalPluralRule(num2, v2)
  112. if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
  113. return locales.PluralRuleFew
  114. } else if start == locales.PluralRuleOne && end == locales.PluralRuleMany {
  115. return locales.PluralRuleMany
  116. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  117. return locales.PluralRuleOther
  118. } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew {
  119. return locales.PluralRuleFew
  120. } else if start == locales.PluralRuleFew && end == locales.PluralRuleMany {
  121. return locales.PluralRuleMany
  122. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
  123. return locales.PluralRuleOther
  124. } else if start == locales.PluralRuleMany && end == locales.PluralRuleOne {
  125. return locales.PluralRuleOne
  126. } else if start == locales.PluralRuleMany && end == locales.PluralRuleFew {
  127. return locales.PluralRuleFew
  128. } else if start == locales.PluralRuleMany && end == locales.PluralRuleMany {
  129. return locales.PluralRuleMany
  130. } else if start == locales.PluralRuleMany && end == locales.PluralRuleOther {
  131. return locales.PluralRuleOther
  132. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  133. return locales.PluralRuleOne
  134. } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew {
  135. return locales.PluralRuleFew
  136. } else if start == locales.PluralRuleOther && end == locales.PluralRuleMany {
  137. return locales.PluralRuleMany
  138. }
  139. return locales.PluralRuleOther
  140. }
  141. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  142. func (cs *cs) MonthAbbreviated(month time.Month) string {
  143. return cs.monthsAbbreviated[month]
  144. }
  145. // MonthsAbbreviated returns the locales abbreviated months
  146. func (cs *cs) MonthsAbbreviated() []string {
  147. return cs.monthsAbbreviated[1:]
  148. }
  149. // MonthNarrow returns the locales narrow month given the 'month' provided
  150. func (cs *cs) MonthNarrow(month time.Month) string {
  151. return cs.monthsNarrow[month]
  152. }
  153. // MonthsNarrow returns the locales narrow months
  154. func (cs *cs) MonthsNarrow() []string {
  155. return cs.monthsNarrow[1:]
  156. }
  157. // MonthWide returns the locales wide month given the 'month' provided
  158. func (cs *cs) MonthWide(month time.Month) string {
  159. return cs.monthsWide[month]
  160. }
  161. // MonthsWide returns the locales wide months
  162. func (cs *cs) MonthsWide() []string {
  163. return cs.monthsWide[1:]
  164. }
  165. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  166. func (cs *cs) WeekdayAbbreviated(weekday time.Weekday) string {
  167. return cs.daysAbbreviated[weekday]
  168. }
  169. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  170. func (cs *cs) WeekdaysAbbreviated() []string {
  171. return cs.daysAbbreviated
  172. }
  173. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  174. func (cs *cs) WeekdayNarrow(weekday time.Weekday) string {
  175. return cs.daysNarrow[weekday]
  176. }
  177. // WeekdaysNarrow returns the locales narrow weekdays
  178. func (cs *cs) WeekdaysNarrow() []string {
  179. return cs.daysNarrow
  180. }
  181. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  182. func (cs *cs) WeekdayShort(weekday time.Weekday) string {
  183. return cs.daysShort[weekday]
  184. }
  185. // WeekdaysShort returns the locales short weekdays
  186. func (cs *cs) WeekdaysShort() []string {
  187. return cs.daysShort
  188. }
  189. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  190. func (cs *cs) WeekdayWide(weekday time.Weekday) string {
  191. return cs.daysWide[weekday]
  192. }
  193. // WeekdaysWide returns the locales wide weekdays
  194. func (cs *cs) WeekdaysWide() []string {
  195. return cs.daysWide
  196. }
  197. // FmtNumber returns 'num' with digits/precision of 'v' for 'cs' and handles both Whole and Real numbers based on 'v'
  198. func (cs *cs) FmtNumber(num float64, v uint64) string {
  199. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  200. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  201. count := 0
  202. inWhole := v == 0
  203. b := make([]byte, 0, l)
  204. for i := len(s) - 1; i >= 0; i-- {
  205. if s[i] == '.' {
  206. b = append(b, cs.decimal[0])
  207. inWhole = true
  208. continue
  209. }
  210. if inWhole {
  211. if count == 3 {
  212. for j := len(cs.group) - 1; j >= 0; j-- {
  213. b = append(b, cs.group[j])
  214. }
  215. count = 1
  216. } else {
  217. count++
  218. }
  219. }
  220. b = append(b, s[i])
  221. }
  222. if num < 0 {
  223. b = append(b, cs.minus[0])
  224. }
  225. // reverse
  226. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  227. b[i], b[j] = b[j], b[i]
  228. }
  229. return string(b)
  230. }
  231. // FmtPercent returns 'num' with digits/precision of 'v' for 'cs' and handles both Whole and Real numbers based on 'v'
  232. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  233. func (cs *cs) FmtPercent(num float64, v uint64) string {
  234. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  235. l := len(s) + 5
  236. b := make([]byte, 0, l)
  237. for i := len(s) - 1; i >= 0; i-- {
  238. if s[i] == '.' {
  239. b = append(b, cs.decimal[0])
  240. continue
  241. }
  242. b = append(b, s[i])
  243. }
  244. if num < 0 {
  245. b = append(b, cs.minus[0])
  246. }
  247. // reverse
  248. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  249. b[i], b[j] = b[j], b[i]
  250. }
  251. b = append(b, cs.percentSuffix...)
  252. b = append(b, cs.percent...)
  253. return string(b)
  254. }
  255. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'cs'
  256. func (cs *cs) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  257. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  258. symbol := cs.currencies[currency]
  259. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  260. count := 0
  261. inWhole := v == 0
  262. b := make([]byte, 0, l)
  263. for i := len(s) - 1; i >= 0; i-- {
  264. if s[i] == '.' {
  265. b = append(b, cs.decimal[0])
  266. inWhole = true
  267. continue
  268. }
  269. if inWhole {
  270. if count == 3 {
  271. for j := len(cs.group) - 1; j >= 0; j-- {
  272. b = append(b, cs.group[j])
  273. }
  274. count = 1
  275. } else {
  276. count++
  277. }
  278. }
  279. b = append(b, s[i])
  280. }
  281. if num < 0 {
  282. b = append(b, cs.minus[0])
  283. }
  284. // reverse
  285. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  286. b[i], b[j] = b[j], b[i]
  287. }
  288. if int(v) < 2 {
  289. if v == 0 {
  290. b = append(b, cs.decimal...)
  291. }
  292. for i := 0; i < 2-int(v); i++ {
  293. b = append(b, '0')
  294. }
  295. }
  296. b = append(b, cs.currencyPositiveSuffix...)
  297. b = append(b, symbol...)
  298. return string(b)
  299. }
  300. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'cs'
  301. // in accounting notation.
  302. func (cs *cs) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  303. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  304. symbol := cs.currencies[currency]
  305. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  306. count := 0
  307. inWhole := v == 0
  308. b := make([]byte, 0, l)
  309. for i := len(s) - 1; i >= 0; i-- {
  310. if s[i] == '.' {
  311. b = append(b, cs.decimal[0])
  312. inWhole = true
  313. continue
  314. }
  315. if inWhole {
  316. if count == 3 {
  317. for j := len(cs.group) - 1; j >= 0; j-- {
  318. b = append(b, cs.group[j])
  319. }
  320. count = 1
  321. } else {
  322. count++
  323. }
  324. }
  325. b = append(b, s[i])
  326. }
  327. if num < 0 {
  328. b = append(b, cs.minus[0])
  329. }
  330. // reverse
  331. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  332. b[i], b[j] = b[j], b[i]
  333. }
  334. if int(v) < 2 {
  335. if v == 0 {
  336. b = append(b, cs.decimal...)
  337. }
  338. for i := 0; i < 2-int(v); i++ {
  339. b = append(b, '0')
  340. }
  341. }
  342. if num < 0 {
  343. b = append(b, cs.currencyNegativeSuffix...)
  344. b = append(b, symbol...)
  345. } else {
  346. b = append(b, cs.currencyPositiveSuffix...)
  347. b = append(b, symbol...)
  348. }
  349. return string(b)
  350. }
  351. // FmtDateShort returns the short date representation of 't' for 'cs'
  352. func (cs *cs) FmtDateShort(t time.Time) string {
  353. b := make([]byte, 0, 32)
  354. if t.Day() < 10 {
  355. b = append(b, '0')
  356. }
  357. b = strconv.AppendInt(b, int64(t.Day()), 10)
  358. b = append(b, []byte{0x2e}...)
  359. if t.Month() < 10 {
  360. b = append(b, '0')
  361. }
  362. b = strconv.AppendInt(b, int64(t.Month()), 10)
  363. b = append(b, []byte{0x2e}...)
  364. if t.Year() > 9 {
  365. b = append(b, strconv.Itoa(t.Year())[2:]...)
  366. } else {
  367. b = append(b, strconv.Itoa(t.Year())[1:]...)
  368. }
  369. return string(b)
  370. }
  371. // FmtDateMedium returns the medium date representation of 't' for 'cs'
  372. func (cs *cs) FmtDateMedium(t time.Time) string {
  373. b := make([]byte, 0, 32)
  374. b = strconv.AppendInt(b, int64(t.Day()), 10)
  375. b = append(b, []byte{0x2e, 0x20}...)
  376. b = strconv.AppendInt(b, int64(t.Month()), 10)
  377. b = append(b, []byte{0x2e, 0x20}...)
  378. b = strconv.AppendInt(b, int64(t.Year()), 10)
  379. return string(b)
  380. }
  381. // FmtDateLong returns the long date representation of 't' for 'cs'
  382. func (cs *cs) FmtDateLong(t time.Time) string {
  383. b := make([]byte, 0, 32)
  384. b = strconv.AppendInt(b, int64(t.Day()), 10)
  385. b = append(b, []byte{0x2e, 0x20}...)
  386. b = append(b, cs.monthsWide[t.Month()]...)
  387. b = append(b, []byte{0x20}...)
  388. b = strconv.AppendInt(b, int64(t.Year()), 10)
  389. return string(b)
  390. }
  391. // FmtDateFull returns the full date representation of 't' for 'cs'
  392. func (cs *cs) FmtDateFull(t time.Time) string {
  393. b := make([]byte, 0, 32)
  394. b = append(b, cs.daysWide[t.Weekday()]...)
  395. b = append(b, []byte{0x20}...)
  396. b = strconv.AppendInt(b, int64(t.Day()), 10)
  397. b = append(b, []byte{0x2e, 0x20}...)
  398. b = append(b, cs.monthsWide[t.Month()]...)
  399. b = append(b, []byte{0x20}...)
  400. b = strconv.AppendInt(b, int64(t.Year()), 10)
  401. return string(b)
  402. }
  403. // FmtTimeShort returns the short time representation of 't' for 'cs'
  404. func (cs *cs) FmtTimeShort(t time.Time) string {
  405. b := make([]byte, 0, 32)
  406. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  407. b = append(b, cs.timeSeparator...)
  408. if t.Minute() < 10 {
  409. b = append(b, '0')
  410. }
  411. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  412. return string(b)
  413. }
  414. // FmtTimeMedium returns the medium time representation of 't' for 'cs'
  415. func (cs *cs) FmtTimeMedium(t time.Time) string {
  416. b := make([]byte, 0, 32)
  417. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  418. b = append(b, cs.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, cs.timeSeparator...)
  424. if t.Second() < 10 {
  425. b = append(b, '0')
  426. }
  427. b = strconv.AppendInt(b, int64(t.Second()), 10)
  428. return string(b)
  429. }
  430. // FmtTimeLong returns the long time representation of 't' for 'cs'
  431. func (cs *cs) FmtTimeLong(t time.Time) string {
  432. b := make([]byte, 0, 32)
  433. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  434. b = append(b, cs.timeSeparator...)
  435. if t.Minute() < 10 {
  436. b = append(b, '0')
  437. }
  438. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  439. b = append(b, cs.timeSeparator...)
  440. if t.Second() < 10 {
  441. b = append(b, '0')
  442. }
  443. b = strconv.AppendInt(b, int64(t.Second()), 10)
  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 'cs'
  450. func (cs *cs) FmtTimeFull(t time.Time) string {
  451. b := make([]byte, 0, 32)
  452. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  453. b = append(b, cs.timeSeparator...)
  454. if t.Minute() < 10 {
  455. b = append(b, '0')
  456. }
  457. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  458. b = append(b, cs.timeSeparator...)
  459. if t.Second() < 10 {
  460. b = append(b, '0')
  461. }
  462. b = strconv.AppendInt(b, int64(t.Second()), 10)
  463. b = append(b, []byte{0x20}...)
  464. tz, _ := t.Zone()
  465. if btz, ok := cs.timezones[tz]; ok {
  466. b = append(b, btz...)
  467. } else {
  468. b = append(b, tz...)
  469. }
  470. return string(b)
  471. }