ar_SA.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. package ar_SA
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ar_SA 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 'ar_SA' locale
  42. func New() locales.Translator {
  43. return &ar_SA{
  44. locale: "ar_SA",
  45. pluralsCardinal: []locales.PluralRule{1, 2, 3, 4, 5, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: []locales.PluralRule{1, 4, 5, 6},
  48. decimal: "٫",
  49. group: "٬",
  50. minus: "؜-",
  51. percent: "٪",
  52. perMille: "؉",
  53. timeSeparator: ":",
  54. inifinity: "∞",
  55. currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "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"},
  56. percentSuffix: " ",
  57. currencyPositiveSuffix: " ",
  58. currencyNegativeSuffix: " ",
  59. monthsAbbreviated: []string{"", "يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"},
  60. monthsNarrow: []string{"", "ي", "ف", "م", "أ", "و", "ن", "ل", "غ", "س", "ك", "ب", "د"},
  61. monthsWide: []string{"", "يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"},
  62. daysAbbreviated: []string{"الأحد", "الاثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت"},
  63. daysNarrow: []string{"ح", "ن", "ث", "ر", "خ", "ج", "س"},
  64. daysShort: []string{"أحد", "إثنين", "ثلاثاء", "أربعاء", "خميس", "جمعة", "سبت"},
  65. daysWide: []string{"الأحد", "الاثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت"},
  66. periodsAbbreviated: []string{"", ""},
  67. periodsNarrow: []string{"ص", "م"},
  68. periodsWide: []string{"ص", "م"},
  69. erasAbbreviated: []string{"ق.م", "م"},
  70. erasNarrow: []string{"", ""},
  71. erasWide: []string{"قبل الميلاد", "ميلادي"},
  72. timezones: map[string]string{"CHAST": "توقيت تشاتام الرسمي", "HAT": "توقيت نيوفاوندلاند الصيفي", "HEPM": "توقيت سانت بيير وميكولون الصيفي", "COT": "توقيت كولومبيا الرسمي", "SRT": "توقيت سورينام", "HNPMX": "توقيت المحيط الهادي الرسمي للمكسيك", "AST": "التوقيت الرسمي الأطلسي", "NZST": "توقيت نيوزيلندا الرسمي", "HNEG": "توقيت شرق غرينلاند الرسمي", "HEEG": "توقيت شرق غرينلاند الصيفي", "LHDT": "التوقيت الصيفي للورد هاو", "HNPM": "توقيت سانت بيير وميكولون الرسمي", "ChST": "توقيت تشامورو", "AWDT": "توقيت غرب أستراليا الصيفي", "WAST": "توقيت غرب أفريقيا الصيفي", "HEOG": "توقيت غرب غرينلاند الصيفي", "MESZ": "توقيت وسط أوروبا الصيفي", "CAT": "توقيت وسط أفريقيا", "CLT": "توقيت شيلي الرسمي", "WARST": "توقيت غرب الأرجنتين الصيفي", "CDT": "التوقيت الصيفي المركزي لأمريكا الشمالية", "AWST": "توقيت غرب أستراليا الرسمي", "MDT": "التوقيت الجبلي الصيفي لأمريكا الشمالية", "WESZ": "توقيت غرب أوروبا الصيفي", "BOT": "توقيت بوليفيا", "ACDT": "توقيت وسط أستراليا الصيفي", "IST": "توقيت الهند", "EST": "التوقيت الرسمي الشرقي لأمريكا الشمالية", "ACWST": "توقيت غرب وسط أستراليا الرسمي", "HKST": "توقيت هونغ كونغ الصيفي", "WAT": "توقيت غرب أفريقيا الرسمي", "ECT": "توقيت الإكوادور", "GMT": "توقيت غرينتش", "∅∅∅": "توقيت برازيليا الصيفي", "HEPMX": "توقيت المحيط الهادي الصيفي للمكسيك", "MST": "التوقيت الجبلي الرسمي لأمريكا الشمالية", "JST": "توقيت اليابان الرسمي", "TMT": "توقيت تركمانستان الرسمي", "AEST": "توقيت شرق أستراليا الرسمي", "HKT": "توقيت هونغ كونغ الرسمي", "VET": "توقيت فنزويلا", "HADT": "توقيت هاواي ألوتيان الصيفي", "UYT": "توقيت أوروغواي الرسمي", "WIB": "توقيت غرب إندونيسيا", "LHST": "توقيت لورد هاو الرسمي", "HNT": "توقيت نيوفاوندلاند الرسمي", "CLST": "توقيت شيلي الصيفي", "ART": "توقيت الأرجنتين الرسمي", "ADT": "التوقيت الصيفي الأطلسي", "SAST": "توقيت جنوب أفريقيا", "NZDT": "توقيت نيوزيلندا الصيفي", "GFT": "توقيت غايانا الفرنسية", "AKST": "التوقيت الرسمي لألاسكا", "WIT": "توقيت شرق إندونيسيا", "TMST": "توقيت تركمانستان الصيفي", "EDT": "التوقيت الصيفي الشرقي لأمريكا الشمالية", "ACWDT": "توقيت غرب وسط أستراليا الصيفي", "ARST": "توقيت الأرجنتين الصيفي", "UYST": "توقيت أوروغواي الصيفي", "BT": "توقيت بوتان", "JDT": "توقيت اليابان الصيفي", "MEZ": "توقيت وسط أوروبا الرسمي", "WART": "توقيت غرب الأرجنتين الرسمي", "HNNOMX": "التوقيت الرسمي لشمال غرب المكسيك", "OEZ": "توقيت شرق أوروبا الرسمي", "COST": "توقيت كولومبيا الصيفي", "HENOMX": "التوقيت الصيفي لشمال غرب المكسيك", "OESZ": "توقيت شرق أوروبا الصيفي", "WEZ": "توقيت غرب أوروبا الرسمي", "AKDT": "توقيت ألاسكا الصيفي", "EAT": "توقيت شرق أفريقيا", "HAST": "توقيت هاواي ألوتيان الرسمي", "HECU": "توقيت كوبا الصيفي", "CST": "التوقيت الرسمي المركزي لأمريكا الشمالية", "AEDT": "توقيت شرق أستراليا الصيفي", "MYT": "توقيت ماليزيا", "WITA": "توقيت وسط إندونيسيا", "GYT": "توقيت غيانا", "CHADT": "توقيت تشاتام الصيفي", "HNCU": "توقيت كوبا الرسمي", "PST": "توقيت المحيط الهادي الرسمي", "PDT": "توقيت المحيط الهادي الصيفي", "SGT": "توقيت سنغافورة", "ACST": "توقيت وسط أستراليا الرسمي", "HNOG": "توقيت غرب غرينلاند الرسمي"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (ar *ar_SA) Locale() string {
  77. return ar.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'ar_SA'
  80. func (ar *ar_SA) PluralsCardinal() []locales.PluralRule {
  81. return ar.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ar_SA'
  84. func (ar *ar_SA) PluralsOrdinal() []locales.PluralRule {
  85. return ar.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'ar_SA'
  88. func (ar *ar_SA) PluralsRange() []locales.PluralRule {
  89. return ar.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ar_SA'
  92. func (ar *ar_SA) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. nMod100 := math.Mod(n, 100)
  95. if n == 0 {
  96. return locales.PluralRuleZero
  97. } else if n == 1 {
  98. return locales.PluralRuleOne
  99. } else if n == 2 {
  100. return locales.PluralRuleTwo
  101. } else if nMod100 >= 3 && nMod100 <= 10 {
  102. return locales.PluralRuleFew
  103. } else if nMod100 >= 11 && nMod100 <= 99 {
  104. return locales.PluralRuleMany
  105. }
  106. return locales.PluralRuleOther
  107. }
  108. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ar_SA'
  109. func (ar *ar_SA) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  110. return locales.PluralRuleOther
  111. }
  112. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ar_SA'
  113. func (ar *ar_SA) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  114. start := ar.CardinalPluralRule(num1, v1)
  115. end := ar.CardinalPluralRule(num2, v2)
  116. if start == locales.PluralRuleZero && end == locales.PluralRuleOne {
  117. return locales.PluralRuleZero
  118. } else if start == locales.PluralRuleZero && end == locales.PluralRuleTwo {
  119. return locales.PluralRuleZero
  120. } else if start == locales.PluralRuleZero && end == locales.PluralRuleFew {
  121. return locales.PluralRuleFew
  122. } else if start == locales.PluralRuleZero && end == locales.PluralRuleMany {
  123. return locales.PluralRuleMany
  124. } else if start == locales.PluralRuleZero && end == locales.PluralRuleOther {
  125. return locales.PluralRuleOther
  126. } else if start == locales.PluralRuleOne && end == locales.PluralRuleTwo {
  127. return locales.PluralRuleOther
  128. } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
  129. return locales.PluralRuleFew
  130. } else if start == locales.PluralRuleOne && end == locales.PluralRuleMany {
  131. return locales.PluralRuleMany
  132. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  133. return locales.PluralRuleOther
  134. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleFew {
  135. return locales.PluralRuleFew
  136. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleMany {
  137. return locales.PluralRuleMany
  138. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleOther {
  139. return locales.PluralRuleOther
  140. } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew {
  141. return locales.PluralRuleFew
  142. } else if start == locales.PluralRuleFew && end == locales.PluralRuleMany {
  143. return locales.PluralRuleMany
  144. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
  145. return locales.PluralRuleOther
  146. } else if start == locales.PluralRuleMany && end == locales.PluralRuleFew {
  147. return locales.PluralRuleFew
  148. } else if start == locales.PluralRuleMany && end == locales.PluralRuleMany {
  149. return locales.PluralRuleMany
  150. } else if start == locales.PluralRuleMany && end == locales.PluralRuleOther {
  151. return locales.PluralRuleOther
  152. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  153. return locales.PluralRuleOther
  154. } else if start == locales.PluralRuleOther && end == locales.PluralRuleTwo {
  155. return locales.PluralRuleOther
  156. } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew {
  157. return locales.PluralRuleFew
  158. } else if start == locales.PluralRuleOther && end == locales.PluralRuleMany {
  159. return locales.PluralRuleMany
  160. }
  161. return locales.PluralRuleOther
  162. }
  163. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  164. func (ar *ar_SA) MonthAbbreviated(month time.Month) string {
  165. return ar.monthsAbbreviated[month]
  166. }
  167. // MonthsAbbreviated returns the locales abbreviated months
  168. func (ar *ar_SA) MonthsAbbreviated() []string {
  169. return ar.monthsAbbreviated[1:]
  170. }
  171. // MonthNarrow returns the locales narrow month given the 'month' provided
  172. func (ar *ar_SA) MonthNarrow(month time.Month) string {
  173. return ar.monthsNarrow[month]
  174. }
  175. // MonthsNarrow returns the locales narrow months
  176. func (ar *ar_SA) MonthsNarrow() []string {
  177. return ar.monthsNarrow[1:]
  178. }
  179. // MonthWide returns the locales wide month given the 'month' provided
  180. func (ar *ar_SA) MonthWide(month time.Month) string {
  181. return ar.monthsWide[month]
  182. }
  183. // MonthsWide returns the locales wide months
  184. func (ar *ar_SA) MonthsWide() []string {
  185. return ar.monthsWide[1:]
  186. }
  187. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  188. func (ar *ar_SA) WeekdayAbbreviated(weekday time.Weekday) string {
  189. return ar.daysAbbreviated[weekday]
  190. }
  191. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  192. func (ar *ar_SA) WeekdaysAbbreviated() []string {
  193. return ar.daysAbbreviated
  194. }
  195. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  196. func (ar *ar_SA) WeekdayNarrow(weekday time.Weekday) string {
  197. return ar.daysNarrow[weekday]
  198. }
  199. // WeekdaysNarrow returns the locales narrow weekdays
  200. func (ar *ar_SA) WeekdaysNarrow() []string {
  201. return ar.daysNarrow
  202. }
  203. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  204. func (ar *ar_SA) WeekdayShort(weekday time.Weekday) string {
  205. return ar.daysShort[weekday]
  206. }
  207. // WeekdaysShort returns the locales short weekdays
  208. func (ar *ar_SA) WeekdaysShort() []string {
  209. return ar.daysShort
  210. }
  211. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  212. func (ar *ar_SA) WeekdayWide(weekday time.Weekday) string {
  213. return ar.daysWide[weekday]
  214. }
  215. // WeekdaysWide returns the locales wide weekdays
  216. func (ar *ar_SA) WeekdaysWide() []string {
  217. return ar.daysWide
  218. }
  219. // Decimal returns the decimal point of number
  220. func (ar *ar_SA) Decimal() string {
  221. return ar.decimal
  222. }
  223. // Group returns the group of number
  224. func (ar *ar_SA) Group() string {
  225. return ar.group
  226. }
  227. // Group returns the minus sign of number
  228. func (ar *ar_SA) Minus() string {
  229. return ar.minus
  230. }
  231. // FmtNumber returns 'num' with digits/precision of 'v' for 'ar_SA' and handles both Whole and Real numbers based on 'v'
  232. func (ar *ar_SA) FmtNumber(num float64, v uint64) string {
  233. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  234. l := len(s) + 5 + 2*len(s[:len(s)-int(v)-1])/3
  235. count := 0
  236. inWhole := v == 0
  237. b := make([]byte, 0, l)
  238. for i := len(s) - 1; i >= 0; i-- {
  239. if s[i] == '.' {
  240. for j := len(ar.decimal) - 1; j >= 0; j-- {
  241. b = append(b, ar.decimal[j])
  242. }
  243. inWhole = true
  244. continue
  245. }
  246. if inWhole {
  247. if count == 3 {
  248. for j := len(ar.group) - 1; j >= 0; j-- {
  249. b = append(b, ar.group[j])
  250. }
  251. count = 1
  252. } else {
  253. count++
  254. }
  255. }
  256. b = append(b, s[i])
  257. }
  258. if num < 0 {
  259. for j := len(ar.minus) - 1; j >= 0; j-- {
  260. b = append(b, ar.minus[j])
  261. }
  262. }
  263. // reverse
  264. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  265. b[i], b[j] = b[j], b[i]
  266. }
  267. return string(b)
  268. }
  269. // FmtPercent returns 'num' with digits/precision of 'v' for 'ar_SA' and handles both Whole and Real numbers based on 'v'
  270. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  271. func (ar *ar_SA) FmtPercent(num float64, v uint64) string {
  272. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  273. l := len(s) + 9
  274. b := make([]byte, 0, l)
  275. for i := len(s) - 1; i >= 0; i-- {
  276. if s[i] == '.' {
  277. for j := len(ar.decimal) - 1; j >= 0; j-- {
  278. b = append(b, ar.decimal[j])
  279. }
  280. continue
  281. }
  282. b = append(b, s[i])
  283. }
  284. if num < 0 {
  285. for j := len(ar.minus) - 1; j >= 0; j-- {
  286. b = append(b, ar.minus[j])
  287. }
  288. }
  289. // reverse
  290. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  291. b[i], b[j] = b[j], b[i]
  292. }
  293. b = append(b, ar.percentSuffix...)
  294. b = append(b, ar.percent...)
  295. return string(b)
  296. }
  297. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ar_SA'
  298. func (ar *ar_SA) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  299. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  300. symbol := ar.currencies[currency]
  301. l := len(s) + len(symbol) + 7 + 2*len(s[:len(s)-int(v)-1])/3
  302. count := 0
  303. inWhole := v == 0
  304. b := make([]byte, 0, l)
  305. for i := len(s) - 1; i >= 0; i-- {
  306. if s[i] == '.' {
  307. for j := len(ar.decimal) - 1; j >= 0; j-- {
  308. b = append(b, ar.decimal[j])
  309. }
  310. inWhole = true
  311. continue
  312. }
  313. if inWhole {
  314. if count == 3 {
  315. for j := len(ar.group) - 1; j >= 0; j-- {
  316. b = append(b, ar.group[j])
  317. }
  318. count = 1
  319. } else {
  320. count++
  321. }
  322. }
  323. b = append(b, s[i])
  324. }
  325. if num < 0 {
  326. for j := len(ar.minus) - 1; j >= 0; j-- {
  327. b = append(b, ar.minus[j])
  328. }
  329. }
  330. // reverse
  331. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  332. b[i], b[j] = b[j], b[i]
  333. }
  334. if int(v) < 2 {
  335. if v == 0 {
  336. b = append(b, ar.decimal...)
  337. }
  338. for i := 0; i < 2-int(v); i++ {
  339. b = append(b, '0')
  340. }
  341. }
  342. b = append(b, ar.currencyPositiveSuffix...)
  343. b = append(b, symbol...)
  344. return string(b)
  345. }
  346. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ar_SA'
  347. // in accounting notation.
  348. func (ar *ar_SA) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  349. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  350. symbol := ar.currencies[currency]
  351. l := len(s) + len(symbol) + 7 + 2*len(s[:len(s)-int(v)-1])/3
  352. count := 0
  353. inWhole := v == 0
  354. b := make([]byte, 0, l)
  355. for i := len(s) - 1; i >= 0; i-- {
  356. if s[i] == '.' {
  357. for j := len(ar.decimal) - 1; j >= 0; j-- {
  358. b = append(b, ar.decimal[j])
  359. }
  360. inWhole = true
  361. continue
  362. }
  363. if inWhole {
  364. if count == 3 {
  365. for j := len(ar.group) - 1; j >= 0; j-- {
  366. b = append(b, ar.group[j])
  367. }
  368. count = 1
  369. } else {
  370. count++
  371. }
  372. }
  373. b = append(b, s[i])
  374. }
  375. if num < 0 {
  376. for j := len(ar.minus) - 1; j >= 0; j-- {
  377. b = append(b, ar.minus[j])
  378. }
  379. }
  380. // reverse
  381. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  382. b[i], b[j] = b[j], b[i]
  383. }
  384. if int(v) < 2 {
  385. if v == 0 {
  386. b = append(b, ar.decimal...)
  387. }
  388. for i := 0; i < 2-int(v); i++ {
  389. b = append(b, '0')
  390. }
  391. }
  392. if num < 0 {
  393. b = append(b, ar.currencyNegativeSuffix...)
  394. b = append(b, symbol...)
  395. } else {
  396. b = append(b, ar.currencyPositiveSuffix...)
  397. b = append(b, symbol...)
  398. }
  399. return string(b)
  400. }
  401. // FmtDateShort returns the short date representation of 't' for 'ar_SA'
  402. func (ar *ar_SA) FmtDateShort(t time.Time) string {
  403. b := make([]byte, 0, 32)
  404. b = strconv.AppendInt(b, int64(t.Day()), 10)
  405. b = append(b, []byte{0xe2, 0x80, 0x8f, 0x2f}...)
  406. b = strconv.AppendInt(b, int64(t.Month()), 10)
  407. b = append(b, []byte{0xe2, 0x80, 0x8f, 0x2f}...)
  408. if t.Year() > 0 {
  409. b = strconv.AppendInt(b, int64(t.Year()), 10)
  410. } else {
  411. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  412. }
  413. return string(b)
  414. }
  415. // FmtDateMedium returns the medium date representation of 't' for 'ar_SA'
  416. func (ar *ar_SA) FmtDateMedium(t time.Time) string {
  417. b := make([]byte, 0, 32)
  418. if t.Day() < 10 {
  419. b = append(b, '0')
  420. }
  421. b = strconv.AppendInt(b, int64(t.Day()), 10)
  422. b = append(b, []byte{0xe2, 0x80, 0x8f, 0x2f}...)
  423. if t.Month() < 10 {
  424. b = append(b, '0')
  425. }
  426. b = strconv.AppendInt(b, int64(t.Month()), 10)
  427. b = append(b, []byte{0xe2, 0x80, 0x8f, 0x2f}...)
  428. if t.Year() > 0 {
  429. b = strconv.AppendInt(b, int64(t.Year()), 10)
  430. } else {
  431. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  432. }
  433. return string(b)
  434. }
  435. // FmtDateLong returns the long date representation of 't' for 'ar_SA'
  436. func (ar *ar_SA) FmtDateLong(t time.Time) string {
  437. b := make([]byte, 0, 32)
  438. b = strconv.AppendInt(b, int64(t.Day()), 10)
  439. b = append(b, []byte{0x20}...)
  440. b = append(b, ar.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. // FmtDateFull returns the full date representation of 't' for 'ar_SA'
  450. func (ar *ar_SA) FmtDateFull(t time.Time) string {
  451. b := make([]byte, 0, 32)
  452. b = append(b, ar.daysWide[t.Weekday()]...)
  453. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  454. b = strconv.AppendInt(b, int64(t.Day()), 10)
  455. b = append(b, []byte{0x20}...)
  456. b = append(b, ar.monthsWide[t.Month()]...)
  457. b = append(b, []byte{0x20}...)
  458. if t.Year() > 0 {
  459. b = strconv.AppendInt(b, int64(t.Year()), 10)
  460. } else {
  461. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  462. }
  463. return string(b)
  464. }
  465. // FmtTimeShort returns the short time representation of 't' for 'ar_SA'
  466. func (ar *ar_SA) FmtTimeShort(t time.Time) string {
  467. b := make([]byte, 0, 32)
  468. h := t.Hour()
  469. if h > 12 {
  470. h -= 12
  471. }
  472. b = strconv.AppendInt(b, int64(h), 10)
  473. b = append(b, ar.timeSeparator...)
  474. if t.Minute() < 10 {
  475. b = append(b, '0')
  476. }
  477. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  478. b = append(b, []byte{0x20}...)
  479. if t.Hour() < 12 {
  480. b = append(b, ar.periodsAbbreviated[0]...)
  481. } else {
  482. b = append(b, ar.periodsAbbreviated[1]...)
  483. }
  484. return string(b)
  485. }
  486. // FmtTimeMedium returns the medium time representation of 't' for 'ar_SA'
  487. func (ar *ar_SA) FmtTimeMedium(t time.Time) string {
  488. b := make([]byte, 0, 32)
  489. h := t.Hour()
  490. if h > 12 {
  491. h -= 12
  492. }
  493. b = strconv.AppendInt(b, int64(h), 10)
  494. b = append(b, ar.timeSeparator...)
  495. if t.Minute() < 10 {
  496. b = append(b, '0')
  497. }
  498. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  499. b = append(b, ar.timeSeparator...)
  500. if t.Second() < 10 {
  501. b = append(b, '0')
  502. }
  503. b = strconv.AppendInt(b, int64(t.Second()), 10)
  504. b = append(b, []byte{0x20}...)
  505. if t.Hour() < 12 {
  506. b = append(b, ar.periodsAbbreviated[0]...)
  507. } else {
  508. b = append(b, ar.periodsAbbreviated[1]...)
  509. }
  510. return string(b)
  511. }
  512. // FmtTimeLong returns the long time representation of 't' for 'ar_SA'
  513. func (ar *ar_SA) FmtTimeLong(t time.Time) string {
  514. b := make([]byte, 0, 32)
  515. h := t.Hour()
  516. if h > 12 {
  517. h -= 12
  518. }
  519. b = strconv.AppendInt(b, int64(h), 10)
  520. b = append(b, ar.timeSeparator...)
  521. if t.Minute() < 10 {
  522. b = append(b, '0')
  523. }
  524. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  525. b = append(b, ar.timeSeparator...)
  526. if t.Second() < 10 {
  527. b = append(b, '0')
  528. }
  529. b = strconv.AppendInt(b, int64(t.Second()), 10)
  530. b = append(b, []byte{0x20}...)
  531. if t.Hour() < 12 {
  532. b = append(b, ar.periodsAbbreviated[0]...)
  533. } else {
  534. b = append(b, ar.periodsAbbreviated[1]...)
  535. }
  536. b = append(b, []byte{0x20}...)
  537. tz, _ := t.Zone()
  538. b = append(b, tz...)
  539. return string(b)
  540. }
  541. // FmtTimeFull returns the full time representation of 't' for 'ar_SA'
  542. func (ar *ar_SA) FmtTimeFull(t time.Time) string {
  543. b := make([]byte, 0, 32)
  544. h := t.Hour()
  545. if h > 12 {
  546. h -= 12
  547. }
  548. b = strconv.AppendInt(b, int64(h), 10)
  549. b = append(b, ar.timeSeparator...)
  550. if t.Minute() < 10 {
  551. b = append(b, '0')
  552. }
  553. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  554. b = append(b, ar.timeSeparator...)
  555. if t.Second() < 10 {
  556. b = append(b, '0')
  557. }
  558. b = strconv.AppendInt(b, int64(t.Second()), 10)
  559. b = append(b, []byte{0x20}...)
  560. if t.Hour() < 12 {
  561. b = append(b, ar.periodsAbbreviated[0]...)
  562. } else {
  563. b = append(b, ar.periodsAbbreviated[1]...)
  564. }
  565. b = append(b, []byte{0x20}...)
  566. tz, _ := t.Zone()
  567. if btz, ok := ar.timezones[tz]; ok {
  568. b = append(b, btz...)
  569. } else {
  570. b = append(b, tz...)
  571. }
  572. return string(b)
  573. }