si_LK.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. package si_LK
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type si_LK 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 'si_LK' locale
  41. func New() locales.Translator {
  42. return &si_LK{
  43. locale: "si_LK",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: []locales.PluralRule{6},
  46. pluralsRange: []locales.PluralRule{2, 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{"", "ජන", "පෙබ", "මාර්තු", "අප්\u200dරේල්", "මැයි", "ජූනි", "ජූලි", "අගෝ", "සැප්", "ඔක්", "නොවැ", "දෙසැ"},
  58. monthsNarrow: []string{"", "ජ", "පෙ", "මා", "අ", "මැ", "ජූ", "ජූ", "අ", "සැ", "ඔ", "නෙ", "දෙ"},
  59. monthsWide: []string{"", "ජනවාරි", "පෙබරවාරි", "මාර්තු", "අප්\u200dරේල්", "මැයි", "ජූනි", "ජූලි", "අගෝස්තු", "සැප්තැම්බර්", "ඔක්තෝබර්", "නොවැම්බර්", "දෙසැම්බර්"},
  60. daysAbbreviated: []string{"ඉරිදා", "සඳුදා", "අඟහ", "බදාදා", "බ්\u200dරහස්", "සිකු", "සෙන"},
  61. daysNarrow: []string{"ඉ", "ස", "අ", "බ", "බ්\u200dර", "සි", "සෙ"},
  62. daysShort: []string{"ඉරි", "සඳු", "අඟ", "බදා", "බ්\u200dරහ", "සිකු", "සෙන"},
  63. daysWide: []string{"ඉරිදා", "සඳුදා", "අඟහරුවාදා", "බදාදා", "බ්\u200dරහස්පතින්දා", "සිකුරාදා", "සෙනසුරාදා"},
  64. periodsAbbreviated: []string{"පෙ.ව.", "ප.ව."},
  65. periodsNarrow: []string{"පෙ", "ප"},
  66. periodsWide: []string{"පෙ.ව.", "ප.ව."},
  67. erasAbbreviated: []string{"ක්\u200dරි.පූ.", "ක්\u200dරි.ව."},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"ක්\u200dරිස්තු පූර්ව", "ක්\u200dරිස්තු වර්ෂ"},
  70. timezones: map[string]string{"WAT": "බටහිර අප්\u200dරිකානු සම්මත වේලාව", "OEZ": "නැගෙනහිර යුරෝපීය සම්මත වේලාව", "AKDT": "ඇලස්කා දිවාආලෝක වේලාව", "HAT": "නිව්ෆවුන්ලන්ත දිවාආලෝක වේලාව", "COST": "කොලොම්බියා ග්\u200dරීෂ්ම කාලය", "GMT": "ග්\u200dරිනිච් මධ්\u200dයම වේලාව", "PST": "උතුරු ඇමරිකානු පැසිෆික් සම්මත වේලාව", "WEZ": "බටහිර යුරෝපීය සම්මත වේලාව", "WART": "බටහිර ආර්ජන්ටිනා සම්මත වේලාව", "WITA": "මධ්\u200dයම ඉන්දුනීසියානු වේලාව", "CST": "උතුරු ඇමරිකානු මධ්\u200dයම සම්මත වේලාව", "GFT": "ප්\u200dරංශ ගයනා වේලාව", "ACWST": "මධ්\u200dයම බටහිර ඔස්ට්\u200dරේලියානු සම්මත වේලාව", "LHDT": "ලෝර්ඩ් හෝව් දිවා වේලාව", "AEDT": "නැඟෙනහිර ඕස්ට්\u200dරේලියානු දහවල් වේලාව", "EST": "උතුරු ඇමරිකානු නැගෙනහිර සම්මත වේලාව", "CLT": "චිලී සම්මත වේලාව", "CLST": "චිලී ග්\u200dරීෂ්ම කාලය", "OESZ": "නැගෙනහිර යුරෝපීය ග්\u200dරීෂ්ම වේලාව", "ART": "ආර්ජන්ටිනා සම්මත වේලාව", "UYT": "උරුගුවේ සම්මත වේලාව", "AWST": "බටහිර ඕස්ට්\u200dරේලියානු සම්මත වේලාව", "MESZ": "මධ්\u200dයම යුරෝපීය ග්\u200dරීෂ්ම වේලාව", "HKST": "හොංකොං ග්\u200dරීෂ්ම වේලාව", "MDT": "උතුරු ඇමරිකානු කඳුකර දිවාආලෝක වේලාව", "WAST": "බටහිර අප්\u200dරිකානු ග්\u200dරීෂ්ම කාලය", "WIB": "බටහිර ඉන්දුනීසියානු වේලාව", "HEEG": "නැගෙනහිර ග්\u200dරීන්ලන්ත ග්\u200dරීෂ්ම කාලය", "TMST": "ටර්ක්මෙනිස්තාන ග්\u200dරීෂ්ම වේලාව", "ECT": "ඉක්වදෝර් වේලාව", "EDT": "උතුරු ඇමරිකානු නැගෙනහිර දිවාආලෝක වේලාව", "ACDT": "මධ්\u200dයම ඔස්ට්\u200dරේලියානු දහවල් වේලාව", "HNPM": "ශාන්ත පියරේ සහ මැකෝලන් සම්මත වේලාව", "HAST": "හවායි-අලෙයුතියාන් සම්මත වේලාව", "HNCU": "කියුබානු සම්මත වේලාව", "HECU": "කියුබානු දිවාආලෝක වේලාව", "PDT": "උතුරු ඇමරිකානු පැසිෆික් දිවාආලෝක වේලාව", "HNT": "නිව්ෆවුන්ලන්ත සම්මත වේලාව", "VET": "වෙනිසියුලා වේලාව", "JDT": "ජපාන දහවල් වේලාව", "IST": "ඉන්දියානු වේලාව", "∅∅∅": "ඇමර්සන් ග්\u200dරීෂ්ම කාලය", "CDT": "උතුරු ඇමරිකානු මධ්\u200dයම දිවාආලෝක වේලාව", "HNPMX": "මෙක්සිකෝ පැසිෆික් සම්මත වේලාව", "HEPMX": "මෙක්සිකෝ පැසිෆික් දිවාආලෝක වේලාව", "NZDT": "නවසීලන්ත දිවා වේලාව", "JST": "ජපාන සම්මත වේලාව", "HEPM": "ශාන්ත පියරේ සහ මැකෝලන් දිවාආලෝක වේලාව", "SRT": "සුරිනාම වේලාව", "ACWDT": "මධ්\u200dයම බටහිර ඔස්ට්\u200dරේලියානු දහවල් වේලාව", "HEOG": "බටහිර ග්\u200dරීන්ලන්ත ග්\u200dරීෂ්ම කාලය", "TMT": "ටර්ක්මෙනිස්තාන සම්මත වේලාව", "ARST": "ආර්ජන්ටිනා ග්\u200dරීෂ්ම කාලය", "GYT": "ගයනා වේලාව", "ChST": "චමොරෝ වේලාව", "AST": "අත්ලාන්තික් සම්මත වේලාව", "AKST": "ඇලස්කා සම්මත වේලාව", "MEZ": "මධ්\u200dයම යුරෝපීය සම්මත වේලාව", "LHST": "ලෝර්ඩ් හෝව් සම්මත වේලාව", "HADT": "හවායි-අලෙයුතියාන් දිවාආලෝක වේලාව", "WESZ": "බටහිර යුරෝපීය ග්\u200dරීෂ්ම වේලාව", "BOT": "බොලිවියා වේලාව", "HENOMX": "වයඹ මෙක්සිකෝ දිවාආලෝක වේලාව", "MST": "උතුරු ඇමරිකානු කඳුකර සම්මත වේලාව", "BT": "භුතාන වේලාව", "NZST": "නවසීලන්ත සම්මත වේලාව", "HNOG": "බටහිර ග්\u200dරීන්ලන්ත සම්මත වේලාව", "HNNOMX": "වයඹ මෙක්සිකෝ සම්මත වේලාව", "HNEG": "නැගෙනහිර ග්\u200dරීන්ලන්ත සම්මත වේලාව", "CAT": "මධ්\u200dයම අප්\u200dරිකානු වේලාව", "WIT": "නැගෙනහිර ඉන්දුනීසියානු වේලාව", "COT": "කොලොම්බියා සම්මත වේලාව", "UYST": "උරුගුවේ ග්\u200dරීෂ්ම කාලය", "CHADT": "චැතම් දිවා වේලාව", "ACST": "ඕස්ට්\u200dරේලියානු සම්මත වේලාව", "ADT": "අත්ලාන්තික් දිවාආලෝක වේලාව", "AEST": "නැගෙනහිර ඕස්ට්\u200dරේලියානු සම්මත වේලාව", "HKT": "හොංකොං සම්මත වේලාව", "EAT": "නැගෙනහිර අප්\u200dරිකානු වේලාව", "CHAST": "චැතම් සම්මත වේලාව", "AWDT": "බටහිර ඔස්ට්\u200dරේලියානු දහවල් වේලාව", "SGT": "සිංගප්පුරු වේලාව", "WARST": "බටහිර ආර්ජන්ටිනා ග්\u200dරීෂ්ම කාලය", "SAST": "දකුණු අප්\u200dරිකානු වේලාව", "MYT": "මැලේසියානු වේලාව"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (si *si_LK) Locale() string {
  75. return si.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'si_LK'
  78. func (si *si_LK) PluralsCardinal() []locales.PluralRule {
  79. return si.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'si_LK'
  82. func (si *si_LK) PluralsOrdinal() []locales.PluralRule {
  83. return si.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'si_LK'
  86. func (si *si_LK) PluralsRange() []locales.PluralRule {
  87. return si.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'si_LK'
  90. func (si *si_LK) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. f := locales.F(n, v)
  94. if (n == 0 || n == 1) || (i == 0 && f == 1) {
  95. return locales.PluralRuleOne
  96. }
  97. return locales.PluralRuleOther
  98. }
  99. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'si_LK'
  100. func (si *si_LK) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  101. return locales.PluralRuleOther
  102. }
  103. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'si_LK'
  104. func (si *si_LK) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  105. start := si.CardinalPluralRule(num1, v1)
  106. end := si.CardinalPluralRule(num2, v2)
  107. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  108. return locales.PluralRuleOne
  109. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  110. return locales.PluralRuleOther
  111. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  112. return locales.PluralRuleOther
  113. }
  114. return locales.PluralRuleOther
  115. }
  116. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  117. func (si *si_LK) MonthAbbreviated(month time.Month) string {
  118. return si.monthsAbbreviated[month]
  119. }
  120. // MonthsAbbreviated returns the locales abbreviated months
  121. func (si *si_LK) MonthsAbbreviated() []string {
  122. return si.monthsAbbreviated[1:]
  123. }
  124. // MonthNarrow returns the locales narrow month given the 'month' provided
  125. func (si *si_LK) MonthNarrow(month time.Month) string {
  126. return si.monthsNarrow[month]
  127. }
  128. // MonthsNarrow returns the locales narrow months
  129. func (si *si_LK) MonthsNarrow() []string {
  130. return si.monthsNarrow[1:]
  131. }
  132. // MonthWide returns the locales wide month given the 'month' provided
  133. func (si *si_LK) MonthWide(month time.Month) string {
  134. return si.monthsWide[month]
  135. }
  136. // MonthsWide returns the locales wide months
  137. func (si *si_LK) MonthsWide() []string {
  138. return si.monthsWide[1:]
  139. }
  140. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  141. func (si *si_LK) WeekdayAbbreviated(weekday time.Weekday) string {
  142. return si.daysAbbreviated[weekday]
  143. }
  144. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  145. func (si *si_LK) WeekdaysAbbreviated() []string {
  146. return si.daysAbbreviated
  147. }
  148. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  149. func (si *si_LK) WeekdayNarrow(weekday time.Weekday) string {
  150. return si.daysNarrow[weekday]
  151. }
  152. // WeekdaysNarrow returns the locales narrow weekdays
  153. func (si *si_LK) WeekdaysNarrow() []string {
  154. return si.daysNarrow
  155. }
  156. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  157. func (si *si_LK) WeekdayShort(weekday time.Weekday) string {
  158. return si.daysShort[weekday]
  159. }
  160. // WeekdaysShort returns the locales short weekdays
  161. func (si *si_LK) WeekdaysShort() []string {
  162. return si.daysShort
  163. }
  164. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  165. func (si *si_LK) WeekdayWide(weekday time.Weekday) string {
  166. return si.daysWide[weekday]
  167. }
  168. // WeekdaysWide returns the locales wide weekdays
  169. func (si *si_LK) WeekdaysWide() []string {
  170. return si.daysWide
  171. }
  172. // Decimal returns the decimal point of number
  173. func (si *si_LK) Decimal() string {
  174. return si.decimal
  175. }
  176. // Group returns the group of number
  177. func (si *si_LK) Group() string {
  178. return si.group
  179. }
  180. // Group returns the minus sign of number
  181. func (si *si_LK) Minus() string {
  182. return si.minus
  183. }
  184. // FmtNumber returns 'num' with digits/precision of 'v' for 'si_LK' and handles both Whole and Real numbers based on 'v'
  185. func (si *si_LK) FmtNumber(num float64, v uint64) string {
  186. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  187. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  188. count := 0
  189. inWhole := v == 0
  190. b := make([]byte, 0, l)
  191. for i := len(s) - 1; i >= 0; i-- {
  192. if s[i] == '.' {
  193. b = append(b, si.decimal[0])
  194. inWhole = true
  195. continue
  196. }
  197. if inWhole {
  198. if count == 3 {
  199. b = append(b, si.group[0])
  200. count = 1
  201. } else {
  202. count++
  203. }
  204. }
  205. b = append(b, s[i])
  206. }
  207. if num < 0 {
  208. b = append(b, si.minus[0])
  209. }
  210. // reverse
  211. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  212. b[i], b[j] = b[j], b[i]
  213. }
  214. return string(b)
  215. }
  216. // FmtPercent returns 'num' with digits/precision of 'v' for 'si_LK' and handles both Whole and Real numbers based on 'v'
  217. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  218. func (si *si_LK) FmtPercent(num float64, v uint64) string {
  219. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  220. l := len(s) + 3
  221. b := make([]byte, 0, l)
  222. for i := len(s) - 1; i >= 0; i-- {
  223. if s[i] == '.' {
  224. b = append(b, si.decimal[0])
  225. continue
  226. }
  227. b = append(b, s[i])
  228. }
  229. if num < 0 {
  230. b = append(b, si.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, si.percent...)
  237. return string(b)
  238. }
  239. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'si_LK'
  240. func (si *si_LK) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  241. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  242. symbol := si.currencies[currency]
  243. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  244. count := 0
  245. inWhole := v == 0
  246. b := make([]byte, 0, l)
  247. for i := len(s) - 1; i >= 0; i-- {
  248. if s[i] == '.' {
  249. b = append(b, si.decimal[0])
  250. inWhole = true
  251. continue
  252. }
  253. if inWhole {
  254. if count == 3 {
  255. b = append(b, si.group[0])
  256. count = 1
  257. } else {
  258. count++
  259. }
  260. }
  261. b = append(b, s[i])
  262. }
  263. for j := len(symbol) - 1; j >= 0; j-- {
  264. b = append(b, symbol[j])
  265. }
  266. if num < 0 {
  267. b = append(b, si.minus[0])
  268. }
  269. // reverse
  270. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  271. b[i], b[j] = b[j], b[i]
  272. }
  273. if int(v) < 2 {
  274. if v == 0 {
  275. b = append(b, si.decimal...)
  276. }
  277. for i := 0; i < 2-int(v); i++ {
  278. b = append(b, '0')
  279. }
  280. }
  281. return string(b)
  282. }
  283. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'si_LK'
  284. // in accounting notation.
  285. func (si *si_LK) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  286. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  287. symbol := si.currencies[currency]
  288. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  289. count := 0
  290. inWhole := v == 0
  291. b := make([]byte, 0, l)
  292. for i := len(s) - 1; i >= 0; i-- {
  293. if s[i] == '.' {
  294. b = append(b, si.decimal[0])
  295. inWhole = true
  296. continue
  297. }
  298. if inWhole {
  299. if count == 3 {
  300. b = append(b, si.group[0])
  301. count = 1
  302. } else {
  303. count++
  304. }
  305. }
  306. b = append(b, s[i])
  307. }
  308. if num < 0 {
  309. for j := len(symbol) - 1; j >= 0; j-- {
  310. b = append(b, symbol[j])
  311. }
  312. b = append(b, si.currencyNegativePrefix[0])
  313. } else {
  314. for j := len(symbol) - 1; j >= 0; j-- {
  315. b = append(b, symbol[j])
  316. }
  317. }
  318. // reverse
  319. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  320. b[i], b[j] = b[j], b[i]
  321. }
  322. if int(v) < 2 {
  323. if v == 0 {
  324. b = append(b, si.decimal...)
  325. }
  326. for i := 0; i < 2-int(v); i++ {
  327. b = append(b, '0')
  328. }
  329. }
  330. if num < 0 {
  331. b = append(b, si.currencyNegativeSuffix...)
  332. }
  333. return string(b)
  334. }
  335. // FmtDateShort returns the short date representation of 't' for 'si_LK'
  336. func (si *si_LK) FmtDateShort(t time.Time) string {
  337. b := make([]byte, 0, 32)
  338. if t.Year() > 0 {
  339. b = strconv.AppendInt(b, int64(t.Year()), 10)
  340. } else {
  341. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  342. }
  343. b = append(b, []byte{0x2d}...)
  344. if t.Month() < 10 {
  345. b = append(b, '0')
  346. }
  347. b = strconv.AppendInt(b, int64(t.Month()), 10)
  348. b = append(b, []byte{0x2d}...)
  349. if t.Day() < 10 {
  350. b = append(b, '0')
  351. }
  352. b = strconv.AppendInt(b, int64(t.Day()), 10)
  353. return string(b)
  354. }
  355. // FmtDateMedium returns the medium date representation of 't' for 'si_LK'
  356. func (si *si_LK) FmtDateMedium(t time.Time) string {
  357. b := make([]byte, 0, 32)
  358. if t.Year() > 0 {
  359. b = strconv.AppendInt(b, int64(t.Year()), 10)
  360. } else {
  361. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  362. }
  363. b = append(b, []byte{0x20}...)
  364. b = append(b, si.monthsAbbreviated[t.Month()]...)
  365. b = append(b, []byte{0x20}...)
  366. b = strconv.AppendInt(b, int64(t.Day()), 10)
  367. return string(b)
  368. }
  369. // FmtDateLong returns the long date representation of 't' for 'si_LK'
  370. func (si *si_LK) FmtDateLong(t time.Time) string {
  371. b := make([]byte, 0, 32)
  372. if t.Year() > 0 {
  373. b = strconv.AppendInt(b, int64(t.Year()), 10)
  374. } else {
  375. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  376. }
  377. b = append(b, []byte{0x20}...)
  378. b = append(b, si.monthsWide[t.Month()]...)
  379. b = append(b, []byte{0x20}...)
  380. b = strconv.AppendInt(b, int64(t.Day()), 10)
  381. return string(b)
  382. }
  383. // FmtDateFull returns the full date representation of 't' for 'si_LK'
  384. func (si *si_LK) FmtDateFull(t time.Time) string {
  385. b := make([]byte, 0, 32)
  386. if t.Year() > 0 {
  387. b = strconv.AppendInt(b, int64(t.Year()), 10)
  388. } else {
  389. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  390. }
  391. b = append(b, []byte{0x20}...)
  392. b = append(b, si.monthsWide[t.Month()]...)
  393. b = append(b, []byte{0x20}...)
  394. b = strconv.AppendInt(b, int64(t.Day()), 10)
  395. b = append(b, []byte{0x2c, 0x20}...)
  396. b = append(b, si.daysWide[t.Weekday()]...)
  397. return string(b)
  398. }
  399. // FmtTimeShort returns the short time representation of 't' for 'si_LK'
  400. func (si *si_LK) FmtTimeShort(t time.Time) string {
  401. b := make([]byte, 0, 32)
  402. if t.Hour() < 10 {
  403. b = append(b, '0')
  404. }
  405. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  406. b = append(b, []byte{0x2e}...)
  407. if t.Minute() < 10 {
  408. b = append(b, '0')
  409. }
  410. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  411. return string(b)
  412. }
  413. // FmtTimeMedium returns the medium time representation of 't' for 'si_LK'
  414. func (si *si_LK) FmtTimeMedium(t time.Time) string {
  415. b := make([]byte, 0, 32)
  416. if t.Hour() < 10 {
  417. b = append(b, '0')
  418. }
  419. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  420. b = append(b, []byte{0x2e}...)
  421. if t.Minute() < 10 {
  422. b = append(b, '0')
  423. }
  424. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  425. b = append(b, []byte{0x2e}...)
  426. if t.Second() < 10 {
  427. b = append(b, '0')
  428. }
  429. b = strconv.AppendInt(b, int64(t.Second()), 10)
  430. return string(b)
  431. }
  432. // FmtTimeLong returns the long time representation of 't' for 'si_LK'
  433. func (si *si_LK) FmtTimeLong(t time.Time) string {
  434. b := make([]byte, 0, 32)
  435. if t.Hour() < 10 {
  436. b = append(b, '0')
  437. }
  438. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  439. b = append(b, []byte{0x2e}...)
  440. if t.Minute() < 10 {
  441. b = append(b, '0')
  442. }
  443. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  444. b = append(b, []byte{0x2e}...)
  445. if t.Second() < 10 {
  446. b = append(b, '0')
  447. }
  448. b = strconv.AppendInt(b, int64(t.Second()), 10)
  449. b = append(b, []byte{0x20}...)
  450. tz, _ := t.Zone()
  451. b = append(b, tz...)
  452. return string(b)
  453. }
  454. // FmtTimeFull returns the full time representation of 't' for 'si_LK'
  455. func (si *si_LK) FmtTimeFull(t time.Time) string {
  456. b := make([]byte, 0, 32)
  457. if t.Hour() < 10 {
  458. b = append(b, '0')
  459. }
  460. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  461. b = append(b, []byte{0x2e}...)
  462. if t.Minute() < 10 {
  463. b = append(b, '0')
  464. }
  465. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  466. b = append(b, []byte{0x2e}...)
  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. tz, _ := t.Zone()
  473. if btz, ok := si.timezones[tz]; ok {
  474. b = append(b, btz...)
  475. } else {
  476. b = append(b, tz...)
  477. }
  478. return string(b)
  479. }