uk.go 24 KB

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