eo.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. package eo
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type eo struct {
  10. locale string
  11. pluralsCardinal []locales.PluralRule
  12. pluralsOrdinal []locales.PluralRule
  13. pluralsRange []locales.PluralRule
  14. decimal string
  15. group string
  16. minus string
  17. percent string
  18. perMille string
  19. timeSeparator string
  20. inifinity string
  21. currencies []string // idx = enum of currency code
  22. currencyPositivePrefix string
  23. currencyPositiveSuffix string
  24. currencyNegativePrefix string
  25. currencyNegativeSuffix string
  26. monthsAbbreviated []string
  27. monthsNarrow []string
  28. monthsWide []string
  29. daysAbbreviated []string
  30. daysNarrow []string
  31. daysShort []string
  32. daysWide []string
  33. periodsAbbreviated []string
  34. periodsNarrow []string
  35. periodsShort []string
  36. periodsWide []string
  37. erasAbbreviated []string
  38. erasNarrow []string
  39. erasWide []string
  40. timezones map[string]string
  41. }
  42. // New returns a new instance of translator for the 'eo' locale
  43. func New() locales.Translator {
  44. return &eo{
  45. locale: "eo",
  46. pluralsCardinal: []locales.PluralRule{2, 6},
  47. pluralsOrdinal: nil,
  48. pluralsRange: nil,
  49. decimal: ",",
  50. group: " ",
  51. minus: "−",
  52. percent: "%",
  53. perMille: "‰",
  54. timeSeparator: ":",
  55. inifinity: "∞",
  56. currencies: []string{"ADP ", "AED ", "AFA ", "AFN ", "ALK ", "ALL ", "AMD ", "ANG ", "AOA ", "AOK ", "AON ", "AOR ", "ARA ", "ARL ", "ARM ", "ARP ", "ARS ", "ATS ", "AU$", "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 ", "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 ", "ILS ", "₹", "IQD ", "IRR ", "ISJ ", "ISK ", "ITL ", "JMD ", "JOD ", "JP¥", "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 ", "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 ", "฿", "TJR ", "TJS ", "TMM ", "TMT ", "TND ", "TOP ", "TPE ", "TRL ", "₺", "TTD ", "NT$", "TZS ", "UAH ", "UAK ", "UGS ", "UGX ", "US$", "USN ", "USS ", "UYI ", "UYP ", "UYU ", "UZS ", "VEB ", "VEF ", "VND ", "VNN ", "VUV ", "WST ", "XAF ", "XAG ", "XAU ", "XBA ", "XBB ", "XBC ", "XBD ", "XCD ", "XDR ", "XEU ", "XFO ", "XFU ", "XOF ", "XPD ", "XPF ", "XPT ", "XRE ", "XSU ", "XTS ", "XUA ", "XXX ", "YDD ", "YER ", "YUD ", "YUM ", "YUN ", "YUR ", "ZAL ", "ZAR", "ZMK ", "ZMW ", "ZRN ", "ZRZ ", "ZWD ", "ZWL ", "ZWR "},
  57. currencyPositivePrefix: " ",
  58. currencyPositiveSuffix: "K",
  59. currencyNegativePrefix: " ",
  60. currencyNegativeSuffix: "K",
  61. monthsAbbreviated: []string{"", "jan", "feb", "mar", "apr", "maj", "jun", "jul", "aŭg", "sep", "okt", "nov", "dec"},
  62. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  63. monthsWide: []string{"", "januaro", "februaro", "marto", "aprilo", "majo", "junio", "julio", "aŭgusto", "septembro", "oktobro", "novembro", "decembro"},
  64. daysAbbreviated: []string{"di", "lu", "ma", "me", "ĵa", "ve", "sa"},
  65. daysNarrow: []string{"D", "L", "M", "M", "Ĵ", "V", "S"},
  66. daysWide: []string{"dimanĉo", "lundo", "mardo", "merkredo", "ĵaŭdo", "vendredo", "sabato"},
  67. periodsAbbreviated: []string{"atm", "ptm"},
  68. periodsNarrow: []string{"a", "p"},
  69. periodsWide: []string{"atm", "ptm"},
  70. erasAbbreviated: []string{"aK", "pK"},
  71. erasNarrow: []string{"aK", "pK"},
  72. erasWide: []string{"aK", "pK"},
  73. timezones: map[string]string{"HKST": "HKST", "GMT": "universala tempo kunordigita", "ARST": "ARST", "NZDT": "NZDT", "ECT": "ECT", "HADT": "HADT", "SAST": "suda afrika tempo", "GYT": "GYT", "MESZ": "centra eŭropa somera tempo", "AEDT": "orienta aŭstralia somera tempo", "WESZ": "okcidenta eŭropa somera tempo", "EST": "orienta nord-amerika norma tempo", "EDT": "orienta nord-amerika somera tempo", "MEZ": "centra eŭropa norma tempo", "CDT": "centra nord-amerika somera tempo", "COST": "COST", "AWST": "okcidenta aŭstralia norma tempo", "AWDT": "okcidenta aŭstralia somera tempo", "SRT": "SRT", "BOT": "BOT", "COT": "COT", "EAT": "orienta afrika tempo", "UYT": "UYT", "ACWST": "centrokcidenta aŭstralia norma tempo", "JST": "japana norma tempo", "AEST": "orienta aŭstralia norma tempo", "WAT": "okcidenta afrika norma tempo", "JDT": "japana somera tempo", "CAT": "centra afrika tempo", "HKT": "HKT", "OESZ": "orienta eŭropa somera tempo", "MST": "MST", "NZST": "NZST", "CST": "centra nord-amerika norma tempo", "HNT": "HNT", "HAT": "HAT", "WIT": "orienta indonezia tempo", "PDT": "pacifika nord-amerika somera tempo", "CHAST": "CHAST", "ART": "ART", "ACWDT": "centrokcidenta aŭstralia somera tempo", "HAST": "HAST", "WARST": "WARST", "WIB": "okcidenta indonezia tempo", "AKDT": "AKDT", "CHADT": "CHADT", "CLT": "CLT", "WAST": "okcidenta afrika somera tempo", "BT": "BT", "GFT": "GFT", "OEZ": "orienta eŭropa norma tempo", "MDT": "MDT", "AKST": "AKST", "ChST": "ChST", "WEZ": "okcidenta eŭropa norma tempo", "AST": "atlantika nord-amerika norma tempo", "WART": "WART", "ACST": "centra aŭstralia norma tempo", "LHDT": "LHDT", "MYT": "MYT", "CLST": "CLST", "VET": "VET", "SGT": "SGT", "WITA": "centra indonezia tempo", "IST": "barata tempo", "TMST": "TMST", "LHST": "LHST", "UYST": "UYST", "ACDT": "centra aŭstralia somera tempo", "∅∅∅": "∅∅∅", "TMT": "TMT", "PST": "pacifika nord-amerika norma tempo", "ADT": "atlantika nord-amerika somera tempo"},
  74. }
  75. }
  76. // Locale returns the current translators string locale
  77. func (eo *eo) Locale() string {
  78. return eo.locale
  79. }
  80. // PluralsCardinal returns the list of cardinal plural rules associated with 'eo'
  81. func (eo *eo) PluralsCardinal() []locales.PluralRule {
  82. return eo.pluralsCardinal
  83. }
  84. // PluralsOrdinal returns the list of ordinal plural rules associated with 'eo'
  85. func (eo *eo) PluralsOrdinal() []locales.PluralRule {
  86. return eo.pluralsOrdinal
  87. }
  88. // PluralsRange returns the list of range plural rules associated with 'eo'
  89. func (eo *eo) PluralsRange() []locales.PluralRule {
  90. return eo.pluralsRange
  91. }
  92. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'eo'
  93. func (eo *eo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  94. n := math.Abs(num)
  95. if n == 1 {
  96. return locales.PluralRuleOne
  97. }
  98. return locales.PluralRuleOther
  99. }
  100. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'eo'
  101. func (eo *eo) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  102. return locales.PluralRuleUnknown
  103. }
  104. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'eo'
  105. func (eo *eo) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  106. return locales.PluralRuleUnknown
  107. }
  108. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  109. func (eo *eo) MonthAbbreviated(month time.Month) string {
  110. return eo.monthsAbbreviated[month]
  111. }
  112. // MonthsAbbreviated returns the locales abbreviated months
  113. func (eo *eo) MonthsAbbreviated() []string {
  114. return eo.monthsAbbreviated[1:]
  115. }
  116. // MonthNarrow returns the locales narrow month given the 'month' provided
  117. func (eo *eo) MonthNarrow(month time.Month) string {
  118. return eo.monthsNarrow[month]
  119. }
  120. // MonthsNarrow returns the locales narrow months
  121. func (eo *eo) MonthsNarrow() []string {
  122. return eo.monthsNarrow[1:]
  123. }
  124. // MonthWide returns the locales wide month given the 'month' provided
  125. func (eo *eo) MonthWide(month time.Month) string {
  126. return eo.monthsWide[month]
  127. }
  128. // MonthsWide returns the locales wide months
  129. func (eo *eo) MonthsWide() []string {
  130. return eo.monthsWide[1:]
  131. }
  132. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  133. func (eo *eo) WeekdayAbbreviated(weekday time.Weekday) string {
  134. return eo.daysAbbreviated[weekday]
  135. }
  136. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  137. func (eo *eo) WeekdaysAbbreviated() []string {
  138. return eo.daysAbbreviated
  139. }
  140. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  141. func (eo *eo) WeekdayNarrow(weekday time.Weekday) string {
  142. return eo.daysNarrow[weekday]
  143. }
  144. // WeekdaysNarrow returns the locales narrow weekdays
  145. func (eo *eo) WeekdaysNarrow() []string {
  146. return eo.daysNarrow
  147. }
  148. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  149. func (eo *eo) WeekdayShort(weekday time.Weekday) string {
  150. return eo.daysShort[weekday]
  151. }
  152. // WeekdaysShort returns the locales short weekdays
  153. func (eo *eo) WeekdaysShort() []string {
  154. return eo.daysShort
  155. }
  156. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  157. func (eo *eo) WeekdayWide(weekday time.Weekday) string {
  158. return eo.daysWide[weekday]
  159. }
  160. // WeekdaysWide returns the locales wide weekdays
  161. func (eo *eo) WeekdaysWide() []string {
  162. return eo.daysWide
  163. }
  164. // FmtNumber returns 'num' with digits/precision of 'v' for 'eo' and handles both Whole and Real numbers based on 'v'
  165. func (eo *eo) FmtNumber(num float64, v uint64) string {
  166. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  167. l := len(s) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  168. count := 0
  169. inWhole := v == 0
  170. b := make([]byte, 0, l)
  171. for i := len(s) - 1; i >= 0; i-- {
  172. if s[i] == '.' {
  173. b = append(b, eo.decimal[0])
  174. inWhole = true
  175. continue
  176. }
  177. if inWhole {
  178. if count == 3 {
  179. for j := len(eo.group) - 1; j >= 0; j-- {
  180. b = append(b, eo.group[j])
  181. }
  182. count = 1
  183. } else {
  184. count++
  185. }
  186. }
  187. b = append(b, s[i])
  188. }
  189. if num < 0 {
  190. for j := len(eo.minus) - 1; j >= 0; j-- {
  191. b = append(b, eo.minus[j])
  192. }
  193. }
  194. // reverse
  195. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  196. b[i], b[j] = b[j], b[i]
  197. }
  198. return string(b)
  199. }
  200. // FmtPercent returns 'num' with digits/precision of 'v' for 'eo' and handles both Whole and Real numbers based on 'v'
  201. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  202. func (eo *eo) FmtPercent(num float64, v uint64) string {
  203. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  204. l := len(s) + 5
  205. b := make([]byte, 0, l)
  206. for i := len(s) - 1; i >= 0; i-- {
  207. if s[i] == '.' {
  208. b = append(b, eo.decimal[0])
  209. continue
  210. }
  211. b = append(b, s[i])
  212. }
  213. if num < 0 {
  214. for j := len(eo.minus) - 1; j >= 0; j-- {
  215. b = append(b, eo.minus[j])
  216. }
  217. }
  218. // reverse
  219. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  220. b[i], b[j] = b[j], b[i]
  221. }
  222. b = append(b, eo.percent...)
  223. return string(b)
  224. }
  225. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'eo'
  226. func (eo *eo) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  227. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  228. symbol := eo.currencies[currency]
  229. l := len(s) + len(symbol) + 7
  230. b := make([]byte, 0, l)
  231. for i := len(s) - 1; i >= 0; i-- {
  232. if s[i] == '.' {
  233. b = append(b, eo.decimal[0])
  234. continue
  235. }
  236. b = append(b, s[i])
  237. }
  238. for j := len(symbol) - 1; j >= 0; j-- {
  239. b = append(b, symbol[j])
  240. }
  241. for j := len(eo.currencyPositivePrefix) - 1; j >= 0; j-- {
  242. b = append(b, eo.currencyPositivePrefix[j])
  243. }
  244. if num < 0 {
  245. for j := len(eo.minus) - 1; j >= 0; j-- {
  246. b = append(b, eo.minus[j])
  247. }
  248. }
  249. // reverse
  250. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  251. b[i], b[j] = b[j], b[i]
  252. }
  253. b = append(b, eo.currencyPositiveSuffix...)
  254. return string(b)
  255. }
  256. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'eo'
  257. // in accounting notation.
  258. func (eo *eo) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  259. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  260. symbol := eo.currencies[currency]
  261. l := len(s) + len(symbol) + 7
  262. b := make([]byte, 0, l)
  263. for i := len(s) - 1; i >= 0; i-- {
  264. if s[i] == '.' {
  265. b = append(b, eo.decimal[0])
  266. continue
  267. }
  268. b = append(b, s[i])
  269. }
  270. if num < 0 {
  271. for j := len(symbol) - 1; j >= 0; j-- {
  272. b = append(b, symbol[j])
  273. }
  274. for j := len(eo.currencyNegativePrefix) - 1; j >= 0; j-- {
  275. b = append(b, eo.currencyNegativePrefix[j])
  276. }
  277. for j := len(eo.minus) - 1; j >= 0; j-- {
  278. b = append(b, eo.minus[j])
  279. }
  280. } else {
  281. for j := len(symbol) - 1; j >= 0; j-- {
  282. b = append(b, symbol[j])
  283. }
  284. for j := len(eo.currencyPositivePrefix) - 1; j >= 0; j-- {
  285. b = append(b, eo.currencyPositivePrefix[j])
  286. }
  287. }
  288. // reverse
  289. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  290. b[i], b[j] = b[j], b[i]
  291. }
  292. if num < 0 {
  293. b = append(b, eo.currencyNegativeSuffix...)
  294. } else {
  295. b = append(b, eo.currencyPositiveSuffix...)
  296. }
  297. return string(b)
  298. }
  299. // FmtDateShort returns the short date representation of 't' for 'eo'
  300. func (eo *eo) FmtDateShort(t time.Time) string {
  301. b := make([]byte, 0, 32)
  302. if t.Year() > 9 {
  303. b = append(b, strconv.Itoa(t.Year())[2:]...)
  304. } else {
  305. b = append(b, strconv.Itoa(t.Year())[1:]...)
  306. }
  307. b = append(b, []byte{0x2d}...)
  308. if t.Month() < 10 {
  309. b = append(b, '0')
  310. }
  311. b = strconv.AppendInt(b, int64(t.Month()), 10)
  312. b = append(b, []byte{0x2d}...)
  313. if t.Day() < 10 {
  314. b = append(b, '0')
  315. }
  316. b = strconv.AppendInt(b, int64(t.Day()), 10)
  317. return string(b)
  318. }
  319. // FmtDateMedium returns the medium date representation of 't' for 'eo'
  320. func (eo *eo) FmtDateMedium(t time.Time) string {
  321. b := make([]byte, 0, 32)
  322. b = strconv.AppendInt(b, int64(t.Year()), 10)
  323. b = append(b, []byte{0x2d}...)
  324. b = append(b, eo.monthsAbbreviated[t.Month()]...)
  325. b = append(b, []byte{0x2d}...)
  326. if t.Day() < 10 {
  327. b = append(b, '0')
  328. }
  329. b = strconv.AppendInt(b, int64(t.Day()), 10)
  330. return string(b)
  331. }
  332. // FmtDateLong returns the long date representation of 't' for 'eo'
  333. func (eo *eo) FmtDateLong(t time.Time) string {
  334. b := make([]byte, 0, 32)
  335. b = strconv.AppendInt(b, int64(t.Year()), 10)
  336. b = append(b, []byte{0x2d}...)
  337. b = append(b, eo.monthsWide[t.Month()]...)
  338. b = append(b, []byte{0x2d}...)
  339. if t.Day() < 10 {
  340. b = append(b, '0')
  341. }
  342. b = strconv.AppendInt(b, int64(t.Day()), 10)
  343. return string(b)
  344. }
  345. // FmtDateFull returns the full date representation of 't' for 'eo'
  346. func (eo *eo) FmtDateFull(t time.Time) string {
  347. b := make([]byte, 0, 32)
  348. b = append(b, eo.daysWide[t.Weekday()]...)
  349. b = append(b, []byte{0x2c, 0x20}...)
  350. b = strconv.AppendInt(b, int64(t.Day()), 10)
  351. b = append(b, []byte{}...)
  352. b = append(b, []byte{0x27, 0x61, 0x27}...)
  353. b = append(b, []byte{0x27, 0x64, 0x65, 0x27, 0x20}...)
  354. b = append(b, eo.monthsWide[t.Month()]...)
  355. b = append(b, []byte{0x20}...)
  356. b = strconv.AppendInt(b, int64(t.Year()), 10)
  357. return string(b)
  358. }
  359. // FmtTimeShort returns the short time representation of 't' for 'eo'
  360. func (eo *eo) FmtTimeShort(t time.Time) string {
  361. b := make([]byte, 0, 32)
  362. if t.Hour() < 10 {
  363. b = append(b, '0')
  364. }
  365. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  366. b = append(b, eo.timeSeparator...)
  367. if t.Minute() < 10 {
  368. b = append(b, '0')
  369. }
  370. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  371. return string(b)
  372. }
  373. // FmtTimeMedium returns the medium time representation of 't' for 'eo'
  374. func (eo *eo) FmtTimeMedium(t time.Time) string {
  375. b := make([]byte, 0, 32)
  376. if t.Hour() < 10 {
  377. b = append(b, '0')
  378. }
  379. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  380. b = append(b, eo.timeSeparator...)
  381. if t.Minute() < 10 {
  382. b = append(b, '0')
  383. }
  384. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  385. b = append(b, eo.timeSeparator...)
  386. if t.Second() < 10 {
  387. b = append(b, '0')
  388. }
  389. b = strconv.AppendInt(b, int64(t.Second()), 10)
  390. return string(b)
  391. }
  392. // FmtTimeLong returns the long time representation of 't' for 'eo'
  393. func (eo *eo) FmtTimeLong(t time.Time) string {
  394. b := make([]byte, 0, 32)
  395. if t.Hour() < 10 {
  396. b = append(b, '0')
  397. }
  398. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  399. b = append(b, eo.timeSeparator...)
  400. if t.Minute() < 10 {
  401. b = append(b, '0')
  402. }
  403. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  404. b = append(b, eo.timeSeparator...)
  405. if t.Second() < 10 {
  406. b = append(b, '0')
  407. }
  408. b = strconv.AppendInt(b, int64(t.Second()), 10)
  409. b = append(b, []byte{0x20}...)
  410. tz, _ := t.Zone()
  411. b = append(b, tz...)
  412. return string(b)
  413. }
  414. // FmtTimeFull returns the full time representation of 't' for 'eo'
  415. func (eo *eo) FmtTimeFull(t time.Time) string {
  416. b := make([]byte, 0, 32)
  417. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  418. b = append(b, []byte{}...)
  419. b = append(b, []byte{0x27, 0x61, 0x27}...)
  420. b = append(b, []byte{0x27, 0x68, 0x6f, 0x72, 0x6f, 0x27}...)
  421. b = append(b, []byte{0x27, 0x6b, 0x61, 0x6a, 0x27, 0x20}...)
  422. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  423. b = append(b, eo.timeSeparator...)
  424. if t.Second() < 10 {
  425. b = append(b, '0')
  426. }
  427. b = strconv.AppendInt(b, int64(t.Second()), 10)
  428. b = append(b, []byte{0x20}...)
  429. tz, _ := t.Zone()
  430. if btz, ok := eo.timezones[tz]; ok {
  431. b = append(b, btz...)
  432. } else {
  433. b = append(b, tz...)
  434. }
  435. return string(b)
  436. }