1package el 2 3import ( 4 "math" 5 "strconv" 6 "time" 7 8 "github.com/go-playground/locales" 9 "github.com/go-playground/locales/currency" 10) 11 12type el struct { 13 locale string 14 pluralsCardinal []locales.PluralRule 15 pluralsOrdinal []locales.PluralRule 16 pluralsRange []locales.PluralRule 17 decimal string 18 group string 19 minus string 20 percent string 21 perMille string 22 timeSeparator string 23 inifinity string 24 currencies []string // idx = enum of currency code 25 currencyPositiveSuffix string 26 currencyNegativeSuffix string 27 monthsAbbreviated []string 28 monthsNarrow []string 29 monthsWide []string 30 daysAbbreviated []string 31 daysNarrow []string 32 daysShort []string 33 daysWide []string 34 periodsAbbreviated []string 35 periodsNarrow []string 36 periodsShort []string 37 periodsWide []string 38 erasAbbreviated []string 39 erasNarrow []string 40 erasWide []string 41 timezones map[string]string 42} 43 44// New returns a new instance of translator for the 'el' locale 45func New() locales.Translator { 46 return &el{ 47 locale: "el", 48 pluralsCardinal: []locales.PluralRule{2, 6}, 49 pluralsOrdinal: []locales.PluralRule{6}, 50 pluralsRange: []locales.PluralRule{2, 6}, 51 decimal: ",", 52 group: ".", 53 minus: "-", 54 percent: "%", 55 perMille: "‰", 56 timeSeparator: ":", 57 inifinity: "∞", 58 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", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "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", "STN", "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"}, 59 currencyPositiveSuffix: " ", 60 currencyNegativeSuffix: " ", 61 monthsAbbreviated: []string{"", "Ιαν", "Φεβ", "Μαρ", "Απρ", "Μαΐ", "Ιουν", "Ιουλ", "Αυγ", "Σεπ", "Οκτ", "Νοε", "Δεκ"}, 62 monthsNarrow: []string{"", "Ι", "Φ", "Μ", "Α", "Μ", "Ι", "Ι", "Α", "Σ", "Ο", "Ν", "Δ"}, 63 monthsWide: []string{"", "Ιανουαρίου", "Φεβρουαρίου", "Μαρτίου", "Απριλίου", "Μαΐου", "Ιουνίου", "Ιουλίου", "Αυγούστου", "Σεπτεμβρίου", "Οκτωβρίου", "Νοεμβρίου", "Δεκεμβρίου"}, 64 daysAbbreviated: []string{"Κυρ", "Δευ", "Τρί", "Τετ", "Πέμ", "Παρ", "Σάβ"}, 65 daysNarrow: []string{"Κ", "Δ", "Τ", "Τ", "Π", "Π", "Σ"}, 66 daysShort: []string{"Κυ", "Δε", "Τρ", "Τε", "Πέ", "Πα", "Σά"}, 67 daysWide: []string{"Κυριακή", "Δευτέρα", "Τρίτη", "Τετάρτη", "Πέμπτη", "Παρασκευή", "Σάββατο"}, 68 periodsAbbreviated: []string{"π.μ.", "μ.μ."}, 69 periodsNarrow: []string{"πμ", "μμ"}, 70 periodsWide: []string{"π.μ.", "μ.μ."}, 71 erasAbbreviated: []string{"π.Χ.", "μ.Χ."}, 72 erasNarrow: []string{"", ""}, 73 erasWide: []string{"προ Χριστού", "μετά Χριστόν"}, 74 timezones: map[string]string{"AKST": "Χειμερινή ώρα Αλάσκας", "ACDT": "Θερινή ώρα Κεντρικής Αυστραλίας", "MEZ": "Χειμερινή ώρα Κεντρικής Ευρώπης", "COT": "Χειμερινή ώρα Κολομβίας", "AST": "Χειμερινή ώρα Ατλαντικού", "HNOG": "Χειμερινή ώρα Δυτικής Γροιλανδίας", "EST": "Ανατολική χειμερινή ώρα Βόρειας Αμερικής", "WART": "Χειμερινή ώρα Δυτικής Αργεντινής", "MYT": "Ώρα Μαλαισίας", "JDT": "Θερινή ώρα Ιαπωνίας", "ECT": "Ώρα Ισημερινού", "ACST": "Χειμερινή ώρα Κεντρικής Αυστραλίας", "ACWDT": "Θερινή ώρα Κεντροδυτικής Αυστραλίας", "LHDT": "Θερινή ώρα Λορντ Χάου", "HNPM": "Χειμερινή ώρα Σεν Πιερ και Μικελόν", "ARST": "Θερινή ώρα Αργεντινής", "WESZ": "Θερινή ώρα Δυτικής Ευρώπης", "CDT": "Κεντρική θερινή ώρα Βόρειας Αμερικής", "UYST": "Θερινή ώρα Ουρουγουάης", "HEPM": "Θερινή ώρα Σεν Πιερ και Μικελόν", "CHADT": "Θερινή ώρα Τσάταμ", "HEPMX": "Θερινή ώρα Ειρηνικού Μεξικού", "HEOG": "Θερινή ώρα Δυτικής Γροιλανδίας", "OEZ": "Χειμερινή ώρα Ανατολικής Ευρώπης", "GYT": "Ώρα Γουιάνας", "ChST": "Ώρα Τσαμόρο", "HNCU": "Χειμερινή ώρα Κούβας", "CLT": "Χειμερινή ώρα Χιλής", "WAT": "Χειμερινή ώρα Δυτικής Αφρικής", "EDT": "Ανατολική θερινή ώρα Βόρειας Αμερικής", "CLST": "Θερινή ώρα Χιλής", "COST": "Θερινή ώρα Κολομβίας", "CHAST": "Χειμερινή ώρα Τσάταμ", "∅∅∅": "∅∅∅", "WEZ": "Χειμερινή ώρα Δυτικής Ευρώπης", "HEEG": "Θερινή ώρα Ανατολικής Γροιλανδίας", "MESZ": "Θερινή ώρα Κεντρικής Ευρώπης", "OESZ": "Θερινή ώρα Ανατολικής Ευρώπης", "HNPMX": "Χειμερινή ώρα Ειρηνικού Μεξικού", "AEST": "Χειμερινή ώρα Ανατολικής Αυστραλίας", "HNEG": "Χειμερινή ώρα Ανατολικής Γροιλανδίας", "CAT": "Ώρα Κεντρικής Αφρικής", "HAST": "Χειμερινή ώρα Χαβάης-Αλεούτιων Νήσων", "HADT": "Θερινή ώρα Χαβάης-Αλεούτιων Νήσων", "AEDT": "Θερινή ώρα Ανατολικής Αυστραλίας", "BOT": "Ώρα Βολιβίας", "NZDT": "Θερινή ώρα Νέας Ζηλανδίας", "TMST": "Θερινή ώρα Τουρκμενιστάν", "MDT": "Ορεινή θερινή ώρα Βόρειας Αμερικής", "ACWST": "Χειμερινή ώρα Κεντροδυτικής Αυστραλίας", "WITA": "Ώρα Κεντρικής Ινδονησίας", "HNNOMX": "Χειμερινή ώρα Βορειοδυτικού Μεξικού", "TMT": "Χειμερινή ώρα Τουρκμενιστάν", "WAST": "Θερινή ώρα Δυτικής Αφρικής", "JST": "Χειμερινή ώρα Ιαπωνίας", "WARST": "Θερινή ώρα Δυτικής Αργεντινής", "SRT": "Ώρα Σουρινάμ", "UYT": "Χειμερινή ώρα Ουρουγουάης", "PDT": "Θερινή ώρα Ειρηνικού", "SAST": "Χειμερινή ώρα Νότιας Αφρικής", "HNT": "Χειμερινή ώρα Νέας Γης", "VET": "Ώρα Βενεζουέλας", "HENOMX": "Θερινή ώρα Βορειοδυτικού Μεξικού", "AWST": "Χειμερινή ώρα Δυτικής Αυστραλίας", "AKDT": "Θερινή ώρα Αλάσκας", "IST": "Ώρα Ινδίας", "HAT": "Θερινή ώρα Νέας Γης", "PST": "Χειμερινή ώρα Ειρηνικού", "BT": "Ώρα Μπουτάν", "WIB": "Ώρα Δυτικής Ινδονησίας", "GFT": "Ώρα Γαλλικής Γουιάνας", "NZST": "Χειμερινή ώρα Νέας Ζηλανδίας", "HKT": "Χειμερινή ώρα Χονγκ Κονγκ", "HKST": "Θερινή ώρα Χονγκ Κονγκ", "WIT": "Ώρα Ανατολικής Ινδονησίας", "MST": "Ορεινή χειμερινή ώρα Βόρειας Αμερικής", "LHST": "Χειμερινή ώρα Λορντ Χάου", "EAT": "Ώρα Ανατολικής Αφρικής", "AWDT": "Θερινή ώρα Δυτικής Αυστραλίας", "SGT": "Ώρα Σιγκαπούρης", "ART": "Χειμερινή ώρα Αργεντινής", "GMT": "Μέση ώρα Γκρίνουιτς", "HECU": "Θερινή ώρα Κούβας", "CST": "Κεντρική χειμερινή ώρα Βόρειας Αμερικής", "ADT": "Θερινή ώρα Ατλαντικού"}, 75 } 76} 77 78// Locale returns the current translators string locale 79func (el *el) Locale() string { 80 return el.locale 81} 82 83// PluralsCardinal returns the list of cardinal plural rules associated with 'el' 84func (el *el) PluralsCardinal() []locales.PluralRule { 85 return el.pluralsCardinal 86} 87 88// PluralsOrdinal returns the list of ordinal plural rules associated with 'el' 89func (el *el) PluralsOrdinal() []locales.PluralRule { 90 return el.pluralsOrdinal 91} 92 93// PluralsRange returns the list of range plural rules associated with 'el' 94func (el *el) PluralsRange() []locales.PluralRule { 95 return el.pluralsRange 96} 97 98// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'el' 99func (el *el) CardinalPluralRule(num float64, v uint64) locales.PluralRule { 100 101 n := math.Abs(num) 102 103 if n == 1 { 104 return locales.PluralRuleOne 105 } 106 107 return locales.PluralRuleOther 108} 109 110// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'el' 111func (el *el) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 112 return locales.PluralRuleOther 113} 114 115// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'el' 116func (el *el) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 117 118 start := el.CardinalPluralRule(num1, v1) 119 end := el.CardinalPluralRule(num2, v2) 120 121 if start == locales.PluralRuleOne && end == locales.PluralRuleOther { 122 return locales.PluralRuleOther 123 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne { 124 return locales.PluralRuleOne 125 } 126 127 return locales.PluralRuleOther 128 129} 130 131// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 132func (el *el) MonthAbbreviated(month time.Month) string { 133 return el.monthsAbbreviated[month] 134} 135 136// MonthsAbbreviated returns the locales abbreviated months 137func (el *el) MonthsAbbreviated() []string { 138 return el.monthsAbbreviated[1:] 139} 140 141// MonthNarrow returns the locales narrow month given the 'month' provided 142func (el *el) MonthNarrow(month time.Month) string { 143 return el.monthsNarrow[month] 144} 145 146// MonthsNarrow returns the locales narrow months 147func (el *el) MonthsNarrow() []string { 148 return el.monthsNarrow[1:] 149} 150 151// MonthWide returns the locales wide month given the 'month' provided 152func (el *el) MonthWide(month time.Month) string { 153 return el.monthsWide[month] 154} 155 156// MonthsWide returns the locales wide months 157func (el *el) MonthsWide() []string { 158 return el.monthsWide[1:] 159} 160 161// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 162func (el *el) WeekdayAbbreviated(weekday time.Weekday) string { 163 return el.daysAbbreviated[weekday] 164} 165 166// WeekdaysAbbreviated returns the locales abbreviated weekdays 167func (el *el) WeekdaysAbbreviated() []string { 168 return el.daysAbbreviated 169} 170 171// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 172func (el *el) WeekdayNarrow(weekday time.Weekday) string { 173 return el.daysNarrow[weekday] 174} 175 176// WeekdaysNarrow returns the locales narrow weekdays 177func (el *el) WeekdaysNarrow() []string { 178 return el.daysNarrow 179} 180 181// WeekdayShort returns the locales short weekday given the 'weekday' provided 182func (el *el) WeekdayShort(weekday time.Weekday) string { 183 return el.daysShort[weekday] 184} 185 186// WeekdaysShort returns the locales short weekdays 187func (el *el) WeekdaysShort() []string { 188 return el.daysShort 189} 190 191// WeekdayWide returns the locales wide weekday given the 'weekday' provided 192func (el *el) WeekdayWide(weekday time.Weekday) string { 193 return el.daysWide[weekday] 194} 195 196// WeekdaysWide returns the locales wide weekdays 197func (el *el) WeekdaysWide() []string { 198 return el.daysWide 199} 200 201// Decimal returns the decimal point of number 202func (el *el) Decimal() string { 203 return el.decimal 204} 205 206// Group returns the group of number 207func (el *el) Group() string { 208 return el.group 209} 210 211// Group returns the minus sign of number 212func (el *el) Minus() string { 213 return el.minus 214} 215 216// FmtNumber returns 'num' with digits/precision of 'v' for 'el' and handles both Whole and Real numbers based on 'v' 217func (el *el) FmtNumber(num float64, v uint64) string { 218 219 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 220 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3 221 count := 0 222 inWhole := v == 0 223 b := make([]byte, 0, l) 224 225 for i := len(s) - 1; i >= 0; i-- { 226 227 if s[i] == '.' { 228 b = append(b, el.decimal[0]) 229 inWhole = true 230 continue 231 } 232 233 if inWhole { 234 if count == 3 { 235 b = append(b, el.group[0]) 236 count = 1 237 } else { 238 count++ 239 } 240 } 241 242 b = append(b, s[i]) 243 } 244 245 if num < 0 { 246 b = append(b, el.minus[0]) 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 254 return string(b) 255} 256 257// FmtPercent returns 'num' with digits/precision of 'v' for 'el' and handles both Whole and Real numbers based on 'v' 258// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 259func (el *el) FmtPercent(num float64, v uint64) string { 260 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 261 l := len(s) + 3 262 b := make([]byte, 0, l) 263 264 for i := len(s) - 1; i >= 0; i-- { 265 266 if s[i] == '.' { 267 b = append(b, el.decimal[0]) 268 continue 269 } 270 271 b = append(b, s[i]) 272 } 273 274 if num < 0 { 275 b = append(b, el.minus[0]) 276 } 277 278 // reverse 279 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 280 b[i], b[j] = b[j], b[i] 281 } 282 283 b = append(b, el.percent...) 284 285 return string(b) 286} 287 288// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'el' 289func (el *el) FmtCurrency(num float64, v uint64, currency currency.Type) string { 290 291 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 292 symbol := el.currencies[currency] 293 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 294 count := 0 295 inWhole := v == 0 296 b := make([]byte, 0, l) 297 298 for i := len(s) - 1; i >= 0; i-- { 299 300 if s[i] == '.' { 301 b = append(b, el.decimal[0]) 302 inWhole = true 303 continue 304 } 305 306 if inWhole { 307 if count == 3 { 308 b = append(b, el.group[0]) 309 count = 1 310 } else { 311 count++ 312 } 313 } 314 315 b = append(b, s[i]) 316 } 317 318 if num < 0 { 319 b = append(b, el.minus[0]) 320 } 321 322 // reverse 323 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 324 b[i], b[j] = b[j], b[i] 325 } 326 327 if int(v) < 2 { 328 329 if v == 0 { 330 b = append(b, el.decimal...) 331 } 332 333 for i := 0; i < 2-int(v); i++ { 334 b = append(b, '0') 335 } 336 } 337 338 b = append(b, el.currencyPositiveSuffix...) 339 340 b = append(b, symbol...) 341 342 return string(b) 343} 344 345// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'el' 346// in accounting notation. 347func (el *el) FmtAccounting(num float64, v uint64, currency currency.Type) string { 348 349 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 350 symbol := el.currencies[currency] 351 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 352 count := 0 353 inWhole := v == 0 354 b := make([]byte, 0, l) 355 356 for i := len(s) - 1; i >= 0; i-- { 357 358 if s[i] == '.' { 359 b = append(b, el.decimal[0]) 360 inWhole = true 361 continue 362 } 363 364 if inWhole { 365 if count == 3 { 366 b = append(b, el.group[0]) 367 count = 1 368 } else { 369 count++ 370 } 371 } 372 373 b = append(b, s[i]) 374 } 375 376 if num < 0 { 377 378 b = append(b, el.minus[0]) 379 380 } 381 382 // reverse 383 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 384 b[i], b[j] = b[j], b[i] 385 } 386 387 if int(v) < 2 { 388 389 if v == 0 { 390 b = append(b, el.decimal...) 391 } 392 393 for i := 0; i < 2-int(v); i++ { 394 b = append(b, '0') 395 } 396 } 397 398 if num < 0 { 399 b = append(b, el.currencyNegativeSuffix...) 400 b = append(b, symbol...) 401 } else { 402 403 b = append(b, el.currencyPositiveSuffix...) 404 b = append(b, symbol...) 405 } 406 407 return string(b) 408} 409 410// FmtDateShort returns the short date representation of 't' for 'el' 411func (el *el) FmtDateShort(t time.Time) string { 412 413 b := make([]byte, 0, 32) 414 415 b = strconv.AppendInt(b, int64(t.Day()), 10) 416 b = append(b, []byte{0x2f}...) 417 b = strconv.AppendInt(b, int64(t.Month()), 10) 418 b = append(b, []byte{0x2f}...) 419 420 if t.Year() > 9 { 421 b = append(b, strconv.Itoa(t.Year())[2:]...) 422 } else { 423 b = append(b, strconv.Itoa(t.Year())[1:]...) 424 } 425 426 return string(b) 427} 428 429// FmtDateMedium returns the medium date representation of 't' for 'el' 430func (el *el) FmtDateMedium(t time.Time) string { 431 432 b := make([]byte, 0, 32) 433 434 b = strconv.AppendInt(b, int64(t.Day()), 10) 435 b = append(b, []byte{0x20}...) 436 b = append(b, el.monthsAbbreviated[t.Month()]...) 437 b = append(b, []byte{0x20}...) 438 439 if t.Year() > 0 { 440 b = strconv.AppendInt(b, int64(t.Year()), 10) 441 } else { 442 b = strconv.AppendInt(b, int64(-t.Year()), 10) 443 } 444 445 return string(b) 446} 447 448// FmtDateLong returns the long date representation of 't' for 'el' 449func (el *el) FmtDateLong(t time.Time) string { 450 451 b := make([]byte, 0, 32) 452 453 b = strconv.AppendInt(b, int64(t.Day()), 10) 454 b = append(b, []byte{0x20}...) 455 b = append(b, el.monthsWide[t.Month()]...) 456 b = append(b, []byte{0x20}...) 457 458 if t.Year() > 0 { 459 b = strconv.AppendInt(b, int64(t.Year()), 10) 460 } else { 461 b = strconv.AppendInt(b, int64(-t.Year()), 10) 462 } 463 464 return string(b) 465} 466 467// FmtDateFull returns the full date representation of 't' for 'el' 468func (el *el) FmtDateFull(t time.Time) string { 469 470 b := make([]byte, 0, 32) 471 472 b = append(b, el.daysWide[t.Weekday()]...) 473 b = append(b, []byte{0x2c, 0x20}...) 474 b = strconv.AppendInt(b, int64(t.Day()), 10) 475 b = append(b, []byte{0x20}...) 476 b = append(b, el.monthsWide[t.Month()]...) 477 b = append(b, []byte{0x20}...) 478 479 if t.Year() > 0 { 480 b = strconv.AppendInt(b, int64(t.Year()), 10) 481 } else { 482 b = strconv.AppendInt(b, int64(-t.Year()), 10) 483 } 484 485 return string(b) 486} 487 488// FmtTimeShort returns the short time representation of 't' for 'el' 489func (el *el) FmtTimeShort(t time.Time) string { 490 491 b := make([]byte, 0, 32) 492 493 h := t.Hour() 494 495 if h > 12 { 496 h -= 12 497 } 498 499 b = strconv.AppendInt(b, int64(h), 10) 500 b = append(b, el.timeSeparator...) 501 502 if t.Minute() < 10 { 503 b = append(b, '0') 504 } 505 506 b = strconv.AppendInt(b, int64(t.Minute()), 10) 507 b = append(b, []byte{0x20}...) 508 509 if t.Hour() < 12 { 510 b = append(b, el.periodsAbbreviated[0]...) 511 } else { 512 b = append(b, el.periodsAbbreviated[1]...) 513 } 514 515 return string(b) 516} 517 518// FmtTimeMedium returns the medium time representation of 't' for 'el' 519func (el *el) FmtTimeMedium(t time.Time) string { 520 521 b := make([]byte, 0, 32) 522 523 h := t.Hour() 524 525 if h > 12 { 526 h -= 12 527 } 528 529 b = strconv.AppendInt(b, int64(h), 10) 530 b = append(b, el.timeSeparator...) 531 532 if t.Minute() < 10 { 533 b = append(b, '0') 534 } 535 536 b = strconv.AppendInt(b, int64(t.Minute()), 10) 537 b = append(b, el.timeSeparator...) 538 539 if t.Second() < 10 { 540 b = append(b, '0') 541 } 542 543 b = strconv.AppendInt(b, int64(t.Second()), 10) 544 b = append(b, []byte{0x20}...) 545 546 if t.Hour() < 12 { 547 b = append(b, el.periodsAbbreviated[0]...) 548 } else { 549 b = append(b, el.periodsAbbreviated[1]...) 550 } 551 552 return string(b) 553} 554 555// FmtTimeLong returns the long time representation of 't' for 'el' 556func (el *el) FmtTimeLong(t time.Time) string { 557 558 b := make([]byte, 0, 32) 559 560 h := t.Hour() 561 562 if h > 12 { 563 h -= 12 564 } 565 566 b = strconv.AppendInt(b, int64(h), 10) 567 b = append(b, el.timeSeparator...) 568 569 if t.Minute() < 10 { 570 b = append(b, '0') 571 } 572 573 b = strconv.AppendInt(b, int64(t.Minute()), 10) 574 b = append(b, el.timeSeparator...) 575 576 if t.Second() < 10 { 577 b = append(b, '0') 578 } 579 580 b = strconv.AppendInt(b, int64(t.Second()), 10) 581 b = append(b, []byte{0x20}...) 582 583 if t.Hour() < 12 { 584 b = append(b, el.periodsAbbreviated[0]...) 585 } else { 586 b = append(b, el.periodsAbbreviated[1]...) 587 } 588 589 b = append(b, []byte{0x20}...) 590 591 tz, _ := t.Zone() 592 b = append(b, tz...) 593 594 return string(b) 595} 596 597// FmtTimeFull returns the full time representation of 't' for 'el' 598func (el *el) FmtTimeFull(t time.Time) string { 599 600 b := make([]byte, 0, 32) 601 602 h := t.Hour() 603 604 if h > 12 { 605 h -= 12 606 } 607 608 b = strconv.AppendInt(b, int64(h), 10) 609 b = append(b, el.timeSeparator...) 610 611 if t.Minute() < 10 { 612 b = append(b, '0') 613 } 614 615 b = strconv.AppendInt(b, int64(t.Minute()), 10) 616 b = append(b, el.timeSeparator...) 617 618 if t.Second() < 10 { 619 b = append(b, '0') 620 } 621 622 b = strconv.AppendInt(b, int64(t.Second()), 10) 623 b = append(b, []byte{0x20}...) 624 625 if t.Hour() < 12 { 626 b = append(b, el.periodsAbbreviated[0]...) 627 } else { 628 b = append(b, el.periodsAbbreviated[1]...) 629 } 630 631 b = append(b, []byte{0x20}...) 632 633 tz, _ := t.Zone() 634 635 if btz, ok := el.timezones[tz]; ok { 636 b = append(b, btz...) 637 } else { 638 b = append(b, tz...) 639 } 640 641 return string(b) 642} 643