bs.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. package bs
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type bs 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 'bs' locale
  42. func New() locales.Translator {
  43. return &bs{
  44. locale: "bs",
  45. pluralsCardinal: []locales.PluralRule{2, 4, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: []locales.PluralRule{2, 4, 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", "AUD", "AWG", "AZM", "AZN", "BAD", "KM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CNY", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "kn", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "¥", "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", "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", "din.", "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", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "XPF", "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{"", "jan", "feb", "mar", "apr", "maj", "jun", "jul", "avg", "sep", "okt", "nov", "dec"},
  60. monthsNarrow: []string{"", "j", "f", "m", "a", "m", "j", "j", "a", "s", "o", "n", "d"},
  61. monthsWide: []string{"", "januar", "februar", "mart", "april", "maj", "juni", "juli", "avgust", "septembar", "oktobar", "novembar", "decembar"},
  62. daysAbbreviated: []string{"ned", "pon", "uto", "sri", "čet", "pet", "sub"},
  63. daysNarrow: []string{"N", "P", "U", "S", "Č", "P", "S"},
  64. daysShort: []string{"ned", "pon", "uto", "sri", "čet", "pet", "sub"},
  65. daysWide: []string{"nedjelja", "ponedjeljak", "utorak", "srijeda", "četvrtak", "petak", "subota"},
  66. periodsAbbreviated: []string{"prijepodne", "popodne"},
  67. periodsNarrow: []string{"prijepodne", "popodne"},
  68. periodsWide: []string{"prijepodne", "popodne"},
  69. erasAbbreviated: []string{"p. n. e.", "n. e."},
  70. erasNarrow: []string{"pr.n.e.", "AD"},
  71. erasWide: []string{"", ""},
  72. timezones: map[string]string{"NZST": "Novozelandsko standardno vrijeme", "HKT": "Hongkonško standardno vrijeme", "HAST": "Havajsko-aleućansko standardno vrijeme", "HKST": "Hongkonško ljetno vrijeme", "HNNOMX": "Sjeverozapadno meksičko standardno vrijeme", "GMT": "Griničko vrijeme", "AWST": "Zapadnoaustralijsko standardno vrijeme", "AEST": "Istočnoaustralijsko standardno vrijeme", "BT": "Butansko vrijeme", "MYT": "Malezijsko vrijeme", "HNOG": "Zapadnogrenlandsko standardno vrijeme", "AST": "Sjevernoameričko atlantsko standardno vrijeme", "WESZ": "Zapadnoevropsko ljetno vrijeme", "MEZ": "Centralnoevropsko standardno vrijeme", "OESZ": "Istočnoevropsko ljetno vrijeme", "TMT": "Turkmenistansko standardno vrijeme", "CHADT": "Čatamsko ljetno vrijeme", "HNCU": "Kubansko standardno vrijeme", "HECU": "Kubansko ljetno vrijeme", "LHST": "Standardno vrijeme na Ostrvu Lord Hau", "EAT": "Istočnoafričko vrijeme", "WITA": "Centralnoindonezijsko vrijeme", "MST": "Sjevernoameričko planinsko standardno vrijeme", "MDT": "Sjevernoameričko planinsko ljetno vrijeme", "WIB": "Zapadnoindonezijsko vrijeme", "AKDT": "Aljaskansko ljetno vrijeme", "WARST": "Zapadnoargentinsko ljetno vrijeme", "COST": "Kolumbijsko ljetno vrijeme", "GYT": "Gvajansko vrijeme", "WAST": "Zapadnoafričko ljetno vrijeme", "NZDT": "Novozelandsko ljetno vrijeme", "WIT": "Istočnoindonezijsko vrijeme", "ART": "Argentinsko standardno vrijeme", "COT": "Kolumbijsko standardno vrijeme", "SAST": "Južnoafričko standardno vrijeme", "ACWST": "Australijsko centralnozapadno standardno vrijeme", "ACWDT": "Australijsko centralnozapadno ljetno vrijeme", "HEEG": "Istočnogrenlandsko ljetno vrijeme", "HNT": "Njufaundlendsko standardno vrijeme", "CHAST": "Čatamsko standardno vrijeme", "CDT": "Sjevernoameričko centralno ljetno vrijeme", "HNEG": "Istočnogrenlandsko standardno vrijeme", "MESZ": "Centralnoevropsko ljetno vrijeme", "CLST": "Čileansko ljetno vrijeme", "AWDT": "Zapadnoaustralijsko ljetno vrijeme", "WAT": "Zapadnoafričko standardno vrijeme", "HAT": "Njufaundlendsko ljetno vrijeme", "VET": "Venecuelansko vrijeme", "HENOMX": "Sjeverozapadno meksičko ljetno vrijeme", "HADT": "Havajsko-aleućansko ljetno vrijeme", "HEPMX": "Meksičko pacifičko ljetno vrijeme", "AEDT": "Istočnoaustralijsko ljetno vrijeme", "AKST": "Aljaskansko standardno vrijeme", "EST": "Sjevernoameričko istočno standardno vrijeme", "ACDT": "Centralnoaustralijsko ljetno vrijeme", "ARST": "Argentinsko ljetno vrijeme", "UYT": "Urugvajsko standardno vrijeme", "ChST": "Čamorsko standardno vrijeme", "CST": "Sjevernoameričko centralno standardno vrijeme", "PST": "Sjevernoameričko pacifičko standardno vrijeme", "EDT": "Sjevernoameričko istočno ljetno vrijeme", "CLT": "Čileansko standardno vrijeme", "JST": "Japansko standardno vrijeme", "IST": "Indijsko standardno vrijeme", "CAT": "Centralnoafričko vrijeme", "UYST": "Urugvajsko ljetno vrijeme", "OEZ": "Istočnoevropsko standardno vrijeme", "PDT": "Sjevernoameričko pacifičko ljetno vrijeme", "JDT": "Japansko ljetno vrijeme", "WART": "Zapadnoargentinsko standardno vrijeme", "HEPM": "Ljetno vrijeme na Ostrvima Sveti Petar i Mikelon", "SRT": "Surinamsko vrijeme", "∅∅∅": "Brazilijsko ljetno vrijeme", "ADT": "Sjevernoameričko atlantsko ljetno vrijeme", "ECT": "Ekvadorsko vrijeme", "WEZ": "Zapadnoevropsko standardno vrijeme", "BOT": "Bolivijsko vrijeme", "SGT": "Singapursko standardno vrijeme", "HEOG": "Zapadnogrenlandsko ljetno vrijeme", "TMST": "Turkmenistansko ljetno vrijeme", "HNPMX": "Meksičko pacifičko standardno vrijeme", "GFT": "Francuskogvajansko vrijeme", "ACST": "Centralnoaustralijsko standardno vrijeme", "LHDT": "Ljetno vrijeme na Ostrvu Lord Hau", "HNPM": "Standardno vrijeme na Ostrvima Sveti Petar i Mikelon"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (bs *bs) Locale() string {
  77. return bs.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'bs'
  80. func (bs *bs) PluralsCardinal() []locales.PluralRule {
  81. return bs.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'bs'
  84. func (bs *bs) PluralsOrdinal() []locales.PluralRule {
  85. return bs.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'bs'
  88. func (bs *bs) PluralsRange() []locales.PluralRule {
  89. return bs.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'bs'
  92. func (bs *bs) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. i := int64(n)
  95. f := locales.F(n, v)
  96. iMod10 := i % 10
  97. iMod100 := i % 100
  98. fMod10 := f % 10
  99. fMod100 := f % 100
  100. if (v == 0 && iMod10 == 1 && iMod100 != 11) || (fMod10 == 1 && fMod100 != 11) {
  101. return locales.PluralRuleOne
  102. } else if (v == 0 && iMod10 >= 2 && iMod10 <= 4 && (iMod100 < 12 || iMod100 > 14)) || (fMod10 >= 2 && fMod10 <= 4 && (fMod100 < 12 || fMod100 > 14)) {
  103. return locales.PluralRuleFew
  104. }
  105. return locales.PluralRuleOther
  106. }
  107. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'bs'
  108. func (bs *bs) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  109. return locales.PluralRuleOther
  110. }
  111. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'bs'
  112. func (bs *bs) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  113. start := bs.CardinalPluralRule(num1, v1)
  114. end := bs.CardinalPluralRule(num2, v2)
  115. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  116. return locales.PluralRuleOne
  117. } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
  118. return locales.PluralRuleFew
  119. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  120. return locales.PluralRuleOther
  121. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOne {
  122. return locales.PluralRuleOne
  123. } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew {
  124. return locales.PluralRuleFew
  125. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
  126. return locales.PluralRuleOther
  127. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  128. return locales.PluralRuleOne
  129. } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew {
  130. return locales.PluralRuleFew
  131. }
  132. return locales.PluralRuleOther
  133. }
  134. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  135. func (bs *bs) MonthAbbreviated(month time.Month) string {
  136. return bs.monthsAbbreviated[month]
  137. }
  138. // MonthsAbbreviated returns the locales abbreviated months
  139. func (bs *bs) MonthsAbbreviated() []string {
  140. return bs.monthsAbbreviated[1:]
  141. }
  142. // MonthNarrow returns the locales narrow month given the 'month' provided
  143. func (bs *bs) MonthNarrow(month time.Month) string {
  144. return bs.monthsNarrow[month]
  145. }
  146. // MonthsNarrow returns the locales narrow months
  147. func (bs *bs) MonthsNarrow() []string {
  148. return bs.monthsNarrow[1:]
  149. }
  150. // MonthWide returns the locales wide month given the 'month' provided
  151. func (bs *bs) MonthWide(month time.Month) string {
  152. return bs.monthsWide[month]
  153. }
  154. // MonthsWide returns the locales wide months
  155. func (bs *bs) MonthsWide() []string {
  156. return bs.monthsWide[1:]
  157. }
  158. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  159. func (bs *bs) WeekdayAbbreviated(weekday time.Weekday) string {
  160. return bs.daysAbbreviated[weekday]
  161. }
  162. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  163. func (bs *bs) WeekdaysAbbreviated() []string {
  164. return bs.daysAbbreviated
  165. }
  166. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  167. func (bs *bs) WeekdayNarrow(weekday time.Weekday) string {
  168. return bs.daysNarrow[weekday]
  169. }
  170. // WeekdaysNarrow returns the locales narrow weekdays
  171. func (bs *bs) WeekdaysNarrow() []string {
  172. return bs.daysNarrow
  173. }
  174. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  175. func (bs *bs) WeekdayShort(weekday time.Weekday) string {
  176. return bs.daysShort[weekday]
  177. }
  178. // WeekdaysShort returns the locales short weekdays
  179. func (bs *bs) WeekdaysShort() []string {
  180. return bs.daysShort
  181. }
  182. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  183. func (bs *bs) WeekdayWide(weekday time.Weekday) string {
  184. return bs.daysWide[weekday]
  185. }
  186. // WeekdaysWide returns the locales wide weekdays
  187. func (bs *bs) WeekdaysWide() []string {
  188. return bs.daysWide
  189. }
  190. // Decimal returns the decimal point of number
  191. func (bs *bs) Decimal() string {
  192. return bs.decimal
  193. }
  194. // Group returns the group of number
  195. func (bs *bs) Group() string {
  196. return bs.group
  197. }
  198. // Group returns the minus sign of number
  199. func (bs *bs) Minus() string {
  200. return bs.minus
  201. }
  202. // FmtNumber returns 'num' with digits/precision of 'v' for 'bs' and handles both Whole and Real numbers based on 'v'
  203. func (bs *bs) FmtNumber(num float64, v uint64) string {
  204. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  205. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  206. count := 0
  207. inWhole := v == 0
  208. b := make([]byte, 0, l)
  209. for i := len(s) - 1; i >= 0; i-- {
  210. if s[i] == '.' {
  211. b = append(b, bs.decimal[0])
  212. inWhole = true
  213. continue
  214. }
  215. if inWhole {
  216. if count == 3 {
  217. b = append(b, bs.group[0])
  218. count = 1
  219. } else {
  220. count++
  221. }
  222. }
  223. b = append(b, s[i])
  224. }
  225. if num < 0 {
  226. b = append(b, bs.minus[0])
  227. }
  228. // reverse
  229. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  230. b[i], b[j] = b[j], b[i]
  231. }
  232. return string(b)
  233. }
  234. // FmtPercent returns 'num' with digits/precision of 'v' for 'bs' and handles both Whole and Real numbers based on 'v'
  235. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  236. func (bs *bs) FmtPercent(num float64, v uint64) string {
  237. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  238. l := len(s) + 5
  239. b := make([]byte, 0, l)
  240. for i := len(s) - 1; i >= 0; i-- {
  241. if s[i] == '.' {
  242. b = append(b, bs.decimal[0])
  243. continue
  244. }
  245. b = append(b, s[i])
  246. }
  247. if num < 0 {
  248. b = append(b, bs.minus[0])
  249. }
  250. // reverse
  251. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  252. b[i], b[j] = b[j], b[i]
  253. }
  254. b = append(b, bs.percentSuffix...)
  255. b = append(b, bs.percent...)
  256. return string(b)
  257. }
  258. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'bs'
  259. func (bs *bs) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  260. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  261. symbol := bs.currencies[currency]
  262. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  263. count := 0
  264. inWhole := v == 0
  265. b := make([]byte, 0, l)
  266. for i := len(s) - 1; i >= 0; i-- {
  267. if s[i] == '.' {
  268. b = append(b, bs.decimal[0])
  269. inWhole = true
  270. continue
  271. }
  272. if inWhole {
  273. if count == 3 {
  274. b = append(b, bs.group[0])
  275. count = 1
  276. } else {
  277. count++
  278. }
  279. }
  280. b = append(b, s[i])
  281. }
  282. if num < 0 {
  283. b = append(b, bs.minus[0])
  284. }
  285. // reverse
  286. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  287. b[i], b[j] = b[j], b[i]
  288. }
  289. if int(v) < 2 {
  290. if v == 0 {
  291. b = append(b, bs.decimal...)
  292. }
  293. for i := 0; i < 2-int(v); i++ {
  294. b = append(b, '0')
  295. }
  296. }
  297. b = append(b, bs.currencyPositiveSuffix...)
  298. b = append(b, symbol...)
  299. return string(b)
  300. }
  301. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'bs'
  302. // in accounting notation.
  303. func (bs *bs) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  304. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  305. symbol := bs.currencies[currency]
  306. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  307. count := 0
  308. inWhole := v == 0
  309. b := make([]byte, 0, l)
  310. for i := len(s) - 1; i >= 0; i-- {
  311. if s[i] == '.' {
  312. b = append(b, bs.decimal[0])
  313. inWhole = true
  314. continue
  315. }
  316. if inWhole {
  317. if count == 3 {
  318. b = append(b, bs.group[0])
  319. count = 1
  320. } else {
  321. count++
  322. }
  323. }
  324. b = append(b, s[i])
  325. }
  326. if num < 0 {
  327. b = append(b, bs.minus[0])
  328. }
  329. // reverse
  330. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  331. b[i], b[j] = b[j], b[i]
  332. }
  333. if int(v) < 2 {
  334. if v == 0 {
  335. b = append(b, bs.decimal...)
  336. }
  337. for i := 0; i < 2-int(v); i++ {
  338. b = append(b, '0')
  339. }
  340. }
  341. if num < 0 {
  342. b = append(b, bs.currencyNegativeSuffix...)
  343. b = append(b, symbol...)
  344. } else {
  345. b = append(b, bs.currencyPositiveSuffix...)
  346. b = append(b, symbol...)
  347. }
  348. return string(b)
  349. }
  350. // FmtDateShort returns the short date representation of 't' for 'bs'
  351. func (bs *bs) FmtDateShort(t time.Time) string {
  352. b := make([]byte, 0, 32)
  353. b = strconv.AppendInt(b, int64(t.Day()), 10)
  354. b = append(b, []byte{0x2e}...)
  355. b = strconv.AppendInt(b, int64(t.Month()), 10)
  356. b = append(b, []byte{0x2e}...)
  357. if t.Year() > 9 {
  358. b = append(b, strconv.Itoa(t.Year())[2:]...)
  359. } else {
  360. b = append(b, strconv.Itoa(t.Year())[1:]...)
  361. }
  362. b = append(b, []byte{0x2e}...)
  363. return string(b)
  364. }
  365. // FmtDateMedium returns the medium date representation of 't' for 'bs'
  366. func (bs *bs) FmtDateMedium(t time.Time) string {
  367. b := make([]byte, 0, 32)
  368. b = strconv.AppendInt(b, int64(t.Day()), 10)
  369. b = append(b, []byte{0x2e, 0x20}...)
  370. b = append(b, bs.monthsAbbreviated[t.Month()]...)
  371. b = append(b, []byte{0x20}...)
  372. if t.Year() > 0 {
  373. b = strconv.AppendInt(b, int64(t.Year()), 10)
  374. } else {
  375. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  376. }
  377. b = append(b, []byte{0x2e}...)
  378. return string(b)
  379. }
  380. // FmtDateLong returns the long date representation of 't' for 'bs'
  381. func (bs *bs) FmtDateLong(t time.Time) string {
  382. b := make([]byte, 0, 32)
  383. b = strconv.AppendInt(b, int64(t.Day()), 10)
  384. b = append(b, []byte{0x2e, 0x20}...)
  385. b = append(b, bs.monthsWide[t.Month()]...)
  386. b = append(b, []byte{0x20}...)
  387. if t.Year() > 0 {
  388. b = strconv.AppendInt(b, int64(t.Year()), 10)
  389. } else {
  390. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  391. }
  392. b = append(b, []byte{0x2e}...)
  393. return string(b)
  394. }
  395. // FmtDateFull returns the full date representation of 't' for 'bs'
  396. func (bs *bs) FmtDateFull(t time.Time) string {
  397. b := make([]byte, 0, 32)
  398. b = append(b, bs.daysWide[t.Weekday()]...)
  399. b = append(b, []byte{0x2c, 0x20}...)
  400. b = strconv.AppendInt(b, int64(t.Day()), 10)
  401. b = append(b, []byte{0x2e, 0x20}...)
  402. b = append(b, bs.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. b = append(b, []byte{0x2e}...)
  410. return string(b)
  411. }
  412. // FmtTimeShort returns the short time representation of 't' for 'bs'
  413. func (bs *bs) FmtTimeShort(t time.Time) string {
  414. b := make([]byte, 0, 32)
  415. if t.Hour() < 10 {
  416. b = append(b, '0')
  417. }
  418. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  419. b = append(b, bs.timeSeparator...)
  420. if t.Minute() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  424. return string(b)
  425. }
  426. // FmtTimeMedium returns the medium time representation of 't' for 'bs'
  427. func (bs *bs) FmtTimeMedium(t time.Time) string {
  428. b := make([]byte, 0, 32)
  429. if t.Hour() < 10 {
  430. b = append(b, '0')
  431. }
  432. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  433. b = append(b, bs.timeSeparator...)
  434. if t.Minute() < 10 {
  435. b = append(b, '0')
  436. }
  437. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  438. b = append(b, bs.timeSeparator...)
  439. if t.Second() < 10 {
  440. b = append(b, '0')
  441. }
  442. b = strconv.AppendInt(b, int64(t.Second()), 10)
  443. return string(b)
  444. }
  445. // FmtTimeLong returns the long time representation of 't' for 'bs'
  446. func (bs *bs) FmtTimeLong(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, bs.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, bs.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. b = append(b, tz...)
  465. return string(b)
  466. }
  467. // FmtTimeFull returns the full time representation of 't' for 'bs'
  468. func (bs *bs) FmtTimeFull(t time.Time) string {
  469. b := make([]byte, 0, 32)
  470. if t.Hour() < 10 {
  471. b = append(b, '0')
  472. }
  473. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  474. b = append(b, bs.timeSeparator...)
  475. if t.Minute() < 10 {
  476. b = append(b, '0')
  477. }
  478. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  479. b = append(b, bs.timeSeparator...)
  480. if t.Second() < 10 {
  481. b = append(b, '0')
  482. }
  483. b = strconv.AppendInt(b, int64(t.Second()), 10)
  484. b = append(b, []byte{0x20}...)
  485. tz, _ := t.Zone()
  486. if btz, ok := bs.timezones[tz]; ok {
  487. b = append(b, btz...)
  488. } else {
  489. b = append(b, tz...)
  490. }
  491. return string(b)
  492. }