ka.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. package ka
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ka 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 'ka' locale
  42. func New() locales.Translator {
  43. return &ka{
  44. locale: "ka",
  45. pluralsCardinal: []locales.PluralRule{2, 6},
  46. pluralsOrdinal: []locales.PluralRule{2, 5, 6},
  47. pluralsRange: []locales.PluralRule{2, 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 ", "R$", "BRN ", "BRR ", "BRZ ", "BSD", "BTN", "BUK ", "BWP", "BYB ", "BYR", "BZD", "CA$", "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", "€", "FIM ", "FJD", "FKP", "FRF ", "£", "GEK ", "₾", "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", "MX$", "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", "NT$", "TZS", "UAH", "UAK ", "UGS ", "UGX", "US$", "USN ", "USS ", "UYI ", "UYP ", "UYU", "UZS", "VEB ", "VEF", "VND", "VNN ", "VUV", "WST", "FCFA", "XAG ", "XAU ", "XBA ", "XBB ", "XBC ", "XBD ", "EC$", "XDR ", "XEU ", "XFO ", "XFU ", "CFA", "XPD ", "CFPF", "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{"AM", "PM"},
  67. periodsNarrow: []string{"a", "p"},
  68. periodsWide: []string{"AM", "PM"},
  69. erasAbbreviated: []string{"ძვ. წ.", "ახ. წ."},
  70. erasNarrow: []string{"", ""},
  71. erasWide: []string{"ძველი წელთაღრიცხვით", "ახალი წელთაღრიცხვით"},
  72. timezones: map[string]string{"NZST": "ახალი ზელანდიის სტანდარტული დრო", "WARST": "დასავლეთ არგენტინის ზაფხულის დრო", "ARST": "არგენტინის ზაფხულის დრო", "EAT": "აღმოსავლეთ აფრიკის დრო", "SRT": "სურინამის დრო", "PST": "ჩრდილოეთ ამერიკის წყნარი ოკეანის სტანდარტული დრო", "ART": "არგენტინის სტანდარტული დრო", "AWDT": "დასავლეთ ავსტრალიის ზაფხულის დრო", "MYT": "მალაიზიის დრო", "HAT": "ნიუფაუნდლენდის ზაფხულის დრო", "TMST": "თურქმენეთის ზაფხულის დრო", "CAT": "ცენტრალური აფრიკის დრო", "WITA": "ცენტრალური ინდონეზიის დრო", "CHADT": "ჩატემის ზაფხულის დრო", "BT": "ბუტანის დრო", "WIB": "დასავლეთ ინდონეზიის დრო", "MST": "MST", "AWST": "დასავლეთ ავსტრალიის სტანდარტული დრო", "NZDT": "ახალი ზელანდიის ზაფხულის დრო", "CDT": "ჩრდილოეთ ამერიკის ცენტრალური ზაფხულის დრო", "AKST": "ალასკას სტანდარტული დრო", "AEDT": "აღმოსავლეთ ავსტრალიის ზაფხულის დრო", "ChST": "ჩამოროს დრო", "CHAST": "ჩატემის სტანდარტული დრო", "GMT": "გრინვიჩის საშუალო დრო", "ACDT": "ავსტრალიის ცენტრალური ზაფხულის დრო", "GYT": "გაიანის დრო", "UYST": "ურუგვაის ზაფხულის დრო", "MESZ": "ცენტრალური ევროპის ზაფხულის დრო", "CLST": "ჩილეს ზაფხულის დრო", "ACWST": "ცენტრალური და დასავლეთ ავსტრალიის სტანდარტული დრო", "SGT": "სინგაპურის დრო", "WIT": "აღმოსავლეთ ინდონეზიის დრო", "∅∅∅": "ამაზონიის ზაფხულის დრო", "TMT": "თურქმენეთის სტანდარტული დრო", "LHDT": "ლორდ-ჰაუს ზაფხულის დრო", "BOT": "ბოლივიის დრო", "ACWDT": "ცენტრალური და დასავლეთ ავსტრალიის ზაფხულის დრო", "EST": "ჩრდილოეთ ამერიკის აღმოსავლეთის სტანდარტული დრო", "HADT": "ჰავაის და ალეუტის ზაფხულის დრო", "ACST": "ავსტრალიის ცენტრალური სტანდარტული დრო", "MDT": "MDT", "JDT": "იაპონიის ზაფხულის დრო", "MEZ": "ცენტრალური ევროპის სტანდარტული დრო", "WAT": "დასავლეთ აფრიკის სტანდარტული დრო", "HNT": "ნიუფაუნდლენდის სტანდარტული დრო", "SAST": "სამხრეთ აფრიკის დრო", "JST": "იაპონიის სტანდარტული დრო", "CLT": "ჩილეს სტანდარტული დრო", "WESZ": "დასავლეთ ევროპის ზაფხულის დრო", "ECT": "ეკვადორის დრო", "HAST": "ჰავაის და ალეუტის სტანდარტული დრო", "WART": "დასავლეთ არგენტინის სტანდარტული დრო", "PDT": "ჩრდილოეთ ამერიკის წყნარი ოკეანის ზაფხულის დრო", "UYT": "ურუგვაის სტანდარტული დრო", "WEZ": "დასავლეთ ევროპის სტანდარტული დრო", "EDT": "ჩრდილოეთ ამერიკის აღმოსავლეთის ზაფხულის დრო", "WAST": "დასავლეთ აფრიკის ზაფხულის დრო", "GFT": "საფრანგეთის გვიანის დრო", "OESZ": "აღმოსავლეთ ევროპის ზაფხულის დრო", "LHST": "ლორდ-ჰაუს სტანდარტული დრო", "COST": "კოლუმბიის ზაფხულის დრო", "AST": "ატლანტიკის ოკეანის სტანდარტული დრო", "HKST": "ჰონკონგის ზაფხულის დრო", "OEZ": "აღმოსავლეთ ევროპის სტანდარტული დრო", "CST": "ჩრდილოეთ ამერიკის ცენტრალური სტანდარტული დრო", "AEST": "აღმოსავლეთ ავსტრალიის სტანდარტული დრო", "VET": "ვენესუელის დრო", "COT": "კოლუმბიის სტანდარტული დრო", "AKDT": "ალასკას ზაფხულის დრო", "ADT": "ატლანტიკის ოკეანის ზაფხულის დრო", "HKT": "ჰონკონგის სტანდარტული დრო", "IST": "ინდოეთის დრო"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (ka *ka) Locale() string {
  77. return ka.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'ka'
  80. func (ka *ka) PluralsCardinal() []locales.PluralRule {
  81. return ka.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ka'
  84. func (ka *ka) PluralsOrdinal() []locales.PluralRule {
  85. return ka.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'ka'
  88. func (ka *ka) PluralsRange() []locales.PluralRule {
  89. return ka.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ka'
  92. func (ka *ka) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. if n == 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 'ka'
  100. func (ka *ka) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  101. n := math.Abs(num)
  102. i := int64(n)
  103. iMod100 := i % 100
  104. if i == 1 {
  105. return locales.PluralRuleOne
  106. } else if (i == 0) || (iMod100 >= 2 && iMod100 <= 20 && (iMod100 == 40 || iMod100 == 60 || iMod100 == 80)) {
  107. return locales.PluralRuleMany
  108. }
  109. return locales.PluralRuleOther
  110. }
  111. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ka'
  112. func (ka *ka) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  113. start := ka.CardinalPluralRule(num1, v1)
  114. end := ka.CardinalPluralRule(num2, v2)
  115. if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  116. return locales.PluralRuleOne
  117. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  118. return locales.PluralRuleOther
  119. }
  120. return locales.PluralRuleOther
  121. }
  122. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  123. func (ka *ka) MonthAbbreviated(month time.Month) string {
  124. return ka.monthsAbbreviated[month]
  125. }
  126. // MonthsAbbreviated returns the locales abbreviated months
  127. func (ka *ka) MonthsAbbreviated() []string {
  128. return ka.monthsAbbreviated[1:]
  129. }
  130. // MonthNarrow returns the locales narrow month given the 'month' provided
  131. func (ka *ka) MonthNarrow(month time.Month) string {
  132. return ka.monthsNarrow[month]
  133. }
  134. // MonthsNarrow returns the locales narrow months
  135. func (ka *ka) MonthsNarrow() []string {
  136. return ka.monthsNarrow[1:]
  137. }
  138. // MonthWide returns the locales wide month given the 'month' provided
  139. func (ka *ka) MonthWide(month time.Month) string {
  140. return ka.monthsWide[month]
  141. }
  142. // MonthsWide returns the locales wide months
  143. func (ka *ka) MonthsWide() []string {
  144. return ka.monthsWide[1:]
  145. }
  146. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  147. func (ka *ka) WeekdayAbbreviated(weekday time.Weekday) string {
  148. return ka.daysAbbreviated[weekday]
  149. }
  150. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  151. func (ka *ka) WeekdaysAbbreviated() []string {
  152. return ka.daysAbbreviated
  153. }
  154. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  155. func (ka *ka) WeekdayNarrow(weekday time.Weekday) string {
  156. return ka.daysNarrow[weekday]
  157. }
  158. // WeekdaysNarrow returns the locales narrow weekdays
  159. func (ka *ka) WeekdaysNarrow() []string {
  160. return ka.daysNarrow
  161. }
  162. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  163. func (ka *ka) WeekdayShort(weekday time.Weekday) string {
  164. return ka.daysShort[weekday]
  165. }
  166. // WeekdaysShort returns the locales short weekdays
  167. func (ka *ka) WeekdaysShort() []string {
  168. return ka.daysShort
  169. }
  170. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  171. func (ka *ka) WeekdayWide(weekday time.Weekday) string {
  172. return ka.daysWide[weekday]
  173. }
  174. // WeekdaysWide returns the locales wide weekdays
  175. func (ka *ka) WeekdaysWide() []string {
  176. return ka.daysWide
  177. }
  178. // FmtNumber returns 'num' with digits/precision of 'v' for 'ka' and handles both Whole and Real numbers based on 'v'
  179. func (ka *ka) FmtNumber(num float64, v uint64) string {
  180. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  181. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  182. count := 0
  183. inWhole := v == 0
  184. b := make([]byte, 0, l)
  185. for i := len(s) - 1; i >= 0; i-- {
  186. if s[i] == '.' {
  187. b = append(b, ka.decimal[0])
  188. inWhole = true
  189. continue
  190. }
  191. if inWhole {
  192. if count == 3 {
  193. for j := len(ka.group) - 1; j >= 0; j-- {
  194. b = append(b, ka.group[j])
  195. }
  196. count = 1
  197. } else {
  198. count++
  199. }
  200. }
  201. b = append(b, s[i])
  202. }
  203. if num < 0 {
  204. b = append(b, ka.minus[0])
  205. }
  206. // reverse
  207. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  208. b[i], b[j] = b[j], b[i]
  209. }
  210. return string(b)
  211. }
  212. // FmtPercent returns 'num' with digits/precision of 'v' for 'ka' and handles both Whole and Real numbers based on 'v'
  213. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  214. func (ka *ka) FmtPercent(num float64, v uint64) string {
  215. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  216. l := len(s) + 5
  217. b := make([]byte, 0, l)
  218. for i := len(s) - 1; i >= 0; i-- {
  219. if s[i] == '.' {
  220. b = append(b, ka.decimal[0])
  221. continue
  222. }
  223. b = append(b, s[i])
  224. }
  225. if num < 0 {
  226. b = append(b, ka.minus[0])
  227. }
  228. // reverse
  229. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  230. b[i], b[j] = b[j], b[i]
  231. }
  232. b = append(b, ka.percentSuffix...)
  233. b = append(b, ka.percent...)
  234. return string(b)
  235. }
  236. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ka'
  237. func (ka *ka) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  238. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  239. symbol := ka.currencies[currency]
  240. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  241. count := 0
  242. inWhole := v == 0
  243. b := make([]byte, 0, l)
  244. for i := len(s) - 1; i >= 0; i-- {
  245. if s[i] == '.' {
  246. b = append(b, ka.decimal[0])
  247. inWhole = true
  248. continue
  249. }
  250. if inWhole {
  251. if count == 3 {
  252. for j := len(ka.group) - 1; j >= 0; j-- {
  253. b = append(b, ka.group[j])
  254. }
  255. count = 1
  256. } else {
  257. count++
  258. }
  259. }
  260. b = append(b, s[i])
  261. }
  262. if num < 0 {
  263. b = append(b, ka.minus[0])
  264. }
  265. // reverse
  266. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  267. b[i], b[j] = b[j], b[i]
  268. }
  269. if int(v) < 2 {
  270. if v == 0 {
  271. b = append(b, ka.decimal...)
  272. }
  273. for i := 0; i < 2-int(v); i++ {
  274. b = append(b, '0')
  275. }
  276. }
  277. b = append(b, ka.currencyPositiveSuffix...)
  278. b = append(b, symbol...)
  279. return string(b)
  280. }
  281. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ka'
  282. // in accounting notation.
  283. func (ka *ka) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  284. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  285. symbol := ka.currencies[currency]
  286. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  287. count := 0
  288. inWhole := v == 0
  289. b := make([]byte, 0, l)
  290. for i := len(s) - 1; i >= 0; i-- {
  291. if s[i] == '.' {
  292. b = append(b, ka.decimal[0])
  293. inWhole = true
  294. continue
  295. }
  296. if inWhole {
  297. if count == 3 {
  298. for j := len(ka.group) - 1; j >= 0; j-- {
  299. b = append(b, ka.group[j])
  300. }
  301. count = 1
  302. } else {
  303. count++
  304. }
  305. }
  306. b = append(b, s[i])
  307. }
  308. if num < 0 {
  309. b = append(b, ka.minus[0])
  310. }
  311. // reverse
  312. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  313. b[i], b[j] = b[j], b[i]
  314. }
  315. if int(v) < 2 {
  316. if v == 0 {
  317. b = append(b, ka.decimal...)
  318. }
  319. for i := 0; i < 2-int(v); i++ {
  320. b = append(b, '0')
  321. }
  322. }
  323. if num < 0 {
  324. b = append(b, ka.currencyNegativeSuffix...)
  325. b = append(b, symbol...)
  326. } else {
  327. b = append(b, ka.currencyPositiveSuffix...)
  328. b = append(b, symbol...)
  329. }
  330. return string(b)
  331. }
  332. // FmtDateShort returns the short date representation of 't' for 'ka'
  333. func (ka *ka) FmtDateShort(t time.Time) string {
  334. b := make([]byte, 0, 32)
  335. if t.Day() < 10 {
  336. b = append(b, '0')
  337. }
  338. b = strconv.AppendInt(b, int64(t.Day()), 10)
  339. b = append(b, []byte{0x2e}...)
  340. if t.Month() < 10 {
  341. b = append(b, '0')
  342. }
  343. b = strconv.AppendInt(b, int64(t.Month()), 10)
  344. b = append(b, []byte{0x2e}...)
  345. if t.Year() > 9 {
  346. b = append(b, strconv.Itoa(t.Year())[2:]...)
  347. } else {
  348. b = append(b, strconv.Itoa(t.Year())[1:]...)
  349. }
  350. return string(b)
  351. }
  352. // FmtDateMedium returns the medium date representation of 't' for 'ka'
  353. func (ka *ka) FmtDateMedium(t time.Time) string {
  354. b := make([]byte, 0, 32)
  355. b = strconv.AppendInt(b, int64(t.Day()), 10)
  356. b = append(b, []byte{0x20}...)
  357. b = append(b, ka.monthsAbbreviated[t.Month()]...)
  358. b = append(b, []byte{0x2e, 0x20}...)
  359. b = strconv.AppendInt(b, int64(t.Year()), 10)
  360. return string(b)
  361. }
  362. // FmtDateLong returns the long date representation of 't' for 'ka'
  363. func (ka *ka) FmtDateLong(t time.Time) string {
  364. b := make([]byte, 0, 32)
  365. b = strconv.AppendInt(b, int64(t.Day()), 10)
  366. b = append(b, []byte{0x20}...)
  367. b = append(b, ka.monthsWide[t.Month()]...)
  368. b = append(b, []byte{0x2c, 0x20}...)
  369. b = strconv.AppendInt(b, int64(t.Year()), 10)
  370. return string(b)
  371. }
  372. // FmtDateFull returns the full date representation of 't' for 'ka'
  373. func (ka *ka) FmtDateFull(t time.Time) string {
  374. b := make([]byte, 0, 32)
  375. b = append(b, ka.daysWide[t.Weekday()]...)
  376. b = append(b, []byte{0x2c, 0x20}...)
  377. if t.Day() < 10 {
  378. b = append(b, '0')
  379. }
  380. b = strconv.AppendInt(b, int64(t.Day()), 10)
  381. b = append(b, []byte{0x20}...)
  382. b = append(b, ka.monthsWide[t.Month()]...)
  383. b = append(b, []byte{0x2c, 0x20}...)
  384. b = strconv.AppendInt(b, int64(t.Year()), 10)
  385. return string(b)
  386. }
  387. // FmtTimeShort returns the short time representation of 't' for 'ka'
  388. func (ka *ka) FmtTimeShort(t time.Time) string {
  389. b := make([]byte, 0, 32)
  390. if t.Hour() < 10 {
  391. b = append(b, '0')
  392. }
  393. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  394. b = append(b, ka.timeSeparator...)
  395. if t.Minute() < 10 {
  396. b = append(b, '0')
  397. }
  398. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  399. return string(b)
  400. }
  401. // FmtTimeMedium returns the medium time representation of 't' for 'ka'
  402. func (ka *ka) FmtTimeMedium(t time.Time) string {
  403. b := make([]byte, 0, 32)
  404. if t.Hour() < 10 {
  405. b = append(b, '0')
  406. }
  407. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  408. b = append(b, ka.timeSeparator...)
  409. if t.Minute() < 10 {
  410. b = append(b, '0')
  411. }
  412. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  413. b = append(b, ka.timeSeparator...)
  414. if t.Second() < 10 {
  415. b = append(b, '0')
  416. }
  417. b = strconv.AppendInt(b, int64(t.Second()), 10)
  418. return string(b)
  419. }
  420. // FmtTimeLong returns the long time representation of 't' for 'ka'
  421. func (ka *ka) FmtTimeLong(t time.Time) string {
  422. b := make([]byte, 0, 32)
  423. if t.Hour() < 10 {
  424. b = append(b, '0')
  425. }
  426. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  427. b = append(b, ka.timeSeparator...)
  428. if t.Minute() < 10 {
  429. b = append(b, '0')
  430. }
  431. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  432. b = append(b, ka.timeSeparator...)
  433. if t.Second() < 10 {
  434. b = append(b, '0')
  435. }
  436. b = strconv.AppendInt(b, int64(t.Second()), 10)
  437. b = append(b, []byte{0x20}...)
  438. tz, _ := t.Zone()
  439. b = append(b, tz...)
  440. return string(b)
  441. }
  442. // FmtTimeFull returns the full time representation of 't' for 'ka'
  443. func (ka *ka) FmtTimeFull(t time.Time) string {
  444. b := make([]byte, 0, 32)
  445. if t.Hour() < 10 {
  446. b = append(b, '0')
  447. }
  448. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  449. b = append(b, ka.timeSeparator...)
  450. if t.Minute() < 10 {
  451. b = append(b, '0')
  452. }
  453. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  454. b = append(b, ka.timeSeparator...)
  455. if t.Second() < 10 {
  456. b = append(b, '0')
  457. }
  458. b = strconv.AppendInt(b, int64(t.Second()), 10)
  459. b = append(b, []byte{0x20}...)
  460. tz, _ := t.Zone()
  461. if btz, ok := ka.timezones[tz]; ok {
  462. b = append(b, btz...)
  463. } else {
  464. b = append(b, tz...)
  465. }
  466. return string(b)
  467. }