sl.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. package sl
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type sl 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. currencyPositiveSuffix string
  23. currencyNegativePrefix 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 'sl' locale
  42. func New() locales.Translator {
  43. return &sl{
  44. locale: "sl",
  45. pluralsCardinal: []locales.PluralRule{2, 3, 4, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: []locales.PluralRule{4, 3, 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 ", "A$", "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", "CAD", "CDF", "CHE ", "CHF", "CHW ", "CLE ", "CLF ", "CLP", "CNX ", "CN¥", "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 ", "GEL", "GHC ", "GHS", "GIP", "GMD", "GNF", "GNS ", "GQE ", "GRD ", "GTQ", "GWE ", "GWP ", "GYD", "HK$", "HNL", "HRD ", "HRK", "HTG", "HUF", "IDR", "IEP ", "ILP ", "ILR ", "₪", "₹", "IQD", "IRR", "ISJ ", "ISK", "ITL ", "JMD", "JOD", "¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH ", "KRO ", "₩", "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", "NZ$", "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", "฿", "TJR ", "TJS", "TMM ", "TMT", "TND", "TOP", "TPE ", "TRL ", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK ", "UGS ", "UGX", "$", "USN ", "USS ", "UYI ", "UYP ", "UYU", "UZS", "VEB ", "VEF", "₫", "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. currencyPositiveSuffix: " ",
  57. currencyNegativePrefix: "(",
  58. currencyNegativeSuffix: " )",
  59. monthsAbbreviated: []string{"", "jan.", "feb.", "mar.", "apr.", "maj", "jun.", "jul.", "avg.", "sep.", "okt.", "nov.", "dec."},
  60. monthsNarrow: []string{"", "j", "f", "m", "a", "m", "j", "j", "a", "s", "o", "n", "d"},
  61. monthsWide: []string{"", "januar", "februar", "marec", "april", "maj", "junij", "julij", "avgust", "september", "oktober", "november", "december"},
  62. daysAbbreviated: []string{"ned.", "pon.", "tor.", "sre.", "čet.", "pet.", "sob."},
  63. daysNarrow: []string{"n", "p", "t", "s", "č", "p", "s"},
  64. daysShort: []string{"ned.", "pon.", "tor.", "sre.", "čet.", "pet.", "sob."},
  65. daysWide: []string{"nedelja", "ponedeljek", "torek", "sreda", "četrtek", "petek", "sobota"},
  66. periodsAbbreviated: []string{"dop.", "pop."},
  67. periodsNarrow: []string{"d", "p"},
  68. periodsWide: []string{"dop.", "pop."},
  69. erasAbbreviated: []string{"pr. Kr.", "po n. št."},
  70. erasNarrow: []string{"", ""},
  71. erasWide: []string{"pred Kristusom", "naše štetje"},
  72. timezones: map[string]string{"WAT": "Zahodnoafriški standardni čas", "ChST": "Čamorski standardni čas", "CLT": "Čilski standardni čas", "HADT": "Havajski aleutski poletni čas", "HNT": "Novofundlandski standardni čas", "CDT": "Centralni poletni čas", "MESZ": "Srednjeevropski poletni čas", "COT": "Kolumbijski standardni čas", "CAT": "Centralnoafriški čas", "HAST": "Havajski aleutski standardni čas", "HKST": "Hongkonški poletni čas", "GMT": "Greenwiški srednji čas", "TMT": "Turkmenistanski standardni čas", "AWST": "Avstralski zahodni standardni čas", "SRT": "Surinamski čas", "WEZ": "Zahodnoevropski standardni čas", "AKST": "Aljaški standardni čas", "ACWST": "Avstralski centralni zahodni standardni čas", "ACWDT": "Avstralski centralni zahodni poletni čas", "AEST": "Avstralski vzhodni standardni čas", "CHAST": "Čatamski standardni čas", "CHADT": "Čatamski poletni čas", "NZDT": "Novozelandski poletni čas", "ADT": "Atlantski poletni čas", "HAT": "Novofundlandski poletni čas", "GFT": "Čas: Francoska Gvajana", "ART": "Argentinski standardni čas", "LHST": "Standardni čas otoka Lord Howe", "BOT": "Bolivijski čas", "SAST": "Južnoafriški čas", "OESZ": "Vzhodnoevropski poletni čas", "VET": "Venezuelski čas", "GYT": "Gvajanski čas", "UYST": "Urugvajski poletni čas", "AST": "Atlantski standardni čas", "BT": "Butanski čas", "CLST": "Čilski poletni čas", "∅∅∅": "Amazonski poletni čas", "LHDT": "Poletni čas otoka Lord Howe", "JDT": "Japonski poletni čas", "EDT": "Vzhodni poletni čas", "MDT": "MDT", "ARST": "Argentinski poletni čas", "TMST": "Turkmenistanski poletni čas", "AWDT": "Avstralski zahodni poletni čas", "MEZ": "Srednjeevropski standardni čas", "SGT": "Singapurski standardni čas", "NZST": "Novozelandski standardni čas", "EST": "Vzhodni standardni čas", "HKT": "Hongkonški standardni čas", "IST": "Indijski standardni čas", "OEZ": "Vzhodnoevropski standardni čas", "WITA": "Indonezijski osrednji čas", "ACDT": "Avstralski centralni poletni čas", "CST": "Centralni standardni čas", "PST": "Pacifiški standardni čas", "UYT": "Urugvajski standardni čas", "WARST": "Argentinski zahodni poletni čas", "WIT": "Indonezijski vzhodni čas", "EAT": "Vzhodnoafriški čas", "MST": "MST", "ACST": "Avstralski centralni standardni čas", "AKDT": "Aljaški poletni čas", "AEDT": "Avstralski vzhodni poletni čas", "COST": "Kolumbijski poletni čas", "WAST": "Zahodnoafriški poletni čas", "WART": "Argentinski zahodni standardni čas", "PDT": "Pacifiški poletni čas", "WESZ": "Zahodnoevropski poletni čas", "ECT": "Ekvadorski čas", "WIB": "Indonezijski zahodni čas", "MYT": "Malezijski čas", "JST": "Japonski standardni čas"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (sl *sl) Locale() string {
  77. return sl.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'sl'
  80. func (sl *sl) PluralsCardinal() []locales.PluralRule {
  81. return sl.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'sl'
  84. func (sl *sl) PluralsOrdinal() []locales.PluralRule {
  85. return sl.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'sl'
  88. func (sl *sl) PluralsRange() []locales.PluralRule {
  89. return sl.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'sl'
  92. func (sl *sl) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. i := int64(n)
  95. iMod100 := i % 100
  96. if v == 0 && iMod100 == 1 {
  97. return locales.PluralRuleOne
  98. } else if v == 0 && iMod100 == 2 {
  99. return locales.PluralRuleTwo
  100. } else if (v == 0 && iMod100 >= 3 && iMod100 <= 4) || (v != 0) {
  101. return locales.PluralRuleFew
  102. }
  103. return locales.PluralRuleOther
  104. }
  105. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'sl'
  106. func (sl *sl) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  107. return locales.PluralRuleOther
  108. }
  109. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'sl'
  110. func (sl *sl) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  111. start := sl.CardinalPluralRule(num1, v1)
  112. end := sl.CardinalPluralRule(num2, v2)
  113. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  114. return locales.PluralRuleFew
  115. } else if start == locales.PluralRuleOne && end == locales.PluralRuleTwo {
  116. return locales.PluralRuleTwo
  117. } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
  118. return locales.PluralRuleFew
  119. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  120. return locales.PluralRuleOther
  121. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleOne {
  122. return locales.PluralRuleFew
  123. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleTwo {
  124. return locales.PluralRuleTwo
  125. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleFew {
  126. return locales.PluralRuleFew
  127. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleOther {
  128. return locales.PluralRuleOther
  129. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOne {
  130. return locales.PluralRuleFew
  131. } else if start == locales.PluralRuleFew && end == locales.PluralRuleTwo {
  132. return locales.PluralRuleTwo
  133. } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew {
  134. return locales.PluralRuleFew
  135. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
  136. return locales.PluralRuleOther
  137. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  138. return locales.PluralRuleFew
  139. } else if start == locales.PluralRuleOther && end == locales.PluralRuleTwo {
  140. return locales.PluralRuleTwo
  141. } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew {
  142. return locales.PluralRuleFew
  143. }
  144. return locales.PluralRuleOther
  145. }
  146. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  147. func (sl *sl) MonthAbbreviated(month time.Month) string {
  148. return sl.monthsAbbreviated[month]
  149. }
  150. // MonthsAbbreviated returns the locales abbreviated months
  151. func (sl *sl) MonthsAbbreviated() []string {
  152. return sl.monthsAbbreviated[1:]
  153. }
  154. // MonthNarrow returns the locales narrow month given the 'month' provided
  155. func (sl *sl) MonthNarrow(month time.Month) string {
  156. return sl.monthsNarrow[month]
  157. }
  158. // MonthsNarrow returns the locales narrow months
  159. func (sl *sl) MonthsNarrow() []string {
  160. return sl.monthsNarrow[1:]
  161. }
  162. // MonthWide returns the locales wide month given the 'month' provided
  163. func (sl *sl) MonthWide(month time.Month) string {
  164. return sl.monthsWide[month]
  165. }
  166. // MonthsWide returns the locales wide months
  167. func (sl *sl) MonthsWide() []string {
  168. return sl.monthsWide[1:]
  169. }
  170. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  171. func (sl *sl) WeekdayAbbreviated(weekday time.Weekday) string {
  172. return sl.daysAbbreviated[weekday]
  173. }
  174. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  175. func (sl *sl) WeekdaysAbbreviated() []string {
  176. return sl.daysAbbreviated
  177. }
  178. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  179. func (sl *sl) WeekdayNarrow(weekday time.Weekday) string {
  180. return sl.daysNarrow[weekday]
  181. }
  182. // WeekdaysNarrow returns the locales narrow weekdays
  183. func (sl *sl) WeekdaysNarrow() []string {
  184. return sl.daysNarrow
  185. }
  186. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  187. func (sl *sl) WeekdayShort(weekday time.Weekday) string {
  188. return sl.daysShort[weekday]
  189. }
  190. // WeekdaysShort returns the locales short weekdays
  191. func (sl *sl) WeekdaysShort() []string {
  192. return sl.daysShort
  193. }
  194. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  195. func (sl *sl) WeekdayWide(weekday time.Weekday) string {
  196. return sl.daysWide[weekday]
  197. }
  198. // WeekdaysWide returns the locales wide weekdays
  199. func (sl *sl) WeekdaysWide() []string {
  200. return sl.daysWide
  201. }
  202. // FmtNumber returns 'num' with digits/precision of 'v' for 'sl' and handles both Whole and Real numbers based on 'v'
  203. func (sl *sl) FmtNumber(num float64, v uint64) string {
  204. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  205. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  206. count := 0
  207. inWhole := v == 0
  208. b := make([]byte, 0, l)
  209. for i := len(s) - 1; i >= 0; i-- {
  210. if s[i] == '.' {
  211. b = append(b, sl.decimal[0])
  212. inWhole = true
  213. continue
  214. }
  215. if inWhole {
  216. if count == 3 {
  217. b = append(b, sl.group[0])
  218. count = 1
  219. } else {
  220. count++
  221. }
  222. }
  223. b = append(b, s[i])
  224. }
  225. if num < 0 {
  226. b = append(b, sl.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. return string(b)
  233. }
  234. // FmtPercent returns 'num' with digits/precision of 'v' for 'sl' and handles both Whole and Real numbers based on 'v'
  235. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  236. func (sl *sl) FmtPercent(num float64, v uint64) string {
  237. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  238. l := len(s) + 3
  239. b := make([]byte, 0, l)
  240. for i := len(s) - 1; i >= 0; i-- {
  241. if s[i] == '.' {
  242. b = append(b, sl.decimal[0])
  243. continue
  244. }
  245. b = append(b, s[i])
  246. }
  247. if num < 0 {
  248. b = append(b, sl.minus[0])
  249. }
  250. // reverse
  251. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  252. b[i], b[j] = b[j], b[i]
  253. }
  254. b = append(b, sl.percent...)
  255. return string(b)
  256. }
  257. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'sl'
  258. func (sl *sl) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  259. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  260. symbol := sl.currencies[currency]
  261. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  262. count := 0
  263. inWhole := v == 0
  264. b := make([]byte, 0, l)
  265. for i := len(s) - 1; i >= 0; i-- {
  266. if s[i] == '.' {
  267. b = append(b, sl.decimal[0])
  268. inWhole = true
  269. continue
  270. }
  271. if inWhole {
  272. if count == 3 {
  273. b = append(b, sl.group[0])
  274. count = 1
  275. } else {
  276. count++
  277. }
  278. }
  279. b = append(b, s[i])
  280. }
  281. if num < 0 {
  282. b = append(b, sl.minus[0])
  283. }
  284. // reverse
  285. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  286. b[i], b[j] = b[j], b[i]
  287. }
  288. if int(v) < 2 {
  289. if v == 0 {
  290. b = append(b, sl.decimal...)
  291. }
  292. for i := 0; i < 2-int(v); i++ {
  293. b = append(b, '0')
  294. }
  295. }
  296. b = append(b, sl.currencyPositiveSuffix...)
  297. b = append(b, symbol...)
  298. return string(b)
  299. }
  300. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'sl'
  301. // in accounting notation.
  302. func (sl *sl) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  303. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  304. symbol := sl.currencies[currency]
  305. l := len(s) + len(symbol) + 6 + 1*len(s[:len(s)-int(v)-1])/3
  306. count := 0
  307. inWhole := v == 0
  308. b := make([]byte, 0, l)
  309. for i := len(s) - 1; i >= 0; i-- {
  310. if s[i] == '.' {
  311. b = append(b, sl.decimal[0])
  312. inWhole = true
  313. continue
  314. }
  315. if inWhole {
  316. if count == 3 {
  317. b = append(b, sl.group[0])
  318. count = 1
  319. } else {
  320. count++
  321. }
  322. }
  323. b = append(b, s[i])
  324. }
  325. if num < 0 {
  326. b = append(b, sl.currencyNegativePrefix[0])
  327. }
  328. // reverse
  329. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  330. b[i], b[j] = b[j], b[i]
  331. }
  332. if int(v) < 2 {
  333. if v == 0 {
  334. b = append(b, sl.decimal...)
  335. }
  336. for i := 0; i < 2-int(v); i++ {
  337. b = append(b, '0')
  338. }
  339. }
  340. if num < 0 {
  341. b = append(b, sl.currencyNegativeSuffix...)
  342. b = append(b, symbol...)
  343. } else {
  344. b = append(b, sl.currencyPositiveSuffix...)
  345. b = append(b, symbol...)
  346. }
  347. return string(b)
  348. }
  349. // FmtDateShort returns the short date representation of 't' for 'sl'
  350. func (sl *sl) FmtDateShort(t time.Time) string {
  351. b := make([]byte, 0, 32)
  352. b = strconv.AppendInt(b, int64(t.Day()), 10)
  353. b = append(b, []byte{0x2e, 0x20}...)
  354. if t.Month() < 10 {
  355. b = append(b, '0')
  356. }
  357. b = strconv.AppendInt(b, int64(t.Month()), 10)
  358. b = append(b, []byte{0x2e, 0x20}...)
  359. if t.Year() > 9 {
  360. b = append(b, strconv.Itoa(t.Year())[2:]...)
  361. } else {
  362. b = append(b, strconv.Itoa(t.Year())[1:]...)
  363. }
  364. return string(b)
  365. }
  366. // FmtDateMedium returns the medium date representation of 't' for 'sl'
  367. func (sl *sl) FmtDateMedium(t time.Time) string {
  368. b := make([]byte, 0, 32)
  369. b = strconv.AppendInt(b, int64(t.Day()), 10)
  370. b = append(b, []byte{0x2e, 0x20}...)
  371. b = append(b, sl.monthsAbbreviated[t.Month()]...)
  372. b = append(b, []byte{0x20}...)
  373. b = strconv.AppendInt(b, int64(t.Year()), 10)
  374. return string(b)
  375. }
  376. // FmtDateLong returns the long date representation of 't' for 'sl'
  377. func (sl *sl) FmtDateLong(t time.Time) string {
  378. b := make([]byte, 0, 32)
  379. if t.Day() < 10 {
  380. b = append(b, '0')
  381. }
  382. b = strconv.AppendInt(b, int64(t.Day()), 10)
  383. b = append(b, []byte{0x2e, 0x20}...)
  384. b = append(b, sl.monthsWide[t.Month()]...)
  385. b = append(b, []byte{0x20}...)
  386. b = strconv.AppendInt(b, int64(t.Year()), 10)
  387. return string(b)
  388. }
  389. // FmtDateFull returns the full date representation of 't' for 'sl'
  390. func (sl *sl) FmtDateFull(t time.Time) string {
  391. b := make([]byte, 0, 32)
  392. b = append(b, sl.daysWide[t.Weekday()]...)
  393. b = append(b, []byte{0x2c, 0x20}...)
  394. if t.Day() < 10 {
  395. b = append(b, '0')
  396. }
  397. b = strconv.AppendInt(b, int64(t.Day()), 10)
  398. b = append(b, []byte{0x2e, 0x20}...)
  399. b = append(b, sl.monthsWide[t.Month()]...)
  400. b = append(b, []byte{0x20}...)
  401. b = strconv.AppendInt(b, int64(t.Year()), 10)
  402. return string(b)
  403. }
  404. // FmtTimeShort returns the short time representation of 't' for 'sl'
  405. func (sl *sl) FmtTimeShort(t time.Time) string {
  406. b := make([]byte, 0, 32)
  407. if t.Hour() < 10 {
  408. b = append(b, '0')
  409. }
  410. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  411. b = append(b, sl.timeSeparator...)
  412. if t.Minute() < 10 {
  413. b = append(b, '0')
  414. }
  415. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  416. return string(b)
  417. }
  418. // FmtTimeMedium returns the medium time representation of 't' for 'sl'
  419. func (sl *sl) FmtTimeMedium(t time.Time) string {
  420. b := make([]byte, 0, 32)
  421. if t.Hour() < 10 {
  422. b = append(b, '0')
  423. }
  424. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  425. b = append(b, sl.timeSeparator...)
  426. if t.Minute() < 10 {
  427. b = append(b, '0')
  428. }
  429. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  430. b = append(b, sl.timeSeparator...)
  431. if t.Second() < 10 {
  432. b = append(b, '0')
  433. }
  434. b = strconv.AppendInt(b, int64(t.Second()), 10)
  435. return string(b)
  436. }
  437. // FmtTimeLong returns the long time representation of 't' for 'sl'
  438. func (sl *sl) FmtTimeLong(t time.Time) string {
  439. b := make([]byte, 0, 32)
  440. if t.Hour() < 10 {
  441. b = append(b, '0')
  442. }
  443. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  444. b = append(b, sl.timeSeparator...)
  445. if t.Minute() < 10 {
  446. b = append(b, '0')
  447. }
  448. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  449. b = append(b, sl.timeSeparator...)
  450. if t.Second() < 10 {
  451. b = append(b, '0')
  452. }
  453. b = strconv.AppendInt(b, int64(t.Second()), 10)
  454. b = append(b, []byte{0x20}...)
  455. tz, _ := t.Zone()
  456. b = append(b, tz...)
  457. return string(b)
  458. }
  459. // FmtTimeFull returns the full time representation of 't' for 'sl'
  460. func (sl *sl) FmtTimeFull(t time.Time) string {
  461. b := make([]byte, 0, 32)
  462. if t.Hour() < 10 {
  463. b = append(b, '0')
  464. }
  465. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  466. b = append(b, sl.timeSeparator...)
  467. if t.Minute() < 10 {
  468. b = append(b, '0')
  469. }
  470. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  471. b = append(b, sl.timeSeparator...)
  472. if t.Second() < 10 {
  473. b = append(b, '0')
  474. }
  475. b = strconv.AppendInt(b, int64(t.Second()), 10)
  476. b = append(b, []byte{0x20}...)
  477. tz, _ := t.Zone()
  478. if btz, ok := sl.timezones[tz]; ok {
  479. b = append(b, btz...)
  480. } else {
  481. b = append(b, tz...)
  482. }
  483. return string(b)
  484. }