ug.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. package ug
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ug 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 'ug' locale
  41. func New() locales.Translator {
  42. return &ug{
  43. locale: "ug",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: nil,
  46. pluralsRange: []locales.PluralRule{6, 2},
  47. decimal: ".",
  48. group: ",",
  49. minus: "-",
  50. percent: "%",
  51. perMille: "‰",
  52. timeSeparator: ":",
  53. inifinity: "∞",
  54. currencies: []string{"ADP ", "AED ", "AFA ", "AFN ", "ALK ", "ALL ", "AMD ", "ANG ", "AOA ", "AOK ", "AON ", "AOR ", "ARA ", "ARL ", "ARM ", "ARP ", "ARS ", "ATS ", "AUD ", "AWG ", "AZM ", "AZN ", "BAD ", "BAM ", "BAN ", "BBD ", "BDT ", "BEC ", "BEF ", "BEL ", "BGL ", "BGM ", "BGN ", "BGO ", "BHD ", "BIF ", "BMD ", "BND ", "BOB ", "BOL ", "BOP ", "BOV ", "BRB ", "BRC ", "BRE ", "BRL ", "BRN ", "BRR ", "BRZ ", "BSD ", "BTN ", "BUK ", "BWP ", "BYB ", "BYR ", "BZD ", "CAD ", "CDF ", "CHE ", "CHF ", "CHW ", "CLE ", "CLF ", "CLP ", "CNX ", "¥", "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 ", "EUR ", "FIM ", "FJD ", "FKP ", "FRF ", "GBP ", "GEK ", "GEL ", "GHC ", "GHS ", "GIP ", "GMD ", "GNF ", "GNS ", "GQE ", "GRD ", "GTQ ", "GWE ", "GWP ", "GYD ", "HKD ", "HNL ", "HRD ", "HRK ", "HTG ", "HUF ", "IDR ", "IEP ", "ILP ", "ILR ", "ILS ", "INR ", "IQD ", "IRR ", "ISJ ", "ISK ", "ITL ", "JMD ", "JOD ", "JPY ", "KES ", "KGS ", "KHR ", "KMF ", "KPW ", "KRH ", "KRO ", "KRW ", "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 ", "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 ", "TWD ", "TZS ", "UAH ", "UAK ", "UGS ", "UGX ", "$", "USN ", "USS ", "UYI ", "UYP ", "UYU ", "UZS ", "VEB ", "VEF ", "VND ", "VNN ", "VUV ", "WST ", "XAF ", "XAG ", "XAU ", "XBA ", "XBB ", "XBC ", "XBD ", "XCD ", "XDR ", "XEU ", "XFO ", "XFU ", "XOF ", "XPD ", "XPF ", "XPT ", "XRE ", "XSU ", "XTS ", "XUA ", "XXX ", "YDD ", "YER ", "YUD ", "YUM ", "YUN ", "YUR ", "ZAL ", "ZAR ", "ZMK ", "ZMW ", "ZRN ", "ZRZ ", "ZWD ", "ZWL ", "ZWR "},
  55. currencyNegativePrefix: "(",
  56. currencyNegativeSuffix: ")",
  57. monthsAbbreviated: []string{"", "يانۋار", "فېۋرال", "مارت", "ئاپرېل", "ماي", "ئىيۇن", "ئىيۇل", "ئاۋغۇست", "سېنتەبىر", "ئۆكتەبىر", "نويابىر", "دېكابىر"},
  58. monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  59. monthsWide: []string{"", "يانۋار", "فېۋرال", "مارت", "ئاپرېل", "ماي", "ئىيۇن", "ئىيۇل", "ئاۋغۇست", "سېنتەبىر", "ئۆكتەبىر", "نويابىر", "دېكابىر"},
  60. daysAbbreviated: []string{"يە", "دۈ", "سە", "چا", "پە", "جۈ", "شە"},
  61. daysNarrow: []string{"ي", "د", "س", "چ", "پ", "ج", "ش"},
  62. daysShort: []string{"ي", "د", "س", "چ", "پ", "ج", "ش"},
  63. daysWide: []string{"يەكشەنبە", "دۈشەنبە", "سەيشەنبە", "چارشەنبە", "پەيشەنبە", "جۈمە", "شەنبە"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"چۈشتىن بۇرۇن", "چۈشتىن كېيىن"},
  66. periodsWide: []string{"چۈشتىن بۇرۇن", "چۈشتىن كېيىن"},
  67. erasAbbreviated: []string{"BCE", "مىلادىيە"},
  68. erasNarrow: []string{"BCE", "مىلادىيە"},
  69. erasWide: []string{"مىلادىيەدىن بۇرۇن", "مىلادىيە"},
  70. timezones: map[string]string{"EST": "شەرقىي قىسىم ئۆلچەملىك ۋاقتى", "AST": "ئاتلانتىك ئوكيان ئۆلچەملىك ۋاقتى", "HADT": "ھاۋاي-ئالېيۇت يازلىق ۋاقتى", "WIB": "غەربىي ھىندونېزىيە ۋاقتى", "ART": "ئارگېنتىنا ئۆلچەملىك ۋاقتى", "ARST": "ئارگېنتىنا يازلىق ۋاقتى", "ACDT": "ئاۋسترالىيە ئوتتۇرا قىسىم يازلىق ۋاقتى", "CHAST": "چاتام ئۆلچەملىك ۋاقتى", "HNT": "نىۋفوئۇنلاند ئۆلچەملىك ۋاقتى", "GMT": "گىرىنۋىچ ۋاقتى", "TMT": "تۈركمەنىستان ئۆلچەملىك ۋاقتى", "VET": "ۋېنېزۇئېلا ۋاقتى", "ACWST": "ئاۋستىرالىيە ئوتتۇرا غەربىي قىسىم ئۆلچەملىك ۋاقتى", "HKT": "شياڭگاڭ ئۆلچەملىك ۋاقتى", "OESZ": "شەرقىي ياۋروپا يازلىق ۋاقتى", "WEZ": "غەربىي ياۋروپا ئۆلچەملىك ۋاقتى", "ECT": "ئېكۋادور ۋاقتى", "AEDT": "ئاۋسترالىيە شەرقىي قىسىم يازلىق ۋاقتى", "COT": "كولومبىيە ئۆلچەملىك ۋاقتى", "IST": "ھىندىستان ئۆلچەملىك ۋاقتى", "AKDT": "ئالياسكا يازلىق ۋاقتى", "PDT": "تىنچ ئوكيان يازلىق ۋاقتى", "MEZ": "ئوتتۇرا ياۋروپا ئۆلچەملىك ۋاقتى", "MESZ": "ئوتتۇرا ياۋروپا يازلىق ۋاقتى", "OEZ": "شەرقىي ياۋروپا ئۆلچەملىك ۋاقتى", "AKST": "ئالياسكا ئۆلچەملىك ۋاقتى", "CAT": "ئوتتۇرا ئافرىقا ۋاقتى", "COST": "كولومبىيە يازلىق ۋاقتى", "HKST": "شياڭگاڭ يازلىق ۋاقتى", "LHST": "لورد-خاي ئۆلچەملىك ۋاقتى", "LHDT": "لورد-خاي يازلىق ۋاقتى", "ChST": "چاموررو ئۆلچەملىك ۋاقتى", "CHADT": "چاتام يازلىق ۋاقتى", "CLST": "چىلى يازلىق ۋاقتى", "WART": "غەربىي ئارگېنتىنا ئۆلچەملىك ۋاقتى", "JDT": "ياپونىيە يازلىق ۋاقتى", "ACWDT": "ئاۋسترالىيە ئوتتۇرا غەربىي قىسىم يازلىق ۋاقتى", "ADT": "ئاتلانتىك ئوكيان يازلىق ۋاقتى", "WAT": "غەربىي ئافرىقا ئۆلچەملىك ۋاقتى", "GFT": "فىرانسىيەگە قاراشلىق گىۋىيانا ۋاقتى", "WITA": "ئوتتۇرا ھىندونېزىيە ۋاقتى", "EDT": "شەرقىي قىسىم يازلىق ۋاقتى", "MYT": "مالايشىيا ۋاقتى", "JST": "ياپونىيە ئۆلچەملىك ۋاقتى", "BOT": "بولىۋىيە ۋاقتى", "UYT": "ئۇرۇگۋاي ئۆلچەملىك ۋاقتى", "SGT": "سىنگاپور ۋاقتى", "AWST": "ئاۋسترالىيە غەربىي قىسىم ئۆلچەملىك ۋاقتى", "CDT": "ئوتتۇرا قىسىم يازلىق ۋاقتى", "NZDT": "يېڭى زېلاندىيە يازلىق ۋاقتى", "CLT": "چىلى ئۆلچەملىك ۋاقتى", "WESZ": "غەربىي ياۋروپا يازلىق ۋاقتى", "SAST": "جەنۇبىي ئافرىقا ئۆلچەملىك ۋاقتى", "∅∅∅": "ئامازون يازلىق ۋاقتى", "MST": "ئاۋمېن ئۆلچەملىك ۋاقتى", "UYST": "ئۇرۇگۋاي يازلىق ۋاقتى", "WAST": "غەربىي ئافرىقا يازلىق ۋاقتى", "GYT": "گىۋىيانا ۋاقتى", "AWDT": "ئاۋسترالىيە غەربىي قىسىم يازلىق ۋاقتى", "HAST": "ھاۋاي-ئالېيۇت ئۆلچەملىك ۋاقتى", "BT": "بۇتان ۋاقتى", "HAT": "نىۋفوئۇنلاند يازلىق ۋاقتى", "WIT": "شەرقىي ھىندونېزىيە ۋاقتى", "SRT": "سۇرىنام ۋاقتى", "AEST": "ئاۋسترالىيە شەرقىي قىسىم ئۆلچەملىك ۋاقتى", "PST": "تىنچ ئوكيان ئۆلچەملىك ۋاقتى", "CST": "ئوتتۇرا قىسىم ئۆلچەملىك ۋاقتى", "NZST": "يېڭى زېلاندىيە ئۆلچەملىك ۋاقتى", "WARST": "غەربىي ئارگېنتىنا يازلىق ۋاقتى", "TMST": "تۈركمەنىستان يازلىق ۋاقتى", "EAT": "شەرقىي ئافرىقا ۋاقتى", "MDT": "ئاۋمېن يازلىق ۋاقتى", "ACST": "ئاۋسترالىيە ئوتتۇرا قىسىم ئۆلچەملىك ۋاقتى"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (ug *ug) Locale() string {
  75. return ug.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'ug'
  78. func (ug *ug) PluralsCardinal() []locales.PluralRule {
  79. return ug.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ug'
  82. func (ug *ug) PluralsOrdinal() []locales.PluralRule {
  83. return ug.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'ug'
  86. func (ug *ug) PluralsRange() []locales.PluralRule {
  87. return ug.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ug'
  90. func (ug *ug) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. if n == 1 {
  93. return locales.PluralRuleOne
  94. }
  95. return locales.PluralRuleOther
  96. }
  97. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ug'
  98. func (ug *ug) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  99. return locales.PluralRuleUnknown
  100. }
  101. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ug'
  102. func (ug *ug) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  103. start := ug.CardinalPluralRule(num1, v1)
  104. end := ug.CardinalPluralRule(num2, v2)
  105. if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  106. return locales.PluralRuleOther
  107. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  108. return locales.PluralRuleOne
  109. }
  110. return locales.PluralRuleOther
  111. }
  112. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  113. func (ug *ug) MonthAbbreviated(month time.Month) string {
  114. return ug.monthsAbbreviated[month]
  115. }
  116. // MonthsAbbreviated returns the locales abbreviated months
  117. func (ug *ug) MonthsAbbreviated() []string {
  118. return ug.monthsAbbreviated[1:]
  119. }
  120. // MonthNarrow returns the locales narrow month given the 'month' provided
  121. func (ug *ug) MonthNarrow(month time.Month) string {
  122. return ug.monthsNarrow[month]
  123. }
  124. // MonthsNarrow returns the locales narrow months
  125. func (ug *ug) MonthsNarrow() []string {
  126. return ug.monthsNarrow[1:]
  127. }
  128. // MonthWide returns the locales wide month given the 'month' provided
  129. func (ug *ug) MonthWide(month time.Month) string {
  130. return ug.monthsWide[month]
  131. }
  132. // MonthsWide returns the locales wide months
  133. func (ug *ug) MonthsWide() []string {
  134. return ug.monthsWide[1:]
  135. }
  136. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  137. func (ug *ug) WeekdayAbbreviated(weekday time.Weekday) string {
  138. return ug.daysAbbreviated[weekday]
  139. }
  140. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  141. func (ug *ug) WeekdaysAbbreviated() []string {
  142. return ug.daysAbbreviated
  143. }
  144. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  145. func (ug *ug) WeekdayNarrow(weekday time.Weekday) string {
  146. return ug.daysNarrow[weekday]
  147. }
  148. // WeekdaysNarrow returns the locales narrow weekdays
  149. func (ug *ug) WeekdaysNarrow() []string {
  150. return ug.daysNarrow
  151. }
  152. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  153. func (ug *ug) WeekdayShort(weekday time.Weekday) string {
  154. return ug.daysShort[weekday]
  155. }
  156. // WeekdaysShort returns the locales short weekdays
  157. func (ug *ug) WeekdaysShort() []string {
  158. return ug.daysShort
  159. }
  160. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  161. func (ug *ug) WeekdayWide(weekday time.Weekday) string {
  162. return ug.daysWide[weekday]
  163. }
  164. // WeekdaysWide returns the locales wide weekdays
  165. func (ug *ug) WeekdaysWide() []string {
  166. return ug.daysWide
  167. }
  168. // FmtNumber returns 'num' with digits/precision of 'v' for 'ug' and handles both Whole and Real numbers based on 'v'
  169. func (ug *ug) FmtNumber(num float64, v uint64) string {
  170. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  171. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  172. count := 0
  173. inWhole := v == 0
  174. b := make([]byte, 0, l)
  175. for i := len(s) - 1; i >= 0; i-- {
  176. if s[i] == '.' {
  177. b = append(b, ug.decimal[0])
  178. inWhole = true
  179. continue
  180. }
  181. if inWhole {
  182. if count == 3 {
  183. b = append(b, ug.group[0])
  184. count = 1
  185. } else {
  186. count++
  187. }
  188. }
  189. b = append(b, s[i])
  190. }
  191. if num < 0 {
  192. b = append(b, ug.minus[0])
  193. }
  194. // reverse
  195. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  196. b[i], b[j] = b[j], b[i]
  197. }
  198. return string(b)
  199. }
  200. // FmtPercent returns 'num' with digits/precision of 'v' for 'ug' and handles both Whole and Real numbers based on 'v'
  201. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  202. func (ug *ug) FmtPercent(num float64, v uint64) string {
  203. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  204. l := len(s) + 3
  205. b := make([]byte, 0, l)
  206. for i := len(s) - 1; i >= 0; i-- {
  207. if s[i] == '.' {
  208. b = append(b, ug.decimal[0])
  209. continue
  210. }
  211. b = append(b, s[i])
  212. }
  213. if num < 0 {
  214. b = append(b, ug.minus[0])
  215. }
  216. // reverse
  217. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  218. b[i], b[j] = b[j], b[i]
  219. }
  220. b = append(b, ug.percent...)
  221. return string(b)
  222. }
  223. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ug'
  224. func (ug *ug) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  225. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  226. symbol := ug.currencies[currency]
  227. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  228. count := 0
  229. inWhole := v == 0
  230. b := make([]byte, 0, l)
  231. for i := len(s) - 1; i >= 0; i-- {
  232. if s[i] == '.' {
  233. b = append(b, ug.decimal[0])
  234. inWhole = true
  235. continue
  236. }
  237. if inWhole {
  238. if count == 3 {
  239. b = append(b, ug.group[0])
  240. count = 1
  241. } else {
  242. count++
  243. }
  244. }
  245. b = append(b, s[i])
  246. }
  247. for j := len(symbol) - 1; j >= 0; j-- {
  248. b = append(b, symbol[j])
  249. }
  250. if num < 0 {
  251. b = append(b, ug.minus[0])
  252. }
  253. // reverse
  254. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  255. b[i], b[j] = b[j], b[i]
  256. }
  257. if int(v) < 2 {
  258. if v == 0 {
  259. b = append(b, ug.decimal...)
  260. }
  261. for i := 0; i < 2-int(v); i++ {
  262. b = append(b, '0')
  263. }
  264. }
  265. return string(b)
  266. }
  267. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ug'
  268. // in accounting notation.
  269. func (ug *ug) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  270. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  271. symbol := ug.currencies[currency]
  272. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  273. count := 0
  274. inWhole := v == 0
  275. b := make([]byte, 0, l)
  276. for i := len(s) - 1; i >= 0; i-- {
  277. if s[i] == '.' {
  278. b = append(b, ug.decimal[0])
  279. inWhole = true
  280. continue
  281. }
  282. if inWhole {
  283. if count == 3 {
  284. b = append(b, ug.group[0])
  285. count = 1
  286. } else {
  287. count++
  288. }
  289. }
  290. b = append(b, s[i])
  291. }
  292. if num < 0 {
  293. for j := len(symbol) - 1; j >= 0; j-- {
  294. b = append(b, symbol[j])
  295. }
  296. b = append(b, ug.currencyNegativePrefix[0])
  297. } else {
  298. for j := len(symbol) - 1; j >= 0; j-- {
  299. b = append(b, symbol[j])
  300. }
  301. }
  302. // reverse
  303. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  304. b[i], b[j] = b[j], b[i]
  305. }
  306. if int(v) < 2 {
  307. if v == 0 {
  308. b = append(b, ug.decimal...)
  309. }
  310. for i := 0; i < 2-int(v); i++ {
  311. b = append(b, '0')
  312. }
  313. }
  314. if num < 0 {
  315. b = append(b, ug.currencyNegativeSuffix...)
  316. }
  317. return string(b)
  318. }
  319. // FmtDateShort returns the short date representation of 't' for 'ug'
  320. func (ug *ug) FmtDateShort(t time.Time) string {
  321. b := make([]byte, 0, 32)
  322. b = strconv.AppendInt(b, int64(t.Month()), 10)
  323. b = append(b, []byte{0x2f}...)
  324. b = strconv.AppendInt(b, int64(t.Day()), 10)
  325. b = append(b, []byte{0x2f}...)
  326. if t.Year() > 9 {
  327. b = append(b, strconv.Itoa(t.Year())[2:]...)
  328. } else {
  329. b = append(b, strconv.Itoa(t.Year())[1:]...)
  330. }
  331. return string(b)
  332. }
  333. // FmtDateMedium returns the medium date representation of 't' for 'ug'
  334. func (ug *ug) FmtDateMedium(t time.Time) string {
  335. b := make([]byte, 0, 32)
  336. b = append(b, ug.monthsAbbreviated[t.Month()]...)
  337. b = append(b, []byte{0x20}...)
  338. b = strconv.AppendInt(b, int64(t.Day()), 10)
  339. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  340. b = strconv.AppendInt(b, int64(t.Year()), 10)
  341. return string(b)
  342. }
  343. // FmtDateLong returns the long date representation of 't' for 'ug'
  344. func (ug *ug) FmtDateLong(t time.Time) string {
  345. b := make([]byte, 0, 32)
  346. b = append(b, ug.monthsWide[t.Month()]...)
  347. b = append(b, []byte{0x20}...)
  348. b = strconv.AppendInt(b, int64(t.Day()), 10)
  349. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  350. b = strconv.AppendInt(b, int64(t.Year()), 10)
  351. return string(b)
  352. }
  353. // FmtDateFull returns the full date representation of 't' for 'ug'
  354. func (ug *ug) FmtDateFull(t time.Time) string {
  355. b := make([]byte, 0, 32)
  356. b = append(b, ug.daysWide[t.Weekday()]...)
  357. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  358. b = append(b, ug.monthsWide[t.Month()]...)
  359. b = append(b, []byte{0x20}...)
  360. b = strconv.AppendInt(b, int64(t.Day()), 10)
  361. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  362. b = strconv.AppendInt(b, int64(t.Year()), 10)
  363. return string(b)
  364. }
  365. // FmtTimeShort returns the short time representation of 't' for 'ug'
  366. func (ug *ug) FmtTimeShort(t time.Time) string {
  367. b := make([]byte, 0, 32)
  368. h := t.Hour()
  369. if h > 12 {
  370. h -= 12
  371. }
  372. b = strconv.AppendInt(b, int64(h), 10)
  373. b = append(b, ug.timeSeparator...)
  374. if t.Minute() < 10 {
  375. b = append(b, '0')
  376. }
  377. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  378. b = append(b, []byte{0x20}...)
  379. if t.Hour() < 12 {
  380. b = append(b, ug.periodsAbbreviated[0]...)
  381. } else {
  382. b = append(b, ug.periodsAbbreviated[1]...)
  383. }
  384. return string(b)
  385. }
  386. // FmtTimeMedium returns the medium time representation of 't' for 'ug'
  387. func (ug *ug) FmtTimeMedium(t time.Time) string {
  388. b := make([]byte, 0, 32)
  389. h := t.Hour()
  390. if h > 12 {
  391. h -= 12
  392. }
  393. b = strconv.AppendInt(b, int64(h), 10)
  394. b = append(b, ug.timeSeparator...)
  395. if t.Minute() < 10 {
  396. b = append(b, '0')
  397. }
  398. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  399. b = append(b, ug.timeSeparator...)
  400. if t.Second() < 10 {
  401. b = append(b, '0')
  402. }
  403. b = strconv.AppendInt(b, int64(t.Second()), 10)
  404. b = append(b, []byte{0x20}...)
  405. if t.Hour() < 12 {
  406. b = append(b, ug.periodsAbbreviated[0]...)
  407. } else {
  408. b = append(b, ug.periodsAbbreviated[1]...)
  409. }
  410. return string(b)
  411. }
  412. // FmtTimeLong returns the long time representation of 't' for 'ug'
  413. func (ug *ug) FmtTimeLong(t time.Time) string {
  414. b := make([]byte, 0, 32)
  415. h := t.Hour()
  416. if h > 12 {
  417. h -= 12
  418. }
  419. b = strconv.AppendInt(b, int64(h), 10)
  420. b = append(b, ug.timeSeparator...)
  421. if t.Minute() < 10 {
  422. b = append(b, '0')
  423. }
  424. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  425. b = append(b, ug.timeSeparator...)
  426. if t.Second() < 10 {
  427. b = append(b, '0')
  428. }
  429. b = strconv.AppendInt(b, int64(t.Second()), 10)
  430. b = append(b, []byte{0x20}...)
  431. if t.Hour() < 12 {
  432. b = append(b, ug.periodsAbbreviated[0]...)
  433. } else {
  434. b = append(b, ug.periodsAbbreviated[1]...)
  435. }
  436. b = append(b, []byte{0x20}...)
  437. tz, _ := t.Zone()
  438. b = append(b, tz...)
  439. return string(b)
  440. }
  441. // FmtTimeFull returns the full time representation of 't' for 'ug'
  442. func (ug *ug) FmtTimeFull(t time.Time) string {
  443. b := make([]byte, 0, 32)
  444. h := t.Hour()
  445. if h > 12 {
  446. h -= 12
  447. }
  448. b = strconv.AppendInt(b, int64(h), 10)
  449. b = append(b, ug.timeSeparator...)
  450. if t.Minute() < 10 {
  451. b = append(b, '0')
  452. }
  453. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  454. b = append(b, ug.timeSeparator...)
  455. if t.Second() < 10 {
  456. b = append(b, '0')
  457. }
  458. b = strconv.AppendInt(b, int64(t.Second()), 10)
  459. b = append(b, []byte{0x20}...)
  460. if t.Hour() < 12 {
  461. b = append(b, ug.periodsAbbreviated[0]...)
  462. } else {
  463. b = append(b, ug.periodsAbbreviated[1]...)
  464. }
  465. b = append(b, []byte{0x20}...)
  466. tz, _ := t.Zone()
  467. if btz, ok := ug.timezones[tz]; ok {
  468. b = append(b, btz...)
  469. } else {
  470. b = append(b, tz...)
  471. }
  472. return string(b)
  473. }