ks.go 21 KB

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