cs.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "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", "STN", "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řed naším letopočtem", "našeho letopočtu"},
  72. timezones: map[string]string{"HEPM": "Pierre-miquelonský letní čas", "CLST": "Chilský letní čas", "WAST": "Západoafrický letní čas", "LHDT": "Letní čas ostrova lorda Howa", "COT": "Kolumbijský standardní čas", "MESZ": "Středoevropský letní čas", "SRT": "Surinamský čas", "GFT": "Francouzskoguyanský čas", "HENOMX": "Severozápadní mexický letní čas", "CDT": "Severoamerický centrální letní čas", "WEZ": "Západoevropský standardní čas", "WITA": "Středoindonéský čas", "HNT": "Newfoundlandský standardní čas", "COST": "Kolumbijský letní čas", "OESZ": "Východoevropský letní čas", "HNCU": "Kubánský standardní čas", "MST": "Severoamerický horský standardní čas", "BT": "Bhútánský čas", "HKST": "Hongkongský letní čas", "UYST": "Uruguayský letní čas", "GMT": "Greenwichský střední čas", "SAST": "Jihoafrický čas", "NZDT": "Novozélandský letní čas", "SGT": "Singapurský čas", "ACDT": "Středoaustralský letní čas", "HNNOMX": "Severozápadní mexický standardní čas", "HADT": "Havajsko-aleutský letní čas", "ART": "Argentinský standardní čas", "ADT": "Atlantický letní čas", "BOT": "Bolivijský čas", "MDT": "Severoamerický horský letní čas", "AWDT": "Západoaustralský letní čas", "AEST": "Východoaustralský standardní čas", "NZST": "Novozélandský standardní čas", "HNOG": "Západogrónský standardní čas", "VET": "Venezuelský čas", "WIT": "Východoindonéský čas", "HAST": "Havajsko-aleutský standardní čas", "PST": "Severoamerický pacifický standardní čas", "AST": "Atlantický standardní čas", "ECT": "Ekvádorský čas", "AKST": "Aljašský standardní čas", "ACST": "Středoaustralský standardní čas", "LHST": "Standardní čas ostrova lorda Howa", "CLT": "Chilský standardní čas", "TMST": "Turkmenský letní čas", "HEPMX": "Mexický pacifický letní čas", "JST": "Japonský standardní čas", "CAT": "Středoafrický čas", "UYT": "Uruguayský standardní čas", "TMT": "Turkmenský standardní čas", "HNEG": "Východogrónský standardní čas", "HEEG": "Východogrónský letní čas", "MYT": "Malajský čas", "HKT": "Hongkongský standardní čas", "ARST": "Argentinský letní čas", "ChST": "Chamorrský čas", "PDT": "Severoamerický pacifický letní čas", "WIB": "Západoindonéský čas", "OEZ": "Východoevropský standardní čas", "CHAST": "Chathamský standardní čas", "HEOG": "Západogrónský letní čas", "WART": "Západoargentinský standardní čas", "GYT": "Guyanský čas", "HECU": "Kubánský letní čas", "CHADT": "Chathamský letní čas", "AEDT": "Východoaustralský letní čas", "WESZ": "Západoevropský letní čas", "MEZ": "Středoevropský standardní čas", "IST": "Indický čas", "HAT": "Newfoundlandský letní čas", "CST": "Severoamerický centrální standardní čas", "JDT": "Japonský letní čas", "AKDT": "Aljašský letní čas", "ACWST": "Středozápadní australský standardní čas", "EDT": "Severoamerický východní letní čas", "AWST": "Západoaustralský standardní čas", "∅∅∅": "Acrejský letní čas", "ACWDT": "Středozápadní australský letní čas", "EST": "Severoamerický východní standardní čas", "WARST": "Západoargentinský letní čas", "HNPM": "Pierre-miquelonský standardní čas", "EAT": "Východoafrický čas", "HNPMX": "Mexický pacifický standardní čas", "WAT": "Západoafrický 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. // Decimal returns the decimal point of number
  198. func (cs *cs) Decimal() string {
  199. return cs.decimal
  200. }
  201. // Group returns the group of number
  202. func (cs *cs) Group() string {
  203. return cs.group
  204. }
  205. // Group returns the minus sign of number
  206. func (cs *cs) Minus() string {
  207. return cs.minus
  208. }
  209. // FmtNumber returns 'num' with digits/precision of 'v' for 'cs' and handles both Whole and Real numbers based on 'v'
  210. func (cs *cs) FmtNumber(num float64, v uint64) string {
  211. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  212. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  213. count := 0
  214. inWhole := v == 0
  215. b := make([]byte, 0, l)
  216. for i := len(s) - 1; i >= 0; i-- {
  217. if s[i] == '.' {
  218. b = append(b, cs.decimal[0])
  219. inWhole = true
  220. continue
  221. }
  222. if inWhole {
  223. if count == 3 {
  224. for j := len(cs.group) - 1; j >= 0; j-- {
  225. b = append(b, cs.group[j])
  226. }
  227. count = 1
  228. } else {
  229. count++
  230. }
  231. }
  232. b = append(b, s[i])
  233. }
  234. if num < 0 {
  235. b = append(b, cs.minus[0])
  236. }
  237. // reverse
  238. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  239. b[i], b[j] = b[j], b[i]
  240. }
  241. return string(b)
  242. }
  243. // FmtPercent returns 'num' with digits/precision of 'v' for 'cs' and handles both Whole and Real numbers based on 'v'
  244. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  245. func (cs *cs) FmtPercent(num float64, v uint64) string {
  246. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  247. l := len(s) + 5
  248. b := make([]byte, 0, l)
  249. for i := len(s) - 1; i >= 0; i-- {
  250. if s[i] == '.' {
  251. b = append(b, cs.decimal[0])
  252. continue
  253. }
  254. b = append(b, s[i])
  255. }
  256. if num < 0 {
  257. b = append(b, cs.minus[0])
  258. }
  259. // reverse
  260. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  261. b[i], b[j] = b[j], b[i]
  262. }
  263. b = append(b, cs.percentSuffix...)
  264. b = append(b, cs.percent...)
  265. return string(b)
  266. }
  267. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'cs'
  268. func (cs *cs) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  269. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  270. symbol := cs.currencies[currency]
  271. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  272. count := 0
  273. inWhole := v == 0
  274. b := make([]byte, 0, l)
  275. for i := len(s) - 1; i >= 0; i-- {
  276. if s[i] == '.' {
  277. b = append(b, cs.decimal[0])
  278. inWhole = true
  279. continue
  280. }
  281. if inWhole {
  282. if count == 3 {
  283. for j := len(cs.group) - 1; j >= 0; j-- {
  284. b = append(b, cs.group[j])
  285. }
  286. count = 1
  287. } else {
  288. count++
  289. }
  290. }
  291. b = append(b, s[i])
  292. }
  293. if num < 0 {
  294. b = append(b, cs.minus[0])
  295. }
  296. // reverse
  297. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  298. b[i], b[j] = b[j], b[i]
  299. }
  300. if int(v) < 2 {
  301. if v == 0 {
  302. b = append(b, cs.decimal...)
  303. }
  304. for i := 0; i < 2-int(v); i++ {
  305. b = append(b, '0')
  306. }
  307. }
  308. b = append(b, cs.currencyPositiveSuffix...)
  309. b = append(b, symbol...)
  310. return string(b)
  311. }
  312. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'cs'
  313. // in accounting notation.
  314. func (cs *cs) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  315. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  316. symbol := cs.currencies[currency]
  317. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  318. count := 0
  319. inWhole := v == 0
  320. b := make([]byte, 0, l)
  321. for i := len(s) - 1; i >= 0; i-- {
  322. if s[i] == '.' {
  323. b = append(b, cs.decimal[0])
  324. inWhole = true
  325. continue
  326. }
  327. if inWhole {
  328. if count == 3 {
  329. for j := len(cs.group) - 1; j >= 0; j-- {
  330. b = append(b, cs.group[j])
  331. }
  332. count = 1
  333. } else {
  334. count++
  335. }
  336. }
  337. b = append(b, s[i])
  338. }
  339. if num < 0 {
  340. b = append(b, cs.minus[0])
  341. }
  342. // reverse
  343. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  344. b[i], b[j] = b[j], b[i]
  345. }
  346. if int(v) < 2 {
  347. if v == 0 {
  348. b = append(b, cs.decimal...)
  349. }
  350. for i := 0; i < 2-int(v); i++ {
  351. b = append(b, '0')
  352. }
  353. }
  354. if num < 0 {
  355. b = append(b, cs.currencyNegativeSuffix...)
  356. b = append(b, symbol...)
  357. } else {
  358. b = append(b, cs.currencyPositiveSuffix...)
  359. b = append(b, symbol...)
  360. }
  361. return string(b)
  362. }
  363. // FmtDateShort returns the short date representation of 't' for 'cs'
  364. func (cs *cs) FmtDateShort(t time.Time) string {
  365. b := make([]byte, 0, 32)
  366. if t.Day() < 10 {
  367. b = append(b, '0')
  368. }
  369. b = strconv.AppendInt(b, int64(t.Day()), 10)
  370. b = append(b, []byte{0x2e}...)
  371. if t.Month() < 10 {
  372. b = append(b, '0')
  373. }
  374. b = strconv.AppendInt(b, int64(t.Month()), 10)
  375. b = append(b, []byte{0x2e}...)
  376. if t.Year() > 9 {
  377. b = append(b, strconv.Itoa(t.Year())[2:]...)
  378. } else {
  379. b = append(b, strconv.Itoa(t.Year())[1:]...)
  380. }
  381. return string(b)
  382. }
  383. // FmtDateMedium returns the medium date representation of 't' for 'cs'
  384. func (cs *cs) FmtDateMedium(t time.Time) string {
  385. b := make([]byte, 0, 32)
  386. b = strconv.AppendInt(b, int64(t.Day()), 10)
  387. b = append(b, []byte{0x2e, 0x20}...)
  388. b = strconv.AppendInt(b, int64(t.Month()), 10)
  389. b = append(b, []byte{0x2e, 0x20}...)
  390. if t.Year() > 0 {
  391. b = strconv.AppendInt(b, int64(t.Year()), 10)
  392. } else {
  393. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  394. }
  395. return string(b)
  396. }
  397. // FmtDateLong returns the long date representation of 't' for 'cs'
  398. func (cs *cs) FmtDateLong(t time.Time) string {
  399. b := make([]byte, 0, 32)
  400. b = strconv.AppendInt(b, int64(t.Day()), 10)
  401. b = append(b, []byte{0x2e, 0x20}...)
  402. b = append(b, cs.monthsWide[t.Month()]...)
  403. b = append(b, []byte{0x20}...)
  404. if t.Year() > 0 {
  405. b = strconv.AppendInt(b, int64(t.Year()), 10)
  406. } else {
  407. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  408. }
  409. return string(b)
  410. }
  411. // FmtDateFull returns the full date representation of 't' for 'cs'
  412. func (cs *cs) FmtDateFull(t time.Time) string {
  413. b := make([]byte, 0, 32)
  414. b = append(b, cs.daysWide[t.Weekday()]...)
  415. b = append(b, []byte{0x20}...)
  416. b = strconv.AppendInt(b, int64(t.Day()), 10)
  417. b = append(b, []byte{0x2e, 0x20}...)
  418. b = append(b, cs.monthsWide[t.Month()]...)
  419. b = append(b, []byte{0x20}...)
  420. if t.Year() > 0 {
  421. b = strconv.AppendInt(b, int64(t.Year()), 10)
  422. } else {
  423. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  424. }
  425. return string(b)
  426. }
  427. // FmtTimeShort returns the short time representation of 't' for 'cs'
  428. func (cs *cs) FmtTimeShort(t time.Time) string {
  429. b := make([]byte, 0, 32)
  430. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  431. b = append(b, cs.timeSeparator...)
  432. if t.Minute() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  436. return string(b)
  437. }
  438. // FmtTimeMedium returns the medium time representation of 't' for 'cs'
  439. func (cs *cs) FmtTimeMedium(t time.Time) string {
  440. b := make([]byte, 0, 32)
  441. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  442. b = append(b, cs.timeSeparator...)
  443. if t.Minute() < 10 {
  444. b = append(b, '0')
  445. }
  446. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  447. b = append(b, cs.timeSeparator...)
  448. if t.Second() < 10 {
  449. b = append(b, '0')
  450. }
  451. b = strconv.AppendInt(b, int64(t.Second()), 10)
  452. return string(b)
  453. }
  454. // FmtTimeLong returns the long time representation of 't' for 'cs'
  455. func (cs *cs) FmtTimeLong(t time.Time) string {
  456. b := make([]byte, 0, 32)
  457. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  458. b = append(b, cs.timeSeparator...)
  459. if t.Minute() < 10 {
  460. b = append(b, '0')
  461. }
  462. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  463. b = append(b, cs.timeSeparator...)
  464. if t.Second() < 10 {
  465. b = append(b, '0')
  466. }
  467. b = strconv.AppendInt(b, int64(t.Second()), 10)
  468. b = append(b, []byte{0x20}...)
  469. tz, _ := t.Zone()
  470. b = append(b, tz...)
  471. return string(b)
  472. }
  473. // FmtTimeFull returns the full time representation of 't' for 'cs'
  474. func (cs *cs) FmtTimeFull(t time.Time) string {
  475. b := make([]byte, 0, 32)
  476. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  477. b = append(b, cs.timeSeparator...)
  478. if t.Minute() < 10 {
  479. b = append(b, '0')
  480. }
  481. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  482. b = append(b, cs.timeSeparator...)
  483. if t.Second() < 10 {
  484. b = append(b, '0')
  485. }
  486. b = strconv.AppendInt(b, int64(t.Second()), 10)
  487. b = append(b, []byte{0x20}...)
  488. tz, _ := t.Zone()
  489. if btz, ok := cs.timezones[tz]; ok {
  490. b = append(b, btz...)
  491. } else {
  492. b = append(b, tz...)
  493. }
  494. return string(b)
  495. }