sv.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. package sv
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type sv 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 'sv' locale
  42. func New() locales.Translator {
  43. return &sv{
  44. locale: "sv",
  45. pluralsCardinal: []locales.PluralRule{2, 6},
  46. pluralsOrdinal: []locales.PluralRule{2, 6},
  47. pluralsRange: []locales.PluralRule{6},
  48. minus: "‏−",
  49. timeSeparator: ":",
  50. 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 ", "Bds$", "BDT", "BEC ", "BEF ", "BEL ", "BGL ", "BGM ", "BGN", "BGO ", "BHD", "BIF", "BM$", "BND", "BOB", "BOL ", "BOP ", "BOV ", "BRB ", "BRC ", "BRE ", "BR$", "BRN ", "BRR ", "BRZ ", "BS$", "BTN", "BUK ", "BWP", "BYB ", "BYR", "BZ$", "CA$", "CDF", "CHE ", "CHF", "CHW ", "CLE ", "CLF ", "CLP", "CNX", "CNY", "COP", "COU ", "CRC", "CSD ", "CSK ", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM ", "DEM ", "DJF", "Dkr", "RD$", "DZD", "ECS ", "ECV ", "Ekr", "EG£", "ERN", "ESA ", "ESB ", "ESP", "ETB", "€", "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 ", "₪", "INR", "IQD", "IRR", "ISJ", "Ikr", "ITL", "JM$", "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 ", "Nkr", "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 ", "kr", "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", "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 "},
  51. percentSuffix: " ",
  52. currencyPositiveSuffix: " ",
  53. currencyNegativeSuffix: " ",
  54. monthsAbbreviated: []string{"", "jan.", "feb.", "mars", "apr.", "maj", "juni", "juli", "aug.", "sep.", "okt.", "nov.", "dec."},
  55. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  56. monthsWide: []string{"", "januari", "februari", "mars", "april", "maj", "juni", "juli", "augusti", "september", "oktober", "november", "december"},
  57. daysAbbreviated: []string{"sön", "mån", "tis", "ons", "tors", "fre", "lör"},
  58. daysNarrow: []string{"S", "M", "T", "O", "T", "F", "L"},
  59. daysShort: []string{"sö", "må", "ti", "on", "to", "fr", "lö"},
  60. daysWide: []string{"söndag", "måndag", "tisdag", "onsdag", "torsdag", "fredag", "lördag"},
  61. periodsAbbreviated: []string{"fm", "em"},
  62. periodsNarrow: []string{"fm", "em"},
  63. periodsWide: []string{"fm", "em"},
  64. erasAbbreviated: []string{"f.Kr.", "e.Kr."},
  65. erasNarrow: []string{"f.Kr.", "e.Kr."},
  66. erasWide: []string{"före Kristus", "efter Kristus"},
  67. timezones: map[string]string{"HADT": "Honolulu, sommartid", "ACWDT": "västcentralaustralisk sommartid", "ChST": "Chamorrotid", "CAT": "centralafrikansk tid", "∅∅∅": "Amazonas, sommartid", "HKST": "Hongkong, sommartid", "HNT": "Newfoundland, normaltid", "WART": "västargentinsk normaltid", "WIB": "västindonesisk tid", "AWDT": "västaustralisk sommartid", "NZDT": "nyzeeländsk sommartid", "GMT": "Greenwichtid", "TMT": "turkmensk normaltid", "ART": "östargentinsk normaltid", "MYT": "malaysisk tid", "SGT": "Singaporetid", "OEZ": "östeuropeisk normaltid", "GFT": "Franska Guyanatid", "UYST": "uruguayansk sommartid", "CHADT": "Chatham, sommartid", "WEZ": "västeuropeisk normaltid", "BOT": "boliviansk tid", "ACWST": "västcentralaustralisk normaltid", "WAST": "västafrikansk sommartid", "ACDT": "centralaustralisk sommartid", "AKDT": "Alaska, sommartid", "CST": "centralnordamerikansk normaltid", "PDT": "västnordamerikansk sommartid", "VET": "venezuelansk tid", "ARST": "östargentinsk sommartid", "PST": "västnordamerikansk normaltid", "GYT": "Guyanatid", "CDT": "centralnordamerikansk sommartid", "COST": "colombiansk sommartid", "MST": "Macaunormaltid", "MDT": "Macausommartid", "ACST": "centralaustralisk normaltid", "WARST": "västargentinsk sommartid", "HKT": "Hongkong, normaltid", "MEZ": "centraleuropeisk normaltid", "EDT": "östnordamerikansk sommartid", "SAST": "sydafrikansk tid", "NZST": "nyzeeländsk normaltid", "AEST": "östaustralisk normaltid", "AST": "nordamerikansk atlantnormaltid", "CHAST": "Chatham, normaltid", "IST": "indisk tid", "TMST": "turkmensk sommartid", "EAT": "östafrikansk tid", "MESZ": "centraleuropeisk sommartid", "EST": "östnordamerikansk normaltid", "COT": "colombiansk normaltid", "HAST": "Honolulu, normaltid", "AKST": "Alaska, normaltid", "LHST": "Lord Howe, normaltid", "CLST": "chilensk sommartid", "WAT": "västafrikansk normaltid", "HAT": "Newfoundland, sommartid", "JST": "japansk normaltid", "LHDT": "Lord Howe, sommartid", "AEDT": "östaustralisk sommartid", "JDT": "japansk sommartid", "CLT": "chilensk normaltid", "BT": "bhutansk tid", "SRT": "Surinamtid", "AWST": "västaustralisk normaltid", "ADT": "nordamerikansk atlantsommartid", "WITA": "centralindonesisk tid", "WIT": "östindonesisk tid", "OESZ": "östeuropeisk sommartid", "UYT": "uruguayansk normaltid", "WESZ": "västeuropeisk sommartid", "ECT": "ecuadoriansk tid"},
  68. }
  69. }
  70. // Locale returns the current translators string locale
  71. func (sv *sv) Locale() string {
  72. return sv.locale
  73. }
  74. // PluralsCardinal returns the list of cardinal plural rules associated with 'sv'
  75. func (sv *sv) PluralsCardinal() []locales.PluralRule {
  76. return sv.pluralsCardinal
  77. }
  78. // PluralsOrdinal returns the list of ordinal plural rules associated with 'sv'
  79. func (sv *sv) PluralsOrdinal() []locales.PluralRule {
  80. return sv.pluralsOrdinal
  81. }
  82. // PluralsRange returns the list of range plural rules associated with 'sv'
  83. func (sv *sv) PluralsRange() []locales.PluralRule {
  84. return sv.pluralsRange
  85. }
  86. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'sv'
  87. func (sv *sv) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  88. n := math.Abs(num)
  89. i := int64(n)
  90. if i == 1 && v == 0 {
  91. return locales.PluralRuleOne
  92. }
  93. return locales.PluralRuleOther
  94. }
  95. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'sv'
  96. func (sv *sv) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  97. n := math.Abs(num)
  98. nMod100 := math.Mod(n, 100)
  99. nMod10 := math.Mod(n, 10)
  100. if (nMod10 == 1 || nMod10 == 2) && (nMod100 != 11 && nMod100 != 12) {
  101. return locales.PluralRuleOne
  102. }
  103. return locales.PluralRuleOther
  104. }
  105. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'sv'
  106. func (sv *sv) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  107. return locales.PluralRuleOther
  108. }
  109. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  110. func (sv *sv) MonthAbbreviated(month time.Month) string {
  111. return sv.monthsAbbreviated[month]
  112. }
  113. // MonthsAbbreviated returns the locales abbreviated months
  114. func (sv *sv) MonthsAbbreviated() []string {
  115. return sv.monthsAbbreviated[1:]
  116. }
  117. // MonthNarrow returns the locales narrow month given the 'month' provided
  118. func (sv *sv) MonthNarrow(month time.Month) string {
  119. return sv.monthsNarrow[month]
  120. }
  121. // MonthsNarrow returns the locales narrow months
  122. func (sv *sv) MonthsNarrow() []string {
  123. return sv.monthsNarrow[1:]
  124. }
  125. // MonthWide returns the locales wide month given the 'month' provided
  126. func (sv *sv) MonthWide(month time.Month) string {
  127. return sv.monthsWide[month]
  128. }
  129. // MonthsWide returns the locales wide months
  130. func (sv *sv) MonthsWide() []string {
  131. return sv.monthsWide[1:]
  132. }
  133. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  134. func (sv *sv) WeekdayAbbreviated(weekday time.Weekday) string {
  135. return sv.daysAbbreviated[weekday]
  136. }
  137. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  138. func (sv *sv) WeekdaysAbbreviated() []string {
  139. return sv.daysAbbreviated
  140. }
  141. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  142. func (sv *sv) WeekdayNarrow(weekday time.Weekday) string {
  143. return sv.daysNarrow[weekday]
  144. }
  145. // WeekdaysNarrow returns the locales narrow weekdays
  146. func (sv *sv) WeekdaysNarrow() []string {
  147. return sv.daysNarrow
  148. }
  149. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  150. func (sv *sv) WeekdayShort(weekday time.Weekday) string {
  151. return sv.daysShort[weekday]
  152. }
  153. // WeekdaysShort returns the locales short weekdays
  154. func (sv *sv) WeekdaysShort() []string {
  155. return sv.daysShort
  156. }
  157. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  158. func (sv *sv) WeekdayWide(weekday time.Weekday) string {
  159. return sv.daysWide[weekday]
  160. }
  161. // WeekdaysWide returns the locales wide weekdays
  162. func (sv *sv) WeekdaysWide() []string {
  163. return sv.daysWide
  164. }
  165. // FmtNumber returns 'num' with digits/precision of 'v' for 'sv' and handles both Whole and Real numbers based on 'v'
  166. func (sv *sv) FmtNumber(num float64, v uint64) string {
  167. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  168. l := len(s) + 6 + 0*len(s[:len(s)-int(v)-1])/3
  169. count := 0
  170. inWhole := v == 0
  171. b := make([]byte, 0, l)
  172. for i := len(s) - 1; i >= 0; i-- {
  173. if s[i] == '.' {
  174. b = append(b, sv.decimal[0])
  175. inWhole = true
  176. continue
  177. }
  178. if inWhole {
  179. if count == 3 {
  180. b = append(b, sv.group[0])
  181. count = 1
  182. } else {
  183. count++
  184. }
  185. }
  186. b = append(b, s[i])
  187. }
  188. if num < 0 {
  189. for j := len(sv.minus) - 1; j >= 0; j-- {
  190. b = append(b, sv.minus[j])
  191. }
  192. }
  193. // reverse
  194. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  195. b[i], b[j] = b[j], b[i]
  196. }
  197. return string(b)
  198. }
  199. // FmtPercent returns 'num' with digits/precision of 'v' for 'sv' and handles both Whole and Real numbers based on 'v'
  200. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  201. func (sv *sv) FmtPercent(num float64, v uint64) string {
  202. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  203. l := len(s) + 8
  204. b := make([]byte, 0, l)
  205. for i := len(s) - 1; i >= 0; i-- {
  206. if s[i] == '.' {
  207. b = append(b, sv.decimal[0])
  208. continue
  209. }
  210. b = append(b, s[i])
  211. }
  212. if num < 0 {
  213. for j := len(sv.minus) - 1; j >= 0; j-- {
  214. b = append(b, sv.minus[j])
  215. }
  216. }
  217. // reverse
  218. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  219. b[i], b[j] = b[j], b[i]
  220. }
  221. b = append(b, sv.percentSuffix...)
  222. b = append(b, sv.percent...)
  223. return string(b)
  224. }
  225. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'sv'
  226. func (sv *sv) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  227. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  228. symbol := sv.currencies[currency]
  229. l := len(s) + len(symbol) + 8 + 0*len(s[:len(s)-int(v)-1])/3
  230. count := 0
  231. inWhole := v == 0
  232. b := make([]byte, 0, l)
  233. for i := len(s) - 1; i >= 0; i-- {
  234. if s[i] == '.' {
  235. b = append(b, sv.decimal[0])
  236. inWhole = true
  237. continue
  238. }
  239. if inWhole {
  240. if count == 3 {
  241. b = append(b, sv.group[0])
  242. count = 1
  243. } else {
  244. count++
  245. }
  246. }
  247. b = append(b, s[i])
  248. }
  249. if num < 0 {
  250. for j := len(sv.minus) - 1; j >= 0; j-- {
  251. b = append(b, sv.minus[j])
  252. }
  253. }
  254. // reverse
  255. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  256. b[i], b[j] = b[j], b[i]
  257. }
  258. if int(v) < 2 {
  259. if v == 0 {
  260. b = append(b, sv.decimal...)
  261. }
  262. for i := 0; i < 2-int(v); i++ {
  263. b = append(b, '0')
  264. }
  265. }
  266. b = append(b, sv.currencyPositiveSuffix...)
  267. b = append(b, symbol...)
  268. return string(b)
  269. }
  270. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'sv'
  271. // in accounting notation.
  272. func (sv *sv) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  273. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  274. symbol := sv.currencies[currency]
  275. l := len(s) + len(symbol) + 8 + 0*len(s[:len(s)-int(v)-1])/3
  276. count := 0
  277. inWhole := v == 0
  278. b := make([]byte, 0, l)
  279. for i := len(s) - 1; i >= 0; i-- {
  280. if s[i] == '.' {
  281. b = append(b, sv.decimal[0])
  282. inWhole = true
  283. continue
  284. }
  285. if inWhole {
  286. if count == 3 {
  287. b = append(b, sv.group[0])
  288. count = 1
  289. } else {
  290. count++
  291. }
  292. }
  293. b = append(b, s[i])
  294. }
  295. if num < 0 {
  296. for j := len(sv.minus) - 1; j >= 0; j-- {
  297. b = append(b, sv.minus[j])
  298. }
  299. }
  300. // reverse
  301. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  302. b[i], b[j] = b[j], b[i]
  303. }
  304. if int(v) < 2 {
  305. if v == 0 {
  306. b = append(b, sv.decimal...)
  307. }
  308. for i := 0; i < 2-int(v); i++ {
  309. b = append(b, '0')
  310. }
  311. }
  312. if num < 0 {
  313. b = append(b, sv.currencyNegativeSuffix...)
  314. b = append(b, symbol...)
  315. } else {
  316. b = append(b, sv.currencyPositiveSuffix...)
  317. b = append(b, symbol...)
  318. }
  319. return string(b)
  320. }
  321. // FmtDateShort returns the short date representation of 't' for 'sv'
  322. func (sv *sv) FmtDateShort(t time.Time) string {
  323. b := make([]byte, 0, 32)
  324. b = strconv.AppendInt(b, int64(t.Year()), 10)
  325. b = append(b, []byte{0x2d}...)
  326. if t.Month() < 10 {
  327. b = append(b, '0')
  328. }
  329. b = strconv.AppendInt(b, int64(t.Month()), 10)
  330. b = append(b, []byte{0x2d}...)
  331. if t.Day() < 10 {
  332. b = append(b, '0')
  333. }
  334. b = strconv.AppendInt(b, int64(t.Day()), 10)
  335. return string(b)
  336. }
  337. // FmtDateMedium returns the medium date representation of 't' for 'sv'
  338. func (sv *sv) FmtDateMedium(t time.Time) string {
  339. b := make([]byte, 0, 32)
  340. b = strconv.AppendInt(b, int64(t.Day()), 10)
  341. b = append(b, []byte{0x20}...)
  342. b = append(b, sv.monthsAbbreviated[t.Month()]...)
  343. b = append(b, []byte{0x20}...)
  344. b = strconv.AppendInt(b, int64(t.Year()), 10)
  345. return string(b)
  346. }
  347. // FmtDateLong returns the long date representation of 't' for 'sv'
  348. func (sv *sv) FmtDateLong(t time.Time) string {
  349. b := make([]byte, 0, 32)
  350. b = strconv.AppendInt(b, int64(t.Day()), 10)
  351. b = append(b, []byte{0x20}...)
  352. b = append(b, sv.monthsWide[t.Month()]...)
  353. b = append(b, []byte{0x20}...)
  354. b = strconv.AppendInt(b, int64(t.Year()), 10)
  355. return string(b)
  356. }
  357. // FmtDateFull returns the full date representation of 't' for 'sv'
  358. func (sv *sv) FmtDateFull(t time.Time) string {
  359. b := make([]byte, 0, 32)
  360. b = append(b, sv.daysWide[t.Weekday()]...)
  361. b = append(b, []byte{0x20}...)
  362. b = strconv.AppendInt(b, int64(t.Day()), 10)
  363. b = append(b, []byte{0x20}...)
  364. b = append(b, sv.monthsWide[t.Month()]...)
  365. b = append(b, []byte{0x20}...)
  366. b = strconv.AppendInt(b, int64(t.Year()), 10)
  367. return string(b)
  368. }
  369. // FmtTimeShort returns the short time representation of 't' for 'sv'
  370. func (sv *sv) FmtTimeShort(t time.Time) string {
  371. b := make([]byte, 0, 32)
  372. if t.Hour() < 10 {
  373. b = append(b, '0')
  374. }
  375. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  376. b = append(b, sv.timeSeparator...)
  377. if t.Minute() < 10 {
  378. b = append(b, '0')
  379. }
  380. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  381. return string(b)
  382. }
  383. // FmtTimeMedium returns the medium time representation of 't' for 'sv'
  384. func (sv *sv) FmtTimeMedium(t time.Time) string {
  385. b := make([]byte, 0, 32)
  386. if t.Hour() < 10 {
  387. b = append(b, '0')
  388. }
  389. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  390. b = append(b, sv.timeSeparator...)
  391. if t.Minute() < 10 {
  392. b = append(b, '0')
  393. }
  394. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  395. b = append(b, sv.timeSeparator...)
  396. if t.Second() < 10 {
  397. b = append(b, '0')
  398. }
  399. b = strconv.AppendInt(b, int64(t.Second()), 10)
  400. return string(b)
  401. }
  402. // FmtTimeLong returns the long time representation of 't' for 'sv'
  403. func (sv *sv) FmtTimeLong(t time.Time) string {
  404. b := make([]byte, 0, 32)
  405. if t.Hour() < 10 {
  406. b = append(b, '0')
  407. }
  408. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  409. b = append(b, sv.timeSeparator...)
  410. if t.Minute() < 10 {
  411. b = append(b, '0')
  412. }
  413. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  414. b = append(b, sv.timeSeparator...)
  415. if t.Second() < 10 {
  416. b = append(b, '0')
  417. }
  418. b = strconv.AppendInt(b, int64(t.Second()), 10)
  419. b = append(b, []byte{0x20}...)
  420. tz, _ := t.Zone()
  421. b = append(b, tz...)
  422. return string(b)
  423. }
  424. // FmtTimeFull returns the full time representation of 't' for 'sv'
  425. func (sv *sv) FmtTimeFull(t time.Time) string {
  426. b := make([]byte, 0, 32)
  427. b = append(b, []byte{0x27, 0x6b, 0x6c, 0x27, 0x2e, 0x20}...)
  428. if t.Hour() < 10 {
  429. b = append(b, '0')
  430. }
  431. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  432. b = append(b, sv.timeSeparator...)
  433. if t.Minute() < 10 {
  434. b = append(b, '0')
  435. }
  436. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  437. b = append(b, sv.timeSeparator...)
  438. if t.Second() < 10 {
  439. b = append(b, '0')
  440. }
  441. b = strconv.AppendInt(b, int64(t.Second()), 10)
  442. b = append(b, []byte{0x20}...)
  443. tz, _ := t.Zone()
  444. if btz, ok := sv.timezones[tz]; ok {
  445. b = append(b, btz...)
  446. } else {
  447. b = append(b, tz...)
  448. }
  449. return string(b)
  450. }