gu.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. package gu
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type gu 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. perMille string
  19. timeSeparator string
  20. inifinity string
  21. currencies []string // idx = enum of currency code
  22. currencyNegativePrefix string
  23. currencyNegativeSuffix string
  24. monthsAbbreviated []string
  25. monthsNarrow []string
  26. monthsWide []string
  27. daysAbbreviated []string
  28. daysNarrow []string
  29. daysShort []string
  30. daysWide []string
  31. periodsAbbreviated []string
  32. periodsNarrow []string
  33. periodsShort []string
  34. periodsWide []string
  35. erasAbbreviated []string
  36. erasNarrow []string
  37. erasWide []string
  38. timezones map[string]string
  39. }
  40. // New returns a new instance of translator for the 'gu' locale
  41. func New() locales.Translator {
  42. return &gu{
  43. locale: "gu",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: []locales.PluralRule{2, 3, 4, 5, 6},
  46. pluralsRange: []locales.PluralRule{2, 6},
  47. decimal: "٫",
  48. timeSeparator: ":",
  49. currencies: []string{"ADP ", "AED", "AFA ", "AFN", "ALK ", "ALL", "AMD", "ANG", "AOA", "AOK ", "AON ", "AOR ", "ARA ", "ARL ", "ARM ", "ARP ", "ARS", "ATS ", "A$", "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 ", "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", "HK$", "HNL", "HRD ", "HRK", "HTG", "HUF", "IDR", "IEP ", "ILP ", "ILR ", "₪", "₹", "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", "฿", "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", "₫", "VNN ", "VUV", "WST", "FCFA", "XAG ", "XAU ", "XBA ", "XBB ", "XBC ", "XBD ", "EC$", "XDR ", "XEU ", "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 "},
  50. currencyNegativePrefix: "(",
  51. currencyNegativeSuffix: ")",
  52. monthsAbbreviated: []string{"", "જાન્યુ", "ફેબ્રુ", "માર્ચ", "એપ્રિલ", "મે", "જૂન", "જુલાઈ", "ઑગસ્ટ", "સપ્ટે", "ઑક્ટો", "નવે", "ડિસે"},
  53. monthsNarrow: []string{"", "જા", "ફે", "મા", "એ", "મે", "જૂ", "જુ", "ઑ", "સ", "ઑ", "ન", "ડિ"},
  54. monthsWide: []string{"", "જાન્યુઆરી", "ફેબ્રુઆરી", "માર્ચ", "એપ્રિલ", "મે", "જૂન", "જુલાઈ", "ઑગસ્ટ", "સપ્ટેમ્બર", "ઑક્ટોબર", "નવેમ્બર", "ડિસેમ્બર"},
  55. daysAbbreviated: []string{"રવિ", "સોમ", "મંગળ", "બુધ", "ગુરુ", "શુક્ર", "શનિ"},
  56. daysNarrow: []string{"ર", "સો", "મં", "બુ", "ગુ", "શુ", "શ"},
  57. daysShort: []string{"ર", "સો", "મં", "બુ", "ગુ", "શુ", "શ"},
  58. daysWide: []string{"રવિવાર", "સોમવાર", "મંગળવાર", "બુધવાર", "ગુરુવાર", "શુક્રવાર", "શનિવાર"},
  59. periodsAbbreviated: []string{"AM", "PM"},
  60. periodsNarrow: []string{"AM", "PM"},
  61. periodsWide: []string{"AM", "PM"},
  62. erasAbbreviated: []string{"ઈ.સ.પૂર્વે", "ઈ.સ."},
  63. erasNarrow: []string{"ઇ સ પુ", "ઇસ"},
  64. erasWide: []string{"ઈસવીસન પૂર્વે", "ઇસવીસન"},
  65. timezones: map[string]string{"ACDT": "ઓસ્ટ્રેલિયન મધ્ય દિવસ સમય", "CST": "ઉત્તર અમેરિકન કેન્દ્રિય પ્રમાણભૂત સમય", "WAT": "પશ્ચિમ આફ્રિકા માનક સમય", "IST": "ભારતીય માનક સમય", "MST": "મકાઉ પ્રમાણભૂત સમય", "HAST": "હવાઇ-એલ્યુશિઅન માનક સમય", "TMST": "તુર્કમેનિસ્તાન ગ્રીષ્મ સમય", "ACWST": "ઓસ્ટ્રેલિયન મધ્ય પશ્ચિમી પ્રમાણભૂત સમય", "AEDT": "ઓસ્ટ્રેલિયન પૂર્વીય દિવસ સમય", "CLT": "ચિલી માનક સમય", "CAT": "મધ્ય આફ્રિકા સમય", "AST": "અટલાન્ટિક પ્રમાણભૂત સમય", "HKST": "હોંગ કોંગ ગ્રીષ્મ સમય", "BOT": "બોલિવિયા સમય", "SRT": "સૂરીનામ સમય", "NZST": "ન્યુઝીલેન્ડ માનક સમય", "UYT": "ઉરૂગ્વે માનક સમય", "WEZ": "પશ્ચિમી યુરોપિયન માનક સમય", "ACWDT": "ઓસ્ટ્રેલિયન મધ્ય પશ્ચિમી દિવસ સમય", "WAST": "પશ્ચિમ આફ્રિકા ગ્રીષ્મ સમય", "TMT": "તુર્કમેનિસ્તાન માનક સમય", "ART": "અર્જેન્ટીના માનક સમય", "AKDT": "અલાસ્કા દિવસ સમય", "UYST": "ઉરૂગ્વે ગ્રીષ્મ સમય", "AEST": "ઓસ્ટ્રેલિયન પૂર્વીય પ્રમાણભૂત સમય", "EDT": "ઉત્તર અમેરિકન પૂર્વી દિવસ સમય", "EAT": "પૂર્વ આફ્રિકા સમય", "CHADT": "ચેતહામ દિવસ સમય", "EST": "ઉત્તર અમેરિકન પૂર્વી પ્રમાણભૂત સમય", "HAT": "ન્યૂફાઉન્ડલેન્ડ દિવસ સમય", "PDT": "ઉત્તર અમેરિકન પેસિફિક દિવસ સમય", "AKST": "અલાસ્કા પ્રમાણભૂત સમય", "JDT": "જાપાન દિવસ સમય", "MEZ": "મધ્ય યુરોપિયન માનક સમય", "MESZ": "મધ્ય યુરોપિયન ગ્રીષ્મ સમય", "VET": "વેનેઝુએલા સમય", "MDT": "મકાઉ ગ્રીષ્મ સમય", "COT": "કોલંબિયા માનક સમય", "CHAST": "ચેતહામ માનક સમય", "MYT": "મલેશિયા સમય", "CLST": "ચિલી ગ્રીષ્મ સમય", "WITA": "મધ્ય ઇન્ડોનેશિયા સમય", "AWDT": "ઓસ્ટ્રેલિયન પશ્ચિમી દિવસ સમય", "PST": "ઉત્તર અમેરિકન પેસિફિક પ્રમાણભૂત સમય", "GYT": "ગયાના સમય", "COST": "કોલંબિયા ગ્રીષ્મ સમય", "BT": "ભૂટાન સમય", "WIT": "પૂર્વીય ઇન્ડોનેશિયા સમય", "ARST": "આર્જેન્ટીના ગ્રીષ્મ સમય", "ChST": "કેમોરો માનક સમય", "HADT": "હવાઇ-એલ્યુશિઅન દિવસ સમય", "SGT": "સિંગાપુર માનક સમય", "WART": "પશ્ચિમી અર્જેન્ટીના માનક સમય", "WARST": "પશ્ચિમી અર્જેન્ટીના ગ્રીષ્મ સમય", "OESZ": "પૂર્વી યુરોપીયન ગ્રીષ્મ સમય", "HNT": "ન્યૂફાઉન્ડલેન્ડ પ્રમાણભૂત સમય", "AWST": "ઓસ્ટ્રેલિયન પશ્ચિમી પ્રમાણભૂત સમય", "NZDT": "ન્યુઝીલેન્ડ દિવસ સમય", "WESZ": "પશ્ચિમી યુરોપિયન ગ્રીષ્મ સમય", "ECT": "એક્વાડોર સમય", "ADT": "અટલાન્ટિક દિવસ સમય", "LHDT": "લોર્ડ હોવ દિવસ સમય", "JST": "જાપાન માનક સમય", "LHST": "લોર્ડ હોવ પ્રમાણભૂત સમય", "SAST": "દક્ષિણ આફ્રિકા માનક સમય", "WIB": "પશ્ચિમી ઇન્ડોનેશિયા સમય", "GMT": "ગ્રીનવિચ મધ્યમ સમય", "∅∅∅": "એમેઝોન ગ્રીષ્મ સમય", "HKT": "હોંગ કોંગ માનક સમય", "CDT": "ઉત્તર અમેરિકન મધ્ય દિવસ સમય", "OEZ": "પૂર્વી યુરોપિયન માનક સમય", "GFT": "ફ્રેન્ચ ગયાના સમય", "ACST": "ઓસ્ટ્રેલિયન મધ્ય પ્રમાણભૂત સમય"},
  66. }
  67. }
  68. // Locale returns the current translators string locale
  69. func (gu *gu) Locale() string {
  70. return gu.locale
  71. }
  72. // PluralsCardinal returns the list of cardinal plural rules associated with 'gu'
  73. func (gu *gu) PluralsCardinal() []locales.PluralRule {
  74. return gu.pluralsCardinal
  75. }
  76. // PluralsOrdinal returns the list of ordinal plural rules associated with 'gu'
  77. func (gu *gu) PluralsOrdinal() []locales.PluralRule {
  78. return gu.pluralsOrdinal
  79. }
  80. // PluralsRange returns the list of range plural rules associated with 'gu'
  81. func (gu *gu) PluralsRange() []locales.PluralRule {
  82. return gu.pluralsRange
  83. }
  84. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'gu'
  85. func (gu *gu) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  86. n := math.Abs(num)
  87. i := int64(n)
  88. if (i == 0) || (n == 1) {
  89. return locales.PluralRuleOne
  90. }
  91. return locales.PluralRuleOther
  92. }
  93. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'gu'
  94. func (gu *gu) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  95. n := math.Abs(num)
  96. if n == 1 {
  97. return locales.PluralRuleOne
  98. } else if n == 2 || n == 3 {
  99. return locales.PluralRuleTwo
  100. } else if n == 4 {
  101. return locales.PluralRuleFew
  102. } else if n == 6 {
  103. return locales.PluralRuleMany
  104. }
  105. return locales.PluralRuleOther
  106. }
  107. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'gu'
  108. func (gu *gu) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  109. start := gu.CardinalPluralRule(num1, v1)
  110. end := gu.CardinalPluralRule(num2, v2)
  111. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  112. return locales.PluralRuleOne
  113. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  114. return locales.PluralRuleOther
  115. }
  116. return locales.PluralRuleOther
  117. }
  118. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  119. func (gu *gu) MonthAbbreviated(month time.Month) string {
  120. return gu.monthsAbbreviated[month]
  121. }
  122. // MonthsAbbreviated returns the locales abbreviated months
  123. func (gu *gu) MonthsAbbreviated() []string {
  124. return gu.monthsAbbreviated[1:]
  125. }
  126. // MonthNarrow returns the locales narrow month given the 'month' provided
  127. func (gu *gu) MonthNarrow(month time.Month) string {
  128. return gu.monthsNarrow[month]
  129. }
  130. // MonthsNarrow returns the locales narrow months
  131. func (gu *gu) MonthsNarrow() []string {
  132. return gu.monthsNarrow[1:]
  133. }
  134. // MonthWide returns the locales wide month given the 'month' provided
  135. func (gu *gu) MonthWide(month time.Month) string {
  136. return gu.monthsWide[month]
  137. }
  138. // MonthsWide returns the locales wide months
  139. func (gu *gu) MonthsWide() []string {
  140. return gu.monthsWide[1:]
  141. }
  142. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  143. func (gu *gu) WeekdayAbbreviated(weekday time.Weekday) string {
  144. return gu.daysAbbreviated[weekday]
  145. }
  146. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  147. func (gu *gu) WeekdaysAbbreviated() []string {
  148. return gu.daysAbbreviated
  149. }
  150. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  151. func (gu *gu) WeekdayNarrow(weekday time.Weekday) string {
  152. return gu.daysNarrow[weekday]
  153. }
  154. // WeekdaysNarrow returns the locales narrow weekdays
  155. func (gu *gu) WeekdaysNarrow() []string {
  156. return gu.daysNarrow
  157. }
  158. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  159. func (gu *gu) WeekdayShort(weekday time.Weekday) string {
  160. return gu.daysShort[weekday]
  161. }
  162. // WeekdaysShort returns the locales short weekdays
  163. func (gu *gu) WeekdaysShort() []string {
  164. return gu.daysShort
  165. }
  166. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  167. func (gu *gu) WeekdayWide(weekday time.Weekday) string {
  168. return gu.daysWide[weekday]
  169. }
  170. // WeekdaysWide returns the locales wide weekdays
  171. func (gu *gu) WeekdaysWide() []string {
  172. return gu.daysWide
  173. }
  174. // FmtNumber returns 'num' with digits/precision of 'v' for 'gu' and handles both Whole and Real numbers based on 'v'
  175. func (gu *gu) FmtNumber(num float64, v uint64) string {
  176. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  177. l := len(s) + 2 + 0*len(s[:len(s)-int(v)-1])/3
  178. count := 0
  179. inWhole := v == 0
  180. inSecondary := false
  181. groupThreshold := 3
  182. b := make([]byte, 0, l)
  183. for i := len(s) - 1; i >= 0; i-- {
  184. if s[i] == '.' {
  185. for j := len(gu.decimal) - 1; j >= 0; j-- {
  186. b = append(b, gu.decimal[j])
  187. }
  188. inWhole = true
  189. continue
  190. }
  191. if inWhole {
  192. if count == groupThreshold {
  193. b = append(b, gu.group[0])
  194. count = 1
  195. if !inSecondary {
  196. inSecondary = true
  197. groupThreshold = 2
  198. }
  199. } else {
  200. count++
  201. }
  202. }
  203. b = append(b, s[i])
  204. }
  205. if num < 0 {
  206. b = append(b, gu.minus[0])
  207. }
  208. // reverse
  209. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  210. b[i], b[j] = b[j], b[i]
  211. }
  212. return string(b)
  213. }
  214. // FmtPercent returns 'num' with digits/precision of 'v' for 'gu' and handles both Whole and Real numbers based on 'v'
  215. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  216. func (gu *gu) FmtPercent(num float64, v uint64) string {
  217. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  218. l := len(s) + 2
  219. b := make([]byte, 0, l)
  220. for i := len(s) - 1; i >= 0; i-- {
  221. if s[i] == '.' {
  222. for j := len(gu.decimal) - 1; j >= 0; j-- {
  223. b = append(b, gu.decimal[j])
  224. }
  225. continue
  226. }
  227. b = append(b, s[i])
  228. }
  229. if num < 0 {
  230. b = append(b, gu.minus[0])
  231. }
  232. // reverse
  233. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  234. b[i], b[j] = b[j], b[i]
  235. }
  236. b = append(b, gu.percent...)
  237. return string(b)
  238. }
  239. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'gu'
  240. func (gu *gu) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  241. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  242. symbol := gu.currencies[currency]
  243. l := len(s) + len(symbol) + 2 + 0*len(s[:len(s)-int(v)-1])/3
  244. count := 0
  245. inWhole := v == 0
  246. inSecondary := false
  247. groupThreshold := 3
  248. b := make([]byte, 0, l)
  249. for i := len(s) - 1; i >= 0; i-- {
  250. if s[i] == '.' {
  251. for j := len(gu.decimal) - 1; j >= 0; j-- {
  252. b = append(b, gu.decimal[j])
  253. }
  254. inWhole = true
  255. continue
  256. }
  257. if inWhole {
  258. if count == groupThreshold {
  259. b = append(b, gu.group[0])
  260. count = 1
  261. if !inSecondary {
  262. inSecondary = true
  263. groupThreshold = 2
  264. }
  265. } else {
  266. count++
  267. }
  268. }
  269. b = append(b, s[i])
  270. }
  271. for j := len(symbol) - 1; j >= 0; j-- {
  272. b = append(b, symbol[j])
  273. }
  274. if num < 0 {
  275. b = append(b, gu.minus[0])
  276. }
  277. // reverse
  278. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  279. b[i], b[j] = b[j], b[i]
  280. }
  281. if int(v) < 2 {
  282. if v == 0 {
  283. b = append(b, gu.decimal...)
  284. }
  285. for i := 0; i < 2-int(v); i++ {
  286. b = append(b, '0')
  287. }
  288. }
  289. return string(b)
  290. }
  291. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'gu'
  292. // in accounting notation.
  293. func (gu *gu) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  294. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  295. symbol := gu.currencies[currency]
  296. l := len(s) + len(symbol) + 4 + 0*len(s[:len(s)-int(v)-1])/3
  297. count := 0
  298. inWhole := v == 0
  299. inSecondary := false
  300. groupThreshold := 3
  301. b := make([]byte, 0, l)
  302. for i := len(s) - 1; i >= 0; i-- {
  303. if s[i] == '.' {
  304. for j := len(gu.decimal) - 1; j >= 0; j-- {
  305. b = append(b, gu.decimal[j])
  306. }
  307. inWhole = true
  308. continue
  309. }
  310. if inWhole {
  311. if count == groupThreshold {
  312. b = append(b, gu.group[0])
  313. count = 1
  314. if !inSecondary {
  315. inSecondary = true
  316. groupThreshold = 2
  317. }
  318. } else {
  319. count++
  320. }
  321. }
  322. b = append(b, s[i])
  323. }
  324. if num < 0 {
  325. for j := len(symbol) - 1; j >= 0; j-- {
  326. b = append(b, symbol[j])
  327. }
  328. b = append(b, gu.currencyNegativePrefix[0])
  329. } else {
  330. for j := len(symbol) - 1; j >= 0; j-- {
  331. b = append(b, symbol[j])
  332. }
  333. }
  334. // reverse
  335. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  336. b[i], b[j] = b[j], b[i]
  337. }
  338. if int(v) < 2 {
  339. if v == 0 {
  340. b = append(b, gu.decimal...)
  341. }
  342. for i := 0; i < 2-int(v); i++ {
  343. b = append(b, '0')
  344. }
  345. }
  346. if num < 0 {
  347. b = append(b, gu.currencyNegativeSuffix...)
  348. }
  349. return string(b)
  350. }
  351. // FmtDateShort returns the short date representation of 't' for 'gu'
  352. func (gu *gu) FmtDateShort(t time.Time) string {
  353. b := make([]byte, 0, 32)
  354. b = strconv.AppendInt(b, int64(t.Day()), 10)
  355. b = append(b, []byte{0x2f}...)
  356. b = strconv.AppendInt(b, int64(t.Month()), 10)
  357. b = append(b, []byte{0x2f}...)
  358. if t.Year() > 9 {
  359. b = append(b, strconv.Itoa(t.Year())[2:]...)
  360. } else {
  361. b = append(b, strconv.Itoa(t.Year())[1:]...)
  362. }
  363. return string(b)
  364. }
  365. // FmtDateMedium returns the medium date representation of 't' for 'gu'
  366. func (gu *gu) 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{0x20}...)
  370. b = append(b, gu.monthsAbbreviated[t.Month()]...)
  371. b = append(b, []byte{0x2c, 0x20}...)
  372. b = strconv.AppendInt(b, int64(t.Year()), 10)
  373. return string(b)
  374. }
  375. // FmtDateLong returns the long date representation of 't' for 'gu'
  376. func (gu *gu) FmtDateLong(t time.Time) string {
  377. b := make([]byte, 0, 32)
  378. b = strconv.AppendInt(b, int64(t.Day()), 10)
  379. b = append(b, []byte{0x20}...)
  380. b = append(b, gu.monthsWide[t.Month()]...)
  381. b = append(b, []byte{0x2c, 0x20}...)
  382. b = strconv.AppendInt(b, int64(t.Year()), 10)
  383. return string(b)
  384. }
  385. // FmtDateFull returns the full date representation of 't' for 'gu'
  386. func (gu *gu) FmtDateFull(t time.Time) string {
  387. b := make([]byte, 0, 32)
  388. b = append(b, gu.daysWide[t.Weekday()]...)
  389. b = append(b, []byte{0x2c, 0x20}...)
  390. b = strconv.AppendInt(b, int64(t.Day()), 10)
  391. b = append(b, []byte{0x20}...)
  392. b = append(b, gu.monthsWide[t.Month()]...)
  393. b = append(b, []byte{0x2c, 0x20}...)
  394. b = strconv.AppendInt(b, int64(t.Year()), 10)
  395. return string(b)
  396. }
  397. // FmtTimeShort returns the short time representation of 't' for 'gu'
  398. func (gu *gu) FmtTimeShort(t time.Time) string {
  399. b := make([]byte, 0, 32)
  400. h := t.Hour()
  401. if h > 12 {
  402. h -= 12
  403. }
  404. if h < 10 {
  405. b = append(b, '0')
  406. }
  407. b = strconv.AppendInt(b, int64(h), 10)
  408. b = append(b, gu.timeSeparator...)
  409. if t.Minute() < 10 {
  410. b = append(b, '0')
  411. }
  412. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  413. b = append(b, []byte{0x20}...)
  414. if t.Hour() < 12 {
  415. b = append(b, gu.periodsAbbreviated[0]...)
  416. } else {
  417. b = append(b, gu.periodsAbbreviated[1]...)
  418. }
  419. return string(b)
  420. }
  421. // FmtTimeMedium returns the medium time representation of 't' for 'gu'
  422. func (gu *gu) FmtTimeMedium(t time.Time) string {
  423. b := make([]byte, 0, 32)
  424. h := t.Hour()
  425. if h > 12 {
  426. h -= 12
  427. }
  428. if h < 10 {
  429. b = append(b, '0')
  430. }
  431. b = strconv.AppendInt(b, int64(h), 10)
  432. b = append(b, gu.timeSeparator...)
  433. if t.Minute() < 10 {
  434. b = append(b, '0')
  435. }
  436. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  437. b = append(b, gu.timeSeparator...)
  438. if t.Second() < 10 {
  439. b = append(b, '0')
  440. }
  441. b = strconv.AppendInt(b, int64(t.Second()), 10)
  442. b = append(b, []byte{0x20}...)
  443. if t.Hour() < 12 {
  444. b = append(b, gu.periodsAbbreviated[0]...)
  445. } else {
  446. b = append(b, gu.periodsAbbreviated[1]...)
  447. }
  448. return string(b)
  449. }
  450. // FmtTimeLong returns the long time representation of 't' for 'gu'
  451. func (gu *gu) FmtTimeLong(t time.Time) string {
  452. b := make([]byte, 0, 32)
  453. h := t.Hour()
  454. if h > 12 {
  455. h -= 12
  456. }
  457. if h < 10 {
  458. b = append(b, '0')
  459. }
  460. b = strconv.AppendInt(b, int64(h), 10)
  461. b = append(b, gu.timeSeparator...)
  462. if t.Minute() < 10 {
  463. b = append(b, '0')
  464. }
  465. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  466. b = append(b, gu.timeSeparator...)
  467. if t.Second() < 10 {
  468. b = append(b, '0')
  469. }
  470. b = strconv.AppendInt(b, int64(t.Second()), 10)
  471. b = append(b, []byte{0x20}...)
  472. if t.Hour() < 12 {
  473. b = append(b, gu.periodsAbbreviated[0]...)
  474. } else {
  475. b = append(b, gu.periodsAbbreviated[1]...)
  476. }
  477. b = append(b, []byte{0x20}...)
  478. tz, _ := t.Zone()
  479. b = append(b, tz...)
  480. return string(b)
  481. }
  482. // FmtTimeFull returns the full time representation of 't' for 'gu'
  483. func (gu *gu) FmtTimeFull(t time.Time) string {
  484. b := make([]byte, 0, 32)
  485. h := t.Hour()
  486. if h > 12 {
  487. h -= 12
  488. }
  489. if h < 10 {
  490. b = append(b, '0')
  491. }
  492. b = strconv.AppendInt(b, int64(h), 10)
  493. b = append(b, gu.timeSeparator...)
  494. if t.Minute() < 10 {
  495. b = append(b, '0')
  496. }
  497. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  498. b = append(b, gu.timeSeparator...)
  499. if t.Second() < 10 {
  500. b = append(b, '0')
  501. }
  502. b = strconv.AppendInt(b, int64(t.Second()), 10)
  503. b = append(b, []byte{0x20}...)
  504. if t.Hour() < 12 {
  505. b = append(b, gu.periodsAbbreviated[0]...)
  506. } else {
  507. b = append(b, gu.periodsAbbreviated[1]...)
  508. }
  509. b = append(b, []byte{0x20}...)
  510. tz, _ := t.Zone()
  511. if btz, ok := gu.timezones[tz]; ok {
  512. b = append(b, btz...)
  513. } else {
  514. b = append(b, tz...)
  515. }
  516. return string(b)
  517. }