cy_GB.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. package cy_GB
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type cy_GB 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 'cy_GB' locale
  41. func New() locales.Translator {
  42. return &cy_GB{
  43. locale: "cy_GB",
  44. pluralsCardinal: []locales.PluralRule{1, 2, 3, 4, 5, 6},
  45. pluralsOrdinal: []locales.PluralRule{1, 2, 3, 4, 5, 6},
  46. pluralsRange: []locales.PluralRule{2, 3, 4, 5, 6},
  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", "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", "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", "STN", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "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{"", "Ion", "Chwef", "Maw", "Ebrill", "Mai", "Meh", "Gorff", "Awst", "Medi", "Hyd", "Tach", "Rhag"},
  58. monthsNarrow: []string{"", "I", "Ch", "M", "E", "M", "M", "G", "A", "M", "H", "T", "Rh"},
  59. monthsWide: []string{"", "Ionawr", "Chwefror", "Mawrth", "Ebrill", "Mai", "Mehefin", "Gorffennaf", "Awst", "Medi", "Hydref", "Tachwedd", "Rhagfyr"},
  60. daysAbbreviated: []string{"Sul", "Llun", "Maw", "Mer", "Iau", "Gwen", "Sad"},
  61. daysNarrow: []string{"S", "Ll", "M", "M", "I", "G", "S"},
  62. daysShort: []string{"Su", "Ll", "Ma", "Me", "Ia", "Gw", "Sa"},
  63. daysWide: []string{"Dydd Sul", "Dydd Llun", "Dydd Mawrth", "Dydd Mercher", "Dydd Iau", "Dydd Gwener", "Dydd Sadwrn"},
  64. periodsAbbreviated: []string{"yb", "yh"},
  65. periodsNarrow: []string{"b", "h"},
  66. periodsWide: []string{"yb", "yh"},
  67. erasAbbreviated: []string{"CC", "OC"},
  68. erasNarrow: []string{"C", "O"},
  69. erasWide: []string{"Cyn Crist", "Oed Crist"},
  70. timezones: map[string]string{"MDT": "Amser Haf Mynyddoedd Gogledd America", "HEOG": "Amser Haf Gorllewin yr Ynys Las", "HNT": "Amser Safonol Newfoundland", "OESZ": "Amser Haf Dwyrain Ewrop", "HECU": "Amser Haf Cuba", "HEEG": "Amser Haf Dwyrain yr Ynys Las", "ART": "Amser Safonol Ariannin", "LHDT": "Amser Haf yr Arglwydd Howe", "EAT": "Amser Dwyrain Affrica", "HADT": "Amser Haf Hawaii-Aleutian", "CST": "Amser Safonol Canolbarth Gogledd America", "WAST": "Amser Haf Gorllewin Affrica", "SAST": "Amser Safonol De Affrica", "MYT": "Amser Malaysia", "HKST": "Amser Haf Hong Kong", "COT": "Amser Safonol Colombia", "GYT": "Amser Guyana", "CHAST": "Amser Safonol Chatham", "CHADT": "Amser Haf Chatham", "MEZ": "Amser Safonol Canolbarth Ewrop", "LHST": "Amser Safonol yr Arglwydd Howe", "WART": "Amser Safonol Gorllewin Ariannin", "UYST": "Amser Haf Uruguay", "CLT": "Amser Safonol Chile", "HAST": "Amser Safonol Hawaii-Aleutian", "ACWDT": "Amser Haf Canolbarth Gorllewin Awstralia", "HKT": "Amser Safonol Hong Kong", "WARST": "Amser Haf Gorllewin Ariannin", "VET": "Amser Venezuela", "SRT": "Amser Suriname", "IST": "Amser India", "HNPM": "Amser Safonol Saint-Pierre-et-Miquelon", "ChST": "Amser Chamorro", "PDT": "Amser Haf Cefnfor Tawel Gogledd America", "AWDT": "Amser Haf Gorllewin Awstralia", "HEPMX": "Amser Haf Pasiffig Mecsico", "ACWST": "Amser Safonol Canolbarth Gorllewin Awstralia", "MESZ": "Amser Haf Canolbarth Ewrop", "HNCU": "Amser Safonol Cuba", "ADT": "Amser Haf Cefnfor yr Iwerydd", "WAT": "Amser Safonol Gorllewin Affrica", "HEPM": "Amser Haf Saint-Pierre-et-Miquelon", "HNNOMX": "Amser Safonol Gogledd Orllewin Mecsico", "OEZ": "Amser Safonol Dwyrain Ewrop", "HENOMX": "Amser Haf Gogledd Orllewin Mecsico", "AWST": "Amser Safonol Gorllewin Awstralia", "WESZ": "Amser Haf Gorllewin Ewrop", "∅∅∅": "∅∅∅", "GFT": "Amser Guyane Ffrengig", "HNOG": "Amser Safonol Gorllewin yr Ynys Las", "CDT": "Amser Haf Canolbarth Gogledd America", "SGT": "Amser Singapore", "HAT": "Amser Haf Newfoundland", "COST": "Amser Haf Colombia", "JDT": "Amser Haf Siapan", "AKDT": "Amser Haf Alaska", "WITA": "Amser Canolbarth Indonesia", "CLST": "Amser Haf Chile", "WIT": "Amser Dwyrain Indonesia", "PST": "Amser Safonol Cefnfor Tawel Gogledd America", "BOT": "Amser Bolivia", "TMST": "Amser Haf Tyrcmenistan", "GMT": "Amser Safonol Greenwich", "HNPMX": "Amser Safonol Pasiffig Mecsico", "AEDT": "Amser Haf Dwyrain Awstralia", "AST": "Amser Safonol Cefnfor yr Iwerydd", "CAT": "Amser Canolbarth Affrica", "WEZ": "Amser Safonol Gorllewin Ewrop", "BT": "Amser Bhutan", "ACDT": "Amser Haf Canolbarth Awstralia", "HNEG": "Amser Safonol Dwyrain yr Ynys Las", "EST": "Amser Safonol Dwyrain Gogledd America", "MST": "Amser Safonol Mynyddoedd Gogledd America", "WIB": "Amser Gorllewin Indonesia", "AKST": "Amser Safonol Alaska", "ARST": "Amser Haf Ariannin", "UYT": "Amser Safonol Uruguay", "JST": "Amser Safonol Siapan", "ACST": "Amser Safonol Canolbarth Awstralia", "TMT": "Amser Safonol Tyrcmenistan", "AEST": "Amser Safonol Dwyrain Awstralia", "NZST": "Amser Safonol Seland Newydd", "NZDT": "Amser Haf Seland Newydd", "ECT": "Amser Ecuador", "EDT": "Amser Haf Dwyrain Gogledd America"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (cy *cy_GB) Locale() string {
  75. return cy.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'cy_GB'
  78. func (cy *cy_GB) PluralsCardinal() []locales.PluralRule {
  79. return cy.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'cy_GB'
  82. func (cy *cy_GB) PluralsOrdinal() []locales.PluralRule {
  83. return cy.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'cy_GB'
  86. func (cy *cy_GB) PluralsRange() []locales.PluralRule {
  87. return cy.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'cy_GB'
  90. func (cy *cy_GB) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. if n == 0 {
  93. return locales.PluralRuleZero
  94. } else if n == 1 {
  95. return locales.PluralRuleOne
  96. } else if n == 2 {
  97. return locales.PluralRuleTwo
  98. } else if n == 3 {
  99. return locales.PluralRuleFew
  100. } else if n == 6 {
  101. return locales.PluralRuleMany
  102. }
  103. return locales.PluralRuleOther
  104. }
  105. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'cy_GB'
  106. func (cy *cy_GB) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  107. n := math.Abs(num)
  108. if n == 0 || n == 7 || n == 8 || n == 9 {
  109. return locales.PluralRuleZero
  110. } else if n == 1 {
  111. return locales.PluralRuleOne
  112. } else if n == 2 {
  113. return locales.PluralRuleTwo
  114. } else if n == 3 || n == 4 {
  115. return locales.PluralRuleFew
  116. } else if n == 5 || n == 6 {
  117. return locales.PluralRuleMany
  118. }
  119. return locales.PluralRuleOther
  120. }
  121. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'cy_GB'
  122. func (cy *cy_GB) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  123. start := cy.CardinalPluralRule(num1, v1)
  124. end := cy.CardinalPluralRule(num2, v2)
  125. if start == locales.PluralRuleZero && end == locales.PluralRuleOne {
  126. return locales.PluralRuleOne
  127. } else if start == locales.PluralRuleZero && end == locales.PluralRuleTwo {
  128. return locales.PluralRuleTwo
  129. } else if start == locales.PluralRuleZero && end == locales.PluralRuleFew {
  130. return locales.PluralRuleFew
  131. } else if start == locales.PluralRuleZero && end == locales.PluralRuleMany {
  132. return locales.PluralRuleMany
  133. } else if start == locales.PluralRuleZero && end == locales.PluralRuleOther {
  134. return locales.PluralRuleOther
  135. } else if start == locales.PluralRuleOne && end == locales.PluralRuleTwo {
  136. return locales.PluralRuleTwo
  137. } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
  138. return locales.PluralRuleFew
  139. } else if start == locales.PluralRuleOne && end == locales.PluralRuleMany {
  140. return locales.PluralRuleMany
  141. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  142. return locales.PluralRuleOther
  143. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleFew {
  144. return locales.PluralRuleFew
  145. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleMany {
  146. return locales.PluralRuleMany
  147. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleOther {
  148. return locales.PluralRuleOther
  149. } else if start == locales.PluralRuleFew && end == locales.PluralRuleMany {
  150. return locales.PluralRuleMany
  151. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
  152. return locales.PluralRuleOther
  153. } else if start == locales.PluralRuleMany && end == locales.PluralRuleOther {
  154. return locales.PluralRuleOther
  155. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  156. return locales.PluralRuleOne
  157. } else if start == locales.PluralRuleOther && end == locales.PluralRuleTwo {
  158. return locales.PluralRuleTwo
  159. } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew {
  160. return locales.PluralRuleFew
  161. } else if start == locales.PluralRuleOther && end == locales.PluralRuleMany {
  162. return locales.PluralRuleMany
  163. }
  164. return locales.PluralRuleOther
  165. }
  166. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  167. func (cy *cy_GB) MonthAbbreviated(month time.Month) string {
  168. return cy.monthsAbbreviated[month]
  169. }
  170. // MonthsAbbreviated returns the locales abbreviated months
  171. func (cy *cy_GB) MonthsAbbreviated() []string {
  172. return cy.monthsAbbreviated[1:]
  173. }
  174. // MonthNarrow returns the locales narrow month given the 'month' provided
  175. func (cy *cy_GB) MonthNarrow(month time.Month) string {
  176. return cy.monthsNarrow[month]
  177. }
  178. // MonthsNarrow returns the locales narrow months
  179. func (cy *cy_GB) MonthsNarrow() []string {
  180. return cy.monthsNarrow[1:]
  181. }
  182. // MonthWide returns the locales wide month given the 'month' provided
  183. func (cy *cy_GB) MonthWide(month time.Month) string {
  184. return cy.monthsWide[month]
  185. }
  186. // MonthsWide returns the locales wide months
  187. func (cy *cy_GB) MonthsWide() []string {
  188. return cy.monthsWide[1:]
  189. }
  190. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  191. func (cy *cy_GB) WeekdayAbbreviated(weekday time.Weekday) string {
  192. return cy.daysAbbreviated[weekday]
  193. }
  194. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  195. func (cy *cy_GB) WeekdaysAbbreviated() []string {
  196. return cy.daysAbbreviated
  197. }
  198. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  199. func (cy *cy_GB) WeekdayNarrow(weekday time.Weekday) string {
  200. return cy.daysNarrow[weekday]
  201. }
  202. // WeekdaysNarrow returns the locales narrow weekdays
  203. func (cy *cy_GB) WeekdaysNarrow() []string {
  204. return cy.daysNarrow
  205. }
  206. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  207. func (cy *cy_GB) WeekdayShort(weekday time.Weekday) string {
  208. return cy.daysShort[weekday]
  209. }
  210. // WeekdaysShort returns the locales short weekdays
  211. func (cy *cy_GB) WeekdaysShort() []string {
  212. return cy.daysShort
  213. }
  214. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  215. func (cy *cy_GB) WeekdayWide(weekday time.Weekday) string {
  216. return cy.daysWide[weekday]
  217. }
  218. // WeekdaysWide returns the locales wide weekdays
  219. func (cy *cy_GB) WeekdaysWide() []string {
  220. return cy.daysWide
  221. }
  222. // Decimal returns the decimal point of number
  223. func (cy *cy_GB) Decimal() string {
  224. return cy.decimal
  225. }
  226. // Group returns the group of number
  227. func (cy *cy_GB) Group() string {
  228. return cy.group
  229. }
  230. // Group returns the minus sign of number
  231. func (cy *cy_GB) Minus() string {
  232. return cy.minus
  233. }
  234. // FmtNumber returns 'num' with digits/precision of 'v' for 'cy_GB' and handles both Whole and Real numbers based on 'v'
  235. func (cy *cy_GB) FmtNumber(num float64, v uint64) string {
  236. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  237. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  238. count := 0
  239. inWhole := v == 0
  240. b := make([]byte, 0, l)
  241. for i := len(s) - 1; i >= 0; i-- {
  242. if s[i] == '.' {
  243. b = append(b, cy.decimal[0])
  244. inWhole = true
  245. continue
  246. }
  247. if inWhole {
  248. if count == 3 {
  249. b = append(b, cy.group[0])
  250. count = 1
  251. } else {
  252. count++
  253. }
  254. }
  255. b = append(b, s[i])
  256. }
  257. if num < 0 {
  258. b = append(b, cy.minus[0])
  259. }
  260. // reverse
  261. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  262. b[i], b[j] = b[j], b[i]
  263. }
  264. return string(b)
  265. }
  266. // FmtPercent returns 'num' with digits/precision of 'v' for 'cy_GB' and handles both Whole and Real numbers based on 'v'
  267. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  268. func (cy *cy_GB) FmtPercent(num float64, v uint64) string {
  269. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  270. l := len(s) + 3
  271. b := make([]byte, 0, l)
  272. for i := len(s) - 1; i >= 0; i-- {
  273. if s[i] == '.' {
  274. b = append(b, cy.decimal[0])
  275. continue
  276. }
  277. b = append(b, s[i])
  278. }
  279. if num < 0 {
  280. b = append(b, cy.minus[0])
  281. }
  282. // reverse
  283. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  284. b[i], b[j] = b[j], b[i]
  285. }
  286. b = append(b, cy.percent...)
  287. return string(b)
  288. }
  289. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'cy_GB'
  290. func (cy *cy_GB) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  291. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  292. symbol := cy.currencies[currency]
  293. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  294. count := 0
  295. inWhole := v == 0
  296. b := make([]byte, 0, l)
  297. for i := len(s) - 1; i >= 0; i-- {
  298. if s[i] == '.' {
  299. b = append(b, cy.decimal[0])
  300. inWhole = true
  301. continue
  302. }
  303. if inWhole {
  304. if count == 3 {
  305. b = append(b, cy.group[0])
  306. count = 1
  307. } else {
  308. count++
  309. }
  310. }
  311. b = append(b, s[i])
  312. }
  313. for j := len(symbol) - 1; j >= 0; j-- {
  314. b = append(b, symbol[j])
  315. }
  316. if num < 0 {
  317. b = append(b, cy.minus[0])
  318. }
  319. // reverse
  320. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  321. b[i], b[j] = b[j], b[i]
  322. }
  323. if int(v) < 2 {
  324. if v == 0 {
  325. b = append(b, cy.decimal...)
  326. }
  327. for i := 0; i < 2-int(v); i++ {
  328. b = append(b, '0')
  329. }
  330. }
  331. return string(b)
  332. }
  333. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'cy_GB'
  334. // in accounting notation.
  335. func (cy *cy_GB) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  336. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  337. symbol := cy.currencies[currency]
  338. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  339. count := 0
  340. inWhole := v == 0
  341. b := make([]byte, 0, l)
  342. for i := len(s) - 1; i >= 0; i-- {
  343. if s[i] == '.' {
  344. b = append(b, cy.decimal[0])
  345. inWhole = true
  346. continue
  347. }
  348. if inWhole {
  349. if count == 3 {
  350. b = append(b, cy.group[0])
  351. count = 1
  352. } else {
  353. count++
  354. }
  355. }
  356. b = append(b, s[i])
  357. }
  358. if num < 0 {
  359. for j := len(symbol) - 1; j >= 0; j-- {
  360. b = append(b, symbol[j])
  361. }
  362. b = append(b, cy.currencyNegativePrefix[0])
  363. } else {
  364. for j := len(symbol) - 1; j >= 0; j-- {
  365. b = append(b, symbol[j])
  366. }
  367. }
  368. // reverse
  369. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  370. b[i], b[j] = b[j], b[i]
  371. }
  372. if int(v) < 2 {
  373. if v == 0 {
  374. b = append(b, cy.decimal...)
  375. }
  376. for i := 0; i < 2-int(v); i++ {
  377. b = append(b, '0')
  378. }
  379. }
  380. if num < 0 {
  381. b = append(b, cy.currencyNegativeSuffix...)
  382. }
  383. return string(b)
  384. }
  385. // FmtDateShort returns the short date representation of 't' for 'cy_GB'
  386. func (cy *cy_GB) FmtDateShort(t time.Time) string {
  387. b := make([]byte, 0, 32)
  388. if t.Day() < 10 {
  389. b = append(b, '0')
  390. }
  391. b = strconv.AppendInt(b, int64(t.Day()), 10)
  392. b = append(b, []byte{0x2f}...)
  393. if t.Month() < 10 {
  394. b = append(b, '0')
  395. }
  396. b = strconv.AppendInt(b, int64(t.Month()), 10)
  397. b = append(b, []byte{0x2f}...)
  398. if t.Year() > 9 {
  399. b = append(b, strconv.Itoa(t.Year())[2:]...)
  400. } else {
  401. b = append(b, strconv.Itoa(t.Year())[1:]...)
  402. }
  403. return string(b)
  404. }
  405. // FmtDateMedium returns the medium date representation of 't' for 'cy_GB'
  406. func (cy *cy_GB) FmtDateMedium(t time.Time) string {
  407. b := make([]byte, 0, 32)
  408. b = strconv.AppendInt(b, int64(t.Day()), 10)
  409. b = append(b, []byte{0x20}...)
  410. b = append(b, cy.monthsAbbreviated[t.Month()]...)
  411. b = append(b, []byte{0x20}...)
  412. if t.Year() > 0 {
  413. b = strconv.AppendInt(b, int64(t.Year()), 10)
  414. } else {
  415. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  416. }
  417. return string(b)
  418. }
  419. // FmtDateLong returns the long date representation of 't' for 'cy_GB'
  420. func (cy *cy_GB) FmtDateLong(t time.Time) string {
  421. b := make([]byte, 0, 32)
  422. b = strconv.AppendInt(b, int64(t.Day()), 10)
  423. b = append(b, []byte{0x20}...)
  424. b = append(b, cy.monthsWide[t.Month()]...)
  425. b = append(b, []byte{0x20}...)
  426. if t.Year() > 0 {
  427. b = strconv.AppendInt(b, int64(t.Year()), 10)
  428. } else {
  429. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  430. }
  431. return string(b)
  432. }
  433. // FmtDateFull returns the full date representation of 't' for 'cy_GB'
  434. func (cy *cy_GB) FmtDateFull(t time.Time) string {
  435. b := make([]byte, 0, 32)
  436. b = append(b, cy.daysWide[t.Weekday()]...)
  437. b = append(b, []byte{0x2c, 0x20}...)
  438. b = strconv.AppendInt(b, int64(t.Day()), 10)
  439. b = append(b, []byte{0x20}...)
  440. b = append(b, cy.monthsWide[t.Month()]...)
  441. b = append(b, []byte{0x20}...)
  442. if t.Year() > 0 {
  443. b = strconv.AppendInt(b, int64(t.Year()), 10)
  444. } else {
  445. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  446. }
  447. return string(b)
  448. }
  449. // FmtTimeShort returns the short time representation of 't' for 'cy_GB'
  450. func (cy *cy_GB) FmtTimeShort(t time.Time) string {
  451. b := make([]byte, 0, 32)
  452. if t.Hour() < 10 {
  453. b = append(b, '0')
  454. }
  455. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  456. b = append(b, cy.timeSeparator...)
  457. if t.Minute() < 10 {
  458. b = append(b, '0')
  459. }
  460. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  461. return string(b)
  462. }
  463. // FmtTimeMedium returns the medium time representation of 't' for 'cy_GB'
  464. func (cy *cy_GB) FmtTimeMedium(t time.Time) string {
  465. b := make([]byte, 0, 32)
  466. if t.Hour() < 10 {
  467. b = append(b, '0')
  468. }
  469. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  470. b = append(b, cy.timeSeparator...)
  471. if t.Minute() < 10 {
  472. b = append(b, '0')
  473. }
  474. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  475. b = append(b, cy.timeSeparator...)
  476. if t.Second() < 10 {
  477. b = append(b, '0')
  478. }
  479. b = strconv.AppendInt(b, int64(t.Second()), 10)
  480. return string(b)
  481. }
  482. // FmtTimeLong returns the long time representation of 't' for 'cy_GB'
  483. func (cy *cy_GB) FmtTimeLong(t time.Time) string {
  484. b := make([]byte, 0, 32)
  485. if t.Hour() < 10 {
  486. b = append(b, '0')
  487. }
  488. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  489. b = append(b, cy.timeSeparator...)
  490. if t.Minute() < 10 {
  491. b = append(b, '0')
  492. }
  493. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  494. b = append(b, cy.timeSeparator...)
  495. if t.Second() < 10 {
  496. b = append(b, '0')
  497. }
  498. b = strconv.AppendInt(b, int64(t.Second()), 10)
  499. b = append(b, []byte{0x20}...)
  500. tz, _ := t.Zone()
  501. b = append(b, tz...)
  502. return string(b)
  503. }
  504. // FmtTimeFull returns the full time representation of 't' for 'cy_GB'
  505. func (cy *cy_GB) FmtTimeFull(t time.Time) string {
  506. b := make([]byte, 0, 32)
  507. if t.Hour() < 10 {
  508. b = append(b, '0')
  509. }
  510. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  511. b = append(b, cy.timeSeparator...)
  512. if t.Minute() < 10 {
  513. b = append(b, '0')
  514. }
  515. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  516. b = append(b, cy.timeSeparator...)
  517. if t.Second() < 10 {
  518. b = append(b, '0')
  519. }
  520. b = strconv.AppendInt(b, int64(t.Second()), 10)
  521. b = append(b, []byte{0x20}...)
  522. tz, _ := t.Zone()
  523. if btz, ok := cy.timezones[tz]; ok {
  524. b = append(b, btz...)
  525. } else {
  526. b = append(b, tz...)
  527. }
  528. return string(b)
  529. }