el.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. package el
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type el 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 'el' locale
  42. func New() locales.Translator {
  43. return &el{
  44. locale: "el",
  45. pluralsCardinal: []locales.PluralRule{2, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: []locales.PluralRule{6, 2},
  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", "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 ", "Δρχ", "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", "$", "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{"", "Ιαν", "Φεβ", "Μαρ", "Απρ", "Μαΐ", "Ιουν", "Ιουλ", "Αυγ", "Σεπ", "Οκτ", "Νοε", "Δεκ"},
  60. monthsNarrow: []string{"", "Ι", "Φ", "Μ", "Α", "Μ", "Ι", "Ι", "Α", "Σ", "Ο", "Ν", "Δ"},
  61. monthsWide: []string{"", "Ιανουαρίου", "Φεβρουαρίου", "Μαρτίου", "Απριλίου", "Μαΐου", "Ιουνίου", "Ιουλίου", "Αυγούστου", "Σεπτεμβρίου", "Οκτωβρίου", "Νοεμβρίου", "Δεκεμβρίου"},
  62. daysAbbreviated: []string{"Κυρ", "Δευ", "Τρί", "Τετ", "Πέμ", "Παρ", "Σάβ"},
  63. daysNarrow: []string{"Κ", "Δ", "Τ", "Τ", "Π", "Π", "Σ"},
  64. daysShort: []string{"Κυ", "Δε", "Τρ", "Τε", "Πέ", "Πα", "Σά"},
  65. daysWide: []string{"Κυριακή", "Δευτέρα", "Τρίτη", "Τετάρτη", "Πέμπτη", "Παρασκευή", "Σάββατο"},
  66. periodsAbbreviated: []string{"π.μ.", "μ.μ."},
  67. periodsNarrow: []string{"πμ", "μμ"},
  68. periodsWide: []string{"π.μ.", "μ.μ."},
  69. erasAbbreviated: []string{"π.Χ.", "μ.Χ."},
  70. erasNarrow: []string{"", ""},
  71. erasWide: []string{"προ Χριστού", "μετά Χριστόν"},
  72. timezones: map[string]string{"MEZ": "Χειμερινή ώρα Κεντρικής Ευρώπης", "COST": "Θερινή ώρα Κολομβίας", "SGT": "Ώρα Σιγκαπούρης", "ART": "Χειμερινή ώρα Αργεντινής", "GYT": "Ώρα Γουιάνας", "WARST": "Θερινή ώρα Δυτικής Αργεντινής", "WIB": "Ώρα: Δυτική Ινδονησία", "LHST": "Χειμερινή ώρα Λορντ Χάου", "CLT": "Χειμερινή ώρα Χιλής", "SAST": "Χειμερινή ώρα Νότιας Αφρικής", "WAST": "Θερινή ώρα Δυτικής Αφρικής", "TMST": "Θερινή ώρα Τουρκμενιστάν", "OESZ": "Θερινή ώρα Ανατολικής Ευρώπης", "AKDT": "Θερινή ώρα Αλάσκας", "NZST": "Χειμερινή ώρα Νέας Ζηλανδίας", "CST": "Κεντρική χειμερινή ώρα Βόρειας Αμερικής", "ACWST": "Χειμερινή ώρα Κεντροδυτικής Αυστραλίας", "ACWDT": "Θερινή ώρα Κεντροδυτικής Αυστραλίας", "∅∅∅": "Θερινή ώρα Μπραζίλια", "PST": "Χειμερινή ώρα Βόρειας Αμερικής", "EST": "Ανατολική χειμερινή ώρα Βόρειας Αμερικής", "ADT": "Θερινή ώρα Ατλαντικού", "WART": "Χειμερινή ώρα Δυτικής Αργεντινής", "HADT": "Θερινή ώρα Χαβάης-Αλεούτιων νήσων", "HKT": "Χειμερινή ώρα Χονγκ Κονγκ", "ACST": "Χειμερινή ώρα Κεντρικής Αυστραλίας", "AWDT": "Θερινή ώρα Δυτικής Αυστραλίας", "AEST": "Χειμερινή ώρα Ανατολικής Αυστραλίας", "AEDT": "Θερινή ώρα Ανατολικής Αυστραλίας", "CHADT": "Θερινή ώρα Τσάθαμ", "VET": "Ώρα Βενεζουέλας", "GFT": "Ώρα Γαλλικής Γουιάνας", "JDT": "Θερινή ώρα Ιαπωνίας", "MDT": "Ορεινή θερινή ώρα Βόρειας Αμερικής", "WESZ": "Θερινή ώρα Δυτικής Ευρώπης", "CAT": "Ώρα Κεντρικής Αφρικής", "AST": "Χειμερινή ώρα Ατλαντικού", "WITA": "Ώρα: Κεντρική Ινδονησία", "EAT": "Ώρα Ανατολικής Αφρικής", "LHDT": "Θερινή ώρα Λορντ Χάου", "UYST": "Θερινή ώρα Ουρουγουάης", "MESZ": "Θερινή ώρα Κεντρικής Ευρώπης", "HKST": "Θερινή ώρα Χονγκ Κονγκ", "GMT": "Μέση ώρα Γκρίνουιτς", "HNT": "Χειμερινή ώρα Νέας Γης", "ARST": "Θερινή ώρα Αργεντινής", "WIT": "Ώρα: Ανατολική Ινδονησία", "OEZ": "Χειμερινή ώρα Ανατολικής Ευρώπης", "TMT": "Χειμερινή ώρα Τουρκμενιστάν", "MYT": "Ώρα Μαλαισίας", "ChST": "Ώρα Τσαμόρο", "MST": "Ορεινή χειμερινή ώρα Βόρειας Αμερικής", "WEZ": "Χειμερινή ώρα Δυτικής Ευρώπης", "WAT": "Χειμερινή ώρα Δυτικής Αφρικής", "JST": "Χειμερινή ώρα Ιαπωνίας", "PDT": "Θερινή ώρα Βόρειας Αμερικής", "HAST": "Χειμερινή ώρα Χαβάης-Αλεούτιων νήσων", "IST": "Ώρα Ινδίας", "SRT": "Ώρα Σουρινάμ", "UYT": "Χειμερινή ώρα Ουρουγουάης", "BT": "Ώρα Μπουτάν", "HAT": "Θερινή ώρα Νέας Γης", "AWST": "Χειμερινή ώρα Δυτικής Αυστραλίας", "NZDT": "Θερινή ώρα Νέας Ζηλανδίας", "CHAST": "Χειμερινή ώρα Τσάθαμ", "EDT": "Ανατολική θερινή ώρα Βόρειας Αμερικής", "AKST": "Χειμερινή ώρα Αλάσκας", "BOT": "Ώρα Βολιβίας", "CDT": "Κεντρική θερινή ώρα Βόρειας Αμερικής", "CLST": "Θερινή ώρα Χιλής", "COT": "Χειμερινή ώρα Κολομβίας", "ECT": "Ώρα Εκουαδόρ", "ACDT": "Θερινή ώρα Κεντρικής Αυστραλίας"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (el *el) Locale() string {
  77. return el.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'el'
  80. func (el *el) PluralsCardinal() []locales.PluralRule {
  81. return el.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'el'
  84. func (el *el) PluralsOrdinal() []locales.PluralRule {
  85. return el.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'el'
  88. func (el *el) PluralsRange() []locales.PluralRule {
  89. return el.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'el'
  92. func (el *el) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. if n == 1 {
  95. return locales.PluralRuleOne
  96. }
  97. return locales.PluralRuleOther
  98. }
  99. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'el'
  100. func (el *el) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  101. return locales.PluralRuleOther
  102. }
  103. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'el'
  104. func (el *el) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  105. start := el.CardinalPluralRule(num1, v1)
  106. end := el.CardinalPluralRule(num2, v2)
  107. if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  108. return locales.PluralRuleOther
  109. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  110. return locales.PluralRuleOne
  111. }
  112. return locales.PluralRuleOther
  113. }
  114. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  115. func (el *el) MonthAbbreviated(month time.Month) string {
  116. return el.monthsAbbreviated[month]
  117. }
  118. // MonthsAbbreviated returns the locales abbreviated months
  119. func (el *el) MonthsAbbreviated() []string {
  120. return el.monthsAbbreviated[1:]
  121. }
  122. // MonthNarrow returns the locales narrow month given the 'month' provided
  123. func (el *el) MonthNarrow(month time.Month) string {
  124. return el.monthsNarrow[month]
  125. }
  126. // MonthsNarrow returns the locales narrow months
  127. func (el *el) MonthsNarrow() []string {
  128. return el.monthsNarrow[1:]
  129. }
  130. // MonthWide returns the locales wide month given the 'month' provided
  131. func (el *el) MonthWide(month time.Month) string {
  132. return el.monthsWide[month]
  133. }
  134. // MonthsWide returns the locales wide months
  135. func (el *el) MonthsWide() []string {
  136. return el.monthsWide[1:]
  137. }
  138. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  139. func (el *el) WeekdayAbbreviated(weekday time.Weekday) string {
  140. return el.daysAbbreviated[weekday]
  141. }
  142. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  143. func (el *el) WeekdaysAbbreviated() []string {
  144. return el.daysAbbreviated
  145. }
  146. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  147. func (el *el) WeekdayNarrow(weekday time.Weekday) string {
  148. return el.daysNarrow[weekday]
  149. }
  150. // WeekdaysNarrow returns the locales narrow weekdays
  151. func (el *el) WeekdaysNarrow() []string {
  152. return el.daysNarrow
  153. }
  154. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  155. func (el *el) WeekdayShort(weekday time.Weekday) string {
  156. return el.daysShort[weekday]
  157. }
  158. // WeekdaysShort returns the locales short weekdays
  159. func (el *el) WeekdaysShort() []string {
  160. return el.daysShort
  161. }
  162. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  163. func (el *el) WeekdayWide(weekday time.Weekday) string {
  164. return el.daysWide[weekday]
  165. }
  166. // WeekdaysWide returns the locales wide weekdays
  167. func (el *el) WeekdaysWide() []string {
  168. return el.daysWide
  169. }
  170. // FmtNumber returns 'num' with digits/precision of 'v' for 'el' and handles both Whole and Real numbers based on 'v'
  171. func (el *el) FmtNumber(num float64, v uint64) string {
  172. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  173. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  174. count := 0
  175. inWhole := v == 0
  176. b := make([]byte, 0, l)
  177. for i := len(s) - 1; i >= 0; i-- {
  178. if s[i] == '.' {
  179. b = append(b, el.decimal[0])
  180. inWhole = true
  181. continue
  182. }
  183. if inWhole {
  184. if count == 3 {
  185. b = append(b, el.group[0])
  186. count = 1
  187. } else {
  188. count++
  189. }
  190. }
  191. b = append(b, s[i])
  192. }
  193. if num < 0 {
  194. b = append(b, el.minus[0])
  195. }
  196. // reverse
  197. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  198. b[i], b[j] = b[j], b[i]
  199. }
  200. return string(b)
  201. }
  202. // FmtPercent returns 'num' with digits/precision of 'v' for 'el' and handles both Whole and Real numbers based on 'v'
  203. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  204. func (el *el) FmtPercent(num float64, v uint64) string {
  205. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  206. l := len(s) + 3
  207. b := make([]byte, 0, l)
  208. for i := len(s) - 1; i >= 0; i-- {
  209. if s[i] == '.' {
  210. b = append(b, el.decimal[0])
  211. continue
  212. }
  213. b = append(b, s[i])
  214. }
  215. if num < 0 {
  216. b = append(b, el.minus[0])
  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, el.percent...)
  223. return string(b)
  224. }
  225. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'el'
  226. func (el *el) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  227. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  228. symbol := el.currencies[currency]
  229. l := len(s) + len(symbol) + 4 + 1*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, el.decimal[0])
  236. inWhole = true
  237. continue
  238. }
  239. if inWhole {
  240. if count == 3 {
  241. b = append(b, el.group[0])
  242. count = 1
  243. } else {
  244. count++
  245. }
  246. }
  247. b = append(b, s[i])
  248. }
  249. if num < 0 {
  250. b = append(b, el.minus[0])
  251. }
  252. // reverse
  253. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  254. b[i], b[j] = b[j], b[i]
  255. }
  256. if int(v) < 2 {
  257. if v == 0 {
  258. b = append(b, el.decimal...)
  259. }
  260. for i := 0; i < 2-int(v); i++ {
  261. b = append(b, '0')
  262. }
  263. }
  264. b = append(b, el.currencyPositiveSuffix...)
  265. b = append(b, symbol...)
  266. return string(b)
  267. }
  268. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'el'
  269. // in accounting notation.
  270. func (el *el) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  271. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  272. symbol := el.currencies[currency]
  273. l := len(s) + len(symbol) + 6 + 1*len(s[:len(s)-int(v)-1])/3
  274. count := 0
  275. inWhole := v == 0
  276. b := make([]byte, 0, l)
  277. for i := len(s) - 1; i >= 0; i-- {
  278. if s[i] == '.' {
  279. b = append(b, el.decimal[0])
  280. inWhole = true
  281. continue
  282. }
  283. if inWhole {
  284. if count == 3 {
  285. b = append(b, el.group[0])
  286. count = 1
  287. } else {
  288. count++
  289. }
  290. }
  291. b = append(b, s[i])
  292. }
  293. if num < 0 {
  294. b = append(b, el.currencyNegativePrefix[0])
  295. }
  296. // reverse
  297. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  298. b[i], b[j] = b[j], b[i]
  299. }
  300. if int(v) < 2 {
  301. if v == 0 {
  302. b = append(b, el.decimal...)
  303. }
  304. for i := 0; i < 2-int(v); i++ {
  305. b = append(b, '0')
  306. }
  307. }
  308. if num < 0 {
  309. b = append(b, el.currencyNegativeSuffix...)
  310. b = append(b, symbol...)
  311. } else {
  312. b = append(b, el.currencyPositiveSuffix...)
  313. b = append(b, symbol...)
  314. }
  315. return string(b)
  316. }
  317. // FmtDateShort returns the short date representation of 't' for 'el'
  318. func (el *el) FmtDateShort(t time.Time) string {
  319. b := make([]byte, 0, 32)
  320. b = strconv.AppendInt(b, int64(t.Day()), 10)
  321. b = append(b, []byte{0x2f}...)
  322. b = strconv.AppendInt(b, int64(t.Month()), 10)
  323. b = append(b, []byte{0x2f}...)
  324. if t.Year() > 9 {
  325. b = append(b, strconv.Itoa(t.Year())[2:]...)
  326. } else {
  327. b = append(b, strconv.Itoa(t.Year())[1:]...)
  328. }
  329. return string(b)
  330. }
  331. // FmtDateMedium returns the medium date representation of 't' for 'el'
  332. func (el *el) FmtDateMedium(t time.Time) string {
  333. b := make([]byte, 0, 32)
  334. b = strconv.AppendInt(b, int64(t.Day()), 10)
  335. b = append(b, []byte{0x20}...)
  336. b = append(b, el.monthsAbbreviated[t.Month()]...)
  337. b = append(b, []byte{0x20}...)
  338. b = strconv.AppendInt(b, int64(t.Year()), 10)
  339. return string(b)
  340. }
  341. // FmtDateLong returns the long date representation of 't' for 'el'
  342. func (el *el) FmtDateLong(t time.Time) string {
  343. b := make([]byte, 0, 32)
  344. b = strconv.AppendInt(b, int64(t.Day()), 10)
  345. b = append(b, []byte{0x20}...)
  346. b = append(b, el.monthsWide[t.Month()]...)
  347. b = append(b, []byte{0x20}...)
  348. b = strconv.AppendInt(b, int64(t.Year()), 10)
  349. return string(b)
  350. }
  351. // FmtDateFull returns the full date representation of 't' for 'el'
  352. func (el *el) FmtDateFull(t time.Time) string {
  353. b := make([]byte, 0, 32)
  354. b = append(b, el.daysWide[t.Weekday()]...)
  355. b = append(b, []byte{0x2c, 0x20}...)
  356. b = strconv.AppendInt(b, int64(t.Day()), 10)
  357. b = append(b, []byte{0x20}...)
  358. b = append(b, el.monthsWide[t.Month()]...)
  359. b = append(b, []byte{0x20}...)
  360. b = strconv.AppendInt(b, int64(t.Year()), 10)
  361. return string(b)
  362. }
  363. // FmtTimeShort returns the short time representation of 't' for 'el'
  364. func (el *el) FmtTimeShort(t time.Time) string {
  365. b := make([]byte, 0, 32)
  366. h := t.Hour()
  367. if h > 12 {
  368. h -= 12
  369. }
  370. b = strconv.AppendInt(b, int64(h), 10)
  371. b = append(b, el.timeSeparator...)
  372. if t.Minute() < 10 {
  373. b = append(b, '0')
  374. }
  375. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  376. b = append(b, []byte{0x20}...)
  377. if t.Hour() < 12 {
  378. b = append(b, el.periodsAbbreviated[0]...)
  379. } else {
  380. b = append(b, el.periodsAbbreviated[1]...)
  381. }
  382. return string(b)
  383. }
  384. // FmtTimeMedium returns the medium time representation of 't' for 'el'
  385. func (el *el) FmtTimeMedium(t time.Time) string {
  386. b := make([]byte, 0, 32)
  387. h := t.Hour()
  388. if h > 12 {
  389. h -= 12
  390. }
  391. b = strconv.AppendInt(b, int64(h), 10)
  392. b = append(b, el.timeSeparator...)
  393. if t.Minute() < 10 {
  394. b = append(b, '0')
  395. }
  396. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  397. b = append(b, el.timeSeparator...)
  398. if t.Second() < 10 {
  399. b = append(b, '0')
  400. }
  401. b = strconv.AppendInt(b, int64(t.Second()), 10)
  402. b = append(b, []byte{0x20}...)
  403. if t.Hour() < 12 {
  404. b = append(b, el.periodsAbbreviated[0]...)
  405. } else {
  406. b = append(b, el.periodsAbbreviated[1]...)
  407. }
  408. return string(b)
  409. }
  410. // FmtTimeLong returns the long time representation of 't' for 'el'
  411. func (el *el) FmtTimeLong(t time.Time) string {
  412. b := make([]byte, 0, 32)
  413. h := t.Hour()
  414. if h > 12 {
  415. h -= 12
  416. }
  417. b = strconv.AppendInt(b, int64(h), 10)
  418. b = append(b, el.timeSeparator...)
  419. if t.Minute() < 10 {
  420. b = append(b, '0')
  421. }
  422. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  423. b = append(b, el.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. if t.Hour() < 12 {
  430. b = append(b, el.periodsAbbreviated[0]...)
  431. } else {
  432. b = append(b, el.periodsAbbreviated[1]...)
  433. }
  434. b = append(b, []byte{0x20}...)
  435. tz, _ := t.Zone()
  436. b = append(b, tz...)
  437. return string(b)
  438. }
  439. // FmtTimeFull returns the full time representation of 't' for 'el'
  440. func (el *el) FmtTimeFull(t time.Time) string {
  441. b := make([]byte, 0, 32)
  442. h := t.Hour()
  443. if h > 12 {
  444. h -= 12
  445. }
  446. b = strconv.AppendInt(b, int64(h), 10)
  447. b = append(b, el.timeSeparator...)
  448. if t.Minute() < 10 {
  449. b = append(b, '0')
  450. }
  451. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  452. b = append(b, el.timeSeparator...)
  453. if t.Second() < 10 {
  454. b = append(b, '0')
  455. }
  456. b = strconv.AppendInt(b, int64(t.Second()), 10)
  457. b = append(b, []byte{0x20}...)
  458. if t.Hour() < 12 {
  459. b = append(b, el.periodsAbbreviated[0]...)
  460. } else {
  461. b = append(b, el.periodsAbbreviated[1]...)
  462. }
  463. b = append(b, []byte{0x20}...)
  464. tz, _ := t.Zone()
  465. if btz, ok := el.timezones[tz]; ok {
  466. b = append(b, btz...)
  467. } else {
  468. b = append(b, tz...)
  469. }
  470. return string(b)
  471. }