ee.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. package ee
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ee 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 'ee' locale
  41. func New() locales.Translator {
  42. return &ee{
  43. locale: "ee",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  47. timeSeparator: ":",
  48. 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 ", "GH₵", "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 ", "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 ", "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 ", "US$", "USN ", "USS ", "UYI ", "UYP ", "UYU ", "UZS ", "VEB ", "VEF ", "₫", "VNN ", "VUV ", "WST ", "XAF ", "XAG ", "XAU ", "XBA ", "XBB ", "XBC ", "XBD ", "EC$", "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 "},
  49. currencyNegativePrefix: "(",
  50. currencyNegativeSuffix: ")",
  51. monthsAbbreviated: []string{"", "dzv", "dzd", "ted", "afɔ", "dam", "mas", "sia", "dea", "any", "kel", "ade", "dzm"},
  52. monthsNarrow: []string{"", "d", "d", "t", "a", "d", "m", "s", "d", "a", "k", "a", "d"},
  53. monthsWide: []string{"", "dzove", "dzodze", "tedoxe", "afɔfĩe", "dama", "masa", "siamlɔm", "deasiamime", "anyɔnyɔ", "kele", "adeɛmekpɔxe", "dzome"},
  54. daysAbbreviated: []string{"kɔs", "dzo", "bla", "kuɖ", "yaw", "fiɖ", "mem"},
  55. daysNarrow: []string{"k", "d", "b", "k", "y", "f", "m"},
  56. daysShort: []string{"kɔs", "dzo", "bla", "kuɖ", "yaw", "fiɖ", "mem"},
  57. daysWide: []string{"kɔsiɖa", "dzoɖa", "blaɖa", "kuɖa", "yawoɖa", "fiɖa", "memleɖa"},
  58. periodsAbbreviated: []string{"ŋdi", "ɣetrɔ"},
  59. periodsNarrow: []string{"ŋ", "ɣ"},
  60. periodsWide: []string{"ŋdi", "ɣetrɔ"},
  61. erasAbbreviated: []string{"hY", "Yŋ"},
  62. erasNarrow: []string{"hY", "Yŋ"},
  63. erasWide: []string{"Hafi Yesu Va Do ŋgɔ", "Yesu Ŋɔli"},
  64. timezones: map[string]string{"∅∅∅": "Brasilia dzomeŋɔli gaƒoƒome", "COST": "Kolombia dzomeŋɔli gaƒoƒome", "OEZ": "Ɣedzeƒe Europe gaƒoƒoɖoanyime", "SRT": "Suriname gaƒoƒome", "ACWDT": "Australia ɣetoɖofe ŋkekeme gaƒoƒome", "AEST": "Ɣedzeƒe Australia gaƒoƒoɖoanyime", "ECT": "Ikuedɔ dzomeŋɔli gaƒoƒome", "IST": "IST", "MEZ": "Titina Europe gaƒoƒoɖoanyime", "CLT": "Tsile gaƒoƒoɖoanyime", "WEZ": "Ɣetoɖoƒe Europe gaƒoƒoɖoanyime", "WAST": "Ɣetoɖoƒe Africa ŋkekeme gaƒoƒome", "ACDT": "Titina Australia ŋkekeme gaƒoƒome", "GYT": "Gayana gaƒoƒome", "JST": "Japan gaƒoƒoɖanyime", "MESZ": "Titina Europe ŋkekeme gaƒoƒome", "NZST": "NZST", "MST": "America Todzidukɔwo ƒe gaƒoƒoɖoanyime", "HADT": "Hawaii-Aleutia ŋkekeme gaƒoƒome", "ADT": "Atlantic ŋkekeme gaƒoƒome", "GFT": "Frentsi Guiana gaƒoƒome", "EAT": "Ɣedzeƒe Africa gaƒoƒome", "PDT": "Pacific ŋkekme gaƒoƒome", "CST": "Titina America gaƒoƒoɖoanyime", "CHAST": "CHAST", "CLST": "Tsile dzomeŋɔli gaƒoƒome", "HKT": "Hɔng Kɔng gaƒoƒoɖoanyi me", "SAST": "Anyiehe Africa gaƒoƒome", "BT": "BT", "HKST": "Hɔng Kɔng dzomeŋɔli gaƒoƒome", "WIT": "WIT", "WIB": "WIB", "UYST": "Uruguai dzomeŋɔli gaƒoƒome", "COT": "Kolombia gaƒoƒoɖoanyime", "HAST": "Hawaii-Aleutia gaƒoƒoɖoanyime", "WARST": "Ɣetoɖoƒe Argentina dzomeŋɔli gaƒoƒome", "AKST": "Alaska gaƒoƒoɖoanyime", "ChST": "ChST", "EST": "Ɣedzeƒe America gaƒoƒoɖoanyime", "OESZ": "Ɣedzeƒe Europe ŋkekeme gaƒoƒome", "AWST": "Ɣetoɖoƒe Australia gaƒoƒoɖoanyime", "MDT": "America Todzidukɔwo ƒe ŋkekme gaƒoƒome", "CHADT": "CHADT", "VET": "Venezuela gaƒoƒome", "AEDT": "Ɣedzeƒe Australia ŋkekeme gaƒoƒome", "NZDT": "NZDT", "WITA": "WITA", "ARST": "Argentina dzomeŋɔli gaƒoƒome", "AKDT": "Alaska ŋkekeme gaƒoƒome", "ACWST": "Australia ɣetoɖofe gaƒoƒoɖoanyime", "EDT": "Ɣedzeƒe America ŋkekeme gaƒoƒome", "TMST": "Tɛkmenistan dzomeŋɔli gaƒoƒome", "ACST": "Titina Australia gaƒoƒoɖoanyime", "WAT": "Ɣetoɖoƒe Afrika gaƒoƒoɖoanyime", "GMT": "Greenwich gaƒoƒome", "HNT": "Niufaunɖlanɖ gaƒoƒoɖoanyime", "TMT": "Tɛkmenistan gaƒoƒoɖoanyime", "UYT": "Uruguai gaƒoƒoɖoanyime", "CDT": "Titina America ŋkekeme gaƒoƒome", "AST": "Atlantic gaƒoƒoɖoanyime", "SGT": "SGT", "MYT": "MYT", "PST": "Pacific gaƒoƒoɖoanyime", "WESZ": "Ɣetoɖoƒe Europe ŋkekeme gaƒoƒome", "HAT": "Niufaunɖlanɖ ŋkekeme gaƒoƒome", "ART": "Argentina gaƒoƒoɖoanyime", "LHST": "LHST", "AWDT": "Ɣetoɖoƒe Australia ŋkekeme gaƒoƒome", "LHDT": "LHDT", "BOT": "Bolivia gaƒoƒome", "CAT": "Titina Afrika gaƒoƒome", "WART": "Ɣetoɖoƒe Argentina gaƒoƒoɖoanyime", "JDT": "Japan ŋkekeme gaƒoƒome"},
  65. }
  66. }
  67. // Locale returns the current translators string locale
  68. func (ee *ee) Locale() string {
  69. return ee.locale
  70. }
  71. // PluralsCardinal returns the list of cardinal plural rules associated with 'ee'
  72. func (ee *ee) PluralsCardinal() []locales.PluralRule {
  73. return ee.pluralsCardinal
  74. }
  75. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ee'
  76. func (ee *ee) PluralsOrdinal() []locales.PluralRule {
  77. return ee.pluralsOrdinal
  78. }
  79. // PluralsRange returns the list of range plural rules associated with 'ee'
  80. func (ee *ee) PluralsRange() []locales.PluralRule {
  81. return ee.pluralsRange
  82. }
  83. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ee'
  84. func (ee *ee) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  85. n := math.Abs(num)
  86. if n == 1 {
  87. return locales.PluralRuleOne
  88. }
  89. return locales.PluralRuleOther
  90. }
  91. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ee'
  92. func (ee *ee) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. return locales.PluralRuleUnknown
  94. }
  95. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ee'
  96. func (ee *ee) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  97. return locales.PluralRuleUnknown
  98. }
  99. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  100. func (ee *ee) MonthAbbreviated(month time.Month) string {
  101. return ee.monthsAbbreviated[month]
  102. }
  103. // MonthsAbbreviated returns the locales abbreviated months
  104. func (ee *ee) MonthsAbbreviated() []string {
  105. return ee.monthsAbbreviated[1:]
  106. }
  107. // MonthNarrow returns the locales narrow month given the 'month' provided
  108. func (ee *ee) MonthNarrow(month time.Month) string {
  109. return ee.monthsNarrow[month]
  110. }
  111. // MonthsNarrow returns the locales narrow months
  112. func (ee *ee) MonthsNarrow() []string {
  113. return ee.monthsNarrow[1:]
  114. }
  115. // MonthWide returns the locales wide month given the 'month' provided
  116. func (ee *ee) MonthWide(month time.Month) string {
  117. return ee.monthsWide[month]
  118. }
  119. // MonthsWide returns the locales wide months
  120. func (ee *ee) MonthsWide() []string {
  121. return ee.monthsWide[1:]
  122. }
  123. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  124. func (ee *ee) WeekdayAbbreviated(weekday time.Weekday) string {
  125. return ee.daysAbbreviated[weekday]
  126. }
  127. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  128. func (ee *ee) WeekdaysAbbreviated() []string {
  129. return ee.daysAbbreviated
  130. }
  131. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  132. func (ee *ee) WeekdayNarrow(weekday time.Weekday) string {
  133. return ee.daysNarrow[weekday]
  134. }
  135. // WeekdaysNarrow returns the locales narrow weekdays
  136. func (ee *ee) WeekdaysNarrow() []string {
  137. return ee.daysNarrow
  138. }
  139. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  140. func (ee *ee) WeekdayShort(weekday time.Weekday) string {
  141. return ee.daysShort[weekday]
  142. }
  143. // WeekdaysShort returns the locales short weekdays
  144. func (ee *ee) WeekdaysShort() []string {
  145. return ee.daysShort
  146. }
  147. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  148. func (ee *ee) WeekdayWide(weekday time.Weekday) string {
  149. return ee.daysWide[weekday]
  150. }
  151. // WeekdaysWide returns the locales wide weekdays
  152. func (ee *ee) WeekdaysWide() []string {
  153. return ee.daysWide
  154. }
  155. // FmtNumber returns 'num' with digits/precision of 'v' for 'ee' and handles both Whole and Real numbers based on 'v'
  156. func (ee *ee) FmtNumber(num float64, v uint64) string {
  157. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  158. }
  159. // FmtPercent returns 'num' with digits/precision of 'v' for 'ee' and handles both Whole and Real numbers based on 'v'
  160. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  161. func (ee *ee) FmtPercent(num float64, v uint64) string {
  162. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  163. }
  164. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ee'
  165. func (ee *ee) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  166. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  167. symbol := ee.currencies[currency]
  168. l := len(s) + len(symbol) + 0 + 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, ee.decimal[0])
  175. inWhole = true
  176. continue
  177. }
  178. if inWhole {
  179. if count == 3 {
  180. b = append(b, ee.group[0])
  181. count = 1
  182. } else {
  183. count++
  184. }
  185. }
  186. b = append(b, s[i])
  187. }
  188. for j := len(symbol) - 1; j >= 0; j-- {
  189. b = append(b, symbol[j])
  190. }
  191. if num < 0 {
  192. b = append(b, ee.minus[0])
  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. if int(v) < 2 {
  199. if v == 0 {
  200. b = append(b, ee.decimal...)
  201. }
  202. for i := 0; i < 2-int(v); i++ {
  203. b = append(b, '0')
  204. }
  205. }
  206. return string(b)
  207. }
  208. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ee'
  209. // in accounting notation.
  210. func (ee *ee) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  211. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  212. symbol := ee.currencies[currency]
  213. l := len(s) + len(symbol) + 2 + 0*len(s[:len(s)-int(v)-1])/3
  214. count := 0
  215. inWhole := v == 0
  216. b := make([]byte, 0, l)
  217. for i := len(s) - 1; i >= 0; i-- {
  218. if s[i] == '.' {
  219. b = append(b, ee.decimal[0])
  220. inWhole = true
  221. continue
  222. }
  223. if inWhole {
  224. if count == 3 {
  225. b = append(b, ee.group[0])
  226. count = 1
  227. } else {
  228. count++
  229. }
  230. }
  231. b = append(b, s[i])
  232. }
  233. if num < 0 {
  234. for j := len(symbol) - 1; j >= 0; j-- {
  235. b = append(b, symbol[j])
  236. }
  237. b = append(b, ee.currencyNegativePrefix[0])
  238. } else {
  239. for j := len(symbol) - 1; j >= 0; j-- {
  240. b = append(b, symbol[j])
  241. }
  242. }
  243. // reverse
  244. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  245. b[i], b[j] = b[j], b[i]
  246. }
  247. if int(v) < 2 {
  248. if v == 0 {
  249. b = append(b, ee.decimal...)
  250. }
  251. for i := 0; i < 2-int(v); i++ {
  252. b = append(b, '0')
  253. }
  254. }
  255. if num < 0 {
  256. b = append(b, ee.currencyNegativeSuffix...)
  257. }
  258. return string(b)
  259. }
  260. // FmtDateShort returns the short date representation of 't' for 'ee'
  261. func (ee *ee) FmtDateShort(t time.Time) string {
  262. b := make([]byte, 0, 32)
  263. b = strconv.AppendInt(b, int64(t.Month()), 10)
  264. b = append(b, []byte{0x2f}...)
  265. b = strconv.AppendInt(b, int64(t.Day()), 10)
  266. b = append(b, []byte{0x2f}...)
  267. if t.Year() > 9 {
  268. b = append(b, strconv.Itoa(t.Year())[2:]...)
  269. } else {
  270. b = append(b, strconv.Itoa(t.Year())[1:]...)
  271. }
  272. return string(b)
  273. }
  274. // FmtDateMedium returns the medium date representation of 't' for 'ee'
  275. func (ee *ee) FmtDateMedium(t time.Time) string {
  276. b := make([]byte, 0, 32)
  277. b = append(b, ee.monthsAbbreviated[t.Month()]...)
  278. b = append(b, []byte{0x20}...)
  279. b = strconv.AppendInt(b, int64(t.Day()), 10)
  280. b = append(b, []byte{}...)
  281. b = append(b, []byte{0x27, 0x6c, 0x69, 0x61, 0x27, 0x2c, 0x20}...)
  282. b = strconv.AppendInt(b, int64(t.Year()), 10)
  283. return string(b)
  284. }
  285. // FmtDateLong returns the long date representation of 't' for 'ee'
  286. func (ee *ee) FmtDateLong(t time.Time) string {
  287. b := make([]byte, 0, 32)
  288. b = append(b, ee.monthsWide[t.Month()]...)
  289. b = append(b, []byte{0x20}...)
  290. b = strconv.AppendInt(b, int64(t.Day()), 10)
  291. b = append(b, []byte{}...)
  292. b = append(b, []byte{0x27, 0x6c, 0x69, 0x61, 0x27, 0x20}...)
  293. b = strconv.AppendInt(b, int64(t.Year()), 10)
  294. return string(b)
  295. }
  296. // FmtDateFull returns the full date representation of 't' for 'ee'
  297. func (ee *ee) FmtDateFull(t time.Time) string {
  298. b := make([]byte, 0, 32)
  299. b = append(b, ee.daysWide[t.Weekday()]...)
  300. b = append(b, []byte{0x2c, 0x20}...)
  301. b = append(b, ee.monthsWide[t.Month()]...)
  302. b = append(b, []byte{0x20}...)
  303. b = strconv.AppendInt(b, int64(t.Day()), 10)
  304. b = append(b, []byte{}...)
  305. b = append(b, []byte{0x27, 0x6c, 0x69, 0x61, 0x27, 0x20}...)
  306. b = strconv.AppendInt(b, int64(t.Year()), 10)
  307. return string(b)
  308. }
  309. // FmtTimeShort returns the short time representation of 't' for 'ee'
  310. func (ee *ee) FmtTimeShort(t time.Time) string {
  311. b := make([]byte, 0, 32)
  312. if t.Hour() < 12 {
  313. b = append(b, ee.periodsAbbreviated[0]...)
  314. } else {
  315. b = append(b, ee.periodsAbbreviated[1]...)
  316. }
  317. b = append(b, []byte{}...)
  318. b = append(b, []byte{0x27, 0x67, 0x61, 0x27, 0x20}...)
  319. h := t.Hour()
  320. if h > 12 {
  321. h -= 12
  322. }
  323. b = strconv.AppendInt(b, int64(h), 10)
  324. b = append(b, ee.timeSeparator...)
  325. if t.Minute() < 10 {
  326. b = append(b, '0')
  327. }
  328. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  329. return string(b)
  330. }
  331. // FmtTimeMedium returns the medium time representation of 't' for 'ee'
  332. func (ee *ee) FmtTimeMedium(t time.Time) string {
  333. b := make([]byte, 0, 32)
  334. if t.Hour() < 12 {
  335. b = append(b, ee.periodsAbbreviated[0]...)
  336. } else {
  337. b = append(b, ee.periodsAbbreviated[1]...)
  338. }
  339. b = append(b, []byte{}...)
  340. b = append(b, []byte{0x27, 0x67, 0x61, 0x27, 0x20}...)
  341. h := t.Hour()
  342. if h > 12 {
  343. h -= 12
  344. }
  345. b = strconv.AppendInt(b, int64(h), 10)
  346. b = append(b, ee.timeSeparator...)
  347. if t.Minute() < 10 {
  348. b = append(b, '0')
  349. }
  350. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  351. b = append(b, ee.timeSeparator...)
  352. if t.Second() < 10 {
  353. b = append(b, '0')
  354. }
  355. b = strconv.AppendInt(b, int64(t.Second()), 10)
  356. return string(b)
  357. }
  358. // FmtTimeLong returns the long time representation of 't' for 'ee'
  359. func (ee *ee) FmtTimeLong(t time.Time) string {
  360. b := make([]byte, 0, 32)
  361. if t.Hour() < 12 {
  362. b = append(b, ee.periodsAbbreviated[0]...)
  363. } else {
  364. b = append(b, ee.periodsAbbreviated[1]...)
  365. }
  366. b = append(b, []byte{}...)
  367. b = append(b, []byte{0x27, 0x67, 0x61, 0x27, 0x20}...)
  368. h := t.Hour()
  369. if h > 12 {
  370. h -= 12
  371. }
  372. b = strconv.AppendInt(b, int64(h), 10)
  373. b = append(b, ee.timeSeparator...)
  374. if t.Minute() < 10 {
  375. b = append(b, '0')
  376. }
  377. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  378. b = append(b, ee.timeSeparator...)
  379. if t.Second() < 10 {
  380. b = append(b, '0')
  381. }
  382. b = strconv.AppendInt(b, int64(t.Second()), 10)
  383. b = append(b, []byte{0x20}...)
  384. tz, _ := t.Zone()
  385. b = append(b, tz...)
  386. return string(b)
  387. }
  388. // FmtTimeFull returns the full time representation of 't' for 'ee'
  389. func (ee *ee) FmtTimeFull(t time.Time) string {
  390. b := make([]byte, 0, 32)
  391. if t.Hour() < 12 {
  392. b = append(b, ee.periodsAbbreviated[0]...)
  393. } else {
  394. b = append(b, ee.periodsAbbreviated[1]...)
  395. }
  396. b = append(b, []byte{}...)
  397. b = append(b, []byte{0x27, 0x67, 0x61, 0x27, 0x20}...)
  398. h := t.Hour()
  399. if h > 12 {
  400. h -= 12
  401. }
  402. b = strconv.AppendInt(b, int64(h), 10)
  403. b = append(b, ee.timeSeparator...)
  404. if t.Minute() < 10 {
  405. b = append(b, '0')
  406. }
  407. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  408. b = append(b, ee.timeSeparator...)
  409. if t.Second() < 10 {
  410. b = append(b, '0')
  411. }
  412. b = strconv.AppendInt(b, int64(t.Second()), 10)
  413. b = append(b, []byte{0x20}...)
  414. tz, _ := t.Zone()
  415. if btz, ok := ee.timezones[tz]; ok {
  416. b = append(b, btz...)
  417. } else {
  418. b = append(b, tz...)
  419. }
  420. return string(b)
  421. }