1package he 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 he 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 'he' locale 45func New() locales.Translator { 46 return &he{ 47 locale: "he", 48 pluralsCardinal: []locales.PluralRule{2, 3, 5, 6}, 49 pluralsOrdinal: []locales.PluralRule{6}, 50 pluralsRange: []locales.PluralRule{5, 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", "\u200eCN¥\u200e", "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", "ל״י", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "¥", "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{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, 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{"CDT": "שעון מרכז ארה״ב (קיץ)", "HNPMX": "שעון מערב מקסיקו (חורף)", "AKST": "שעון אלסקה (חורף)", "WESZ": "שעון מערב אירופה (קיץ)", "ACDT": "שעון מרכז אוסטרליה (קיץ)", "HNOG": "שעון מערב גרינלנד (חורף)", "HKST": "שעון הונג קונג (קיץ)", "WITA": "שעון מרכז אינדונזיה", "AST": "שעון האוקיינוס האטלנטי (חורף)", "MYT": "שעון מלזיה", "SGT": "שעון סינגפור", "MEZ": "שעון מרכז אירופה (חורף)", "PST": "שעון מערב ארה״ב (חורף)", "AKDT": "שעון אלסקה (קיץ)", "HEEG": "שעון מזרח גרינלנד (קיץ)", "HNPM": "שעון סנט פייר ומיקלון (חורף)", "HAST": "שעון האיים האלאוטיים הוואי (חורף)", "NZDT": "שעון ניו זילנד (קיץ)", "HNEG": "שעון מזרח גרינלנד (חורף)", "WARST": "שעון מערב ארגנטינה (קיץ)", "COST": "שעון קולומביה (קיץ)", "HNNOMX": "שעון צפון-מערב מקסיקו (חורף)", "CHADT": "שעון צ׳טהאם (קיץ)", "NZST": "שעון ניו זילנד (חורף)", "BOT": "שעון בוליביה", "EDT": "שעון החוף המזרחי (קיץ)", "IST": "שעון הודו", "AWST": "שעון מערב אוסטרליה (חורף)", "HEPM": "שעון סנט פייר ומיקלון (קיץ)", "CLST": "שעון צ׳ילה (קיץ)", "GMT": "שעון גריניץ׳\u200f", "HKT": "שעון הונג קונג (חורף)", "WART": "שעון מערב ארגנטינה (חורף)", "SRT": "שעון סורינאם", "MDT": "שעון אזור ההרים בארה״ב (קיץ)", "WAT": "שעון מערב אפריקה (חורף)", "WEZ": "שעון מערב אירופה (חורף)", "JST": "שעון יפן (חורף)", "EST": "שעון החוף המזרחי (חורף)", "CAT": "שעון מרכז אפריקה", "TMT": "שעון טורקמניסטן (חורף)", "COT": "שעון קולומביה (חורף)", "HEPMX": "שעון מערב מקסיקו (קיץ)", "ACWDT": "שעון מרכז-מערב אוסטרליה (קיץ)", "LHDT": "שעון אי הלורד האו (קיץ)", "UYT": "שעון אורוגוואי (חורף)", "UYST": "שעון אורוגוואי (קיץ)", "WAST": "שעון מערב אפריקה (קיץ)", "ACST": "שעון מרכז אוסטרליה (חורף)", "CLT": "שעון צ׳ילה (חורף)", "OEZ": "שעון מזרח אירופה (חורף)", "GYT": "שעון גיאנה", "HNT": "שעון ניופאונדלנד (חורף)", "HAT": "שעון ניופאונדלנד (קיץ)", "AWDT": "שעון מערב אוסטרליה (קיץ)", "WIB": "שעון מערב אינדונזיה", "HEOG": "שעון מערב גרינלנד (קיץ)", "MESZ": "שעון מרכז אירופה (קיץ)", "LHST": "שעון אי הלורד האו (חורף)", "VET": "שעון ונצואלה", "HENOMX": "שעון צפון-מערב מקסיקו (קיץ)", "TMST": "שעון טורקמניסטן (קיץ)", "CHAST": "שעון צ׳טהאם (חורף)", "HECU": "שעון קובה (קיץ)", "∅∅∅": "שעון ברזיליה (קיץ)", "MST": "שעון אזור ההרים בארה״ב (חורף)", "ACWST": "שעון מרכז-מערב אוסטרליה (חורף)", "EAT": "שעון מזרח אפריקה", "ARST": "שעון ארגנטינה (קיץ)", "OESZ": "שעון מזרח אירופה (קיץ)", "HNCU": "שעון קובה (חורף)", "PDT": "שעון מערב ארה״ב (קיץ)", "AEDT": "שעון מזרח אוסטרליה (קיץ)", "SAST": "שעון דרום אפריקה", "WIT": "שעון מזרח אינדונזיה", "JDT": "שעון יפן (קיץ)", "ECT": "שעון אקוודור", "HADT": "שעון האיים האלאוטיים הוואי (קיץ)", "ART": "שעון ארגנטינה (חורף)", "ChST": "שעון צ׳אמורו", "CST": "שעון מרכז ארה״ב (חורף)", "ADT": "שעון האוקיינוס האטלנטי (קיץ)", "AEST": "שעון מזרח אוסטרליה (חורף)", "BT": "שעון בהוטן", "GFT": "שעון גיאנה הצרפתית"}, 75 } 76} 77 78// Locale returns the current translators string locale 79func (he *he) Locale() string { 80 return he.locale 81} 82 83// PluralsCardinal returns the list of cardinal plural rules associated with 'he' 84func (he *he) PluralsCardinal() []locales.PluralRule { 85 return he.pluralsCardinal 86} 87 88// PluralsOrdinal returns the list of ordinal plural rules associated with 'he' 89func (he *he) PluralsOrdinal() []locales.PluralRule { 90 return he.pluralsOrdinal 91} 92 93// PluralsRange returns the list of range plural rules associated with 'he' 94func (he *he) PluralsRange() []locales.PluralRule { 95 return he.pluralsRange 96} 97 98// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'he' 99func (he *he) CardinalPluralRule(num float64, v uint64) locales.PluralRule { 100 101 n := math.Abs(num) 102 i := int64(n) 103 nMod10 := math.Mod(n, 10) 104 105 if i == 1 && v == 0 { 106 return locales.PluralRuleOne 107 } else if i == 2 && v == 0 { 108 return locales.PluralRuleTwo 109 } else if v == 0 && (n < 0 || n > 10) && nMod10 == 0 { 110 return locales.PluralRuleMany 111 } 112 113 return locales.PluralRuleOther 114} 115 116// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'he' 117func (he *he) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 118 return locales.PluralRuleOther 119} 120 121// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'he' 122func (he *he) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 123 124 start := he.CardinalPluralRule(num1, v1) 125 end := he.CardinalPluralRule(num2, v2) 126 127 if start == locales.PluralRuleOne && end == locales.PluralRuleTwo { 128 return locales.PluralRuleOther 129 } else if start == locales.PluralRuleOne && end == locales.PluralRuleMany { 130 return locales.PluralRuleMany 131 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther { 132 return locales.PluralRuleOther 133 } else if start == locales.PluralRuleTwo && end == locales.PluralRuleMany { 134 return locales.PluralRuleOther 135 } else if start == locales.PluralRuleTwo && end == locales.PluralRuleOther { 136 return locales.PluralRuleOther 137 } else if start == locales.PluralRuleMany && end == locales.PluralRuleMany { 138 return locales.PluralRuleMany 139 } else if start == locales.PluralRuleMany && end == locales.PluralRuleOther { 140 return locales.PluralRuleMany 141 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne { 142 return locales.PluralRuleOther 143 } else if start == locales.PluralRuleOther && end == locales.PluralRuleTwo { 144 return locales.PluralRuleOther 145 } else if start == locales.PluralRuleOther && end == locales.PluralRuleMany { 146 return locales.PluralRuleMany 147 } 148 149 return locales.PluralRuleOther 150 151} 152 153// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 154func (he *he) MonthAbbreviated(month time.Month) string { 155 return he.monthsAbbreviated[month] 156} 157 158// MonthsAbbreviated returns the locales abbreviated months 159func (he *he) MonthsAbbreviated() []string { 160 return he.monthsAbbreviated[1:] 161} 162 163// MonthNarrow returns the locales narrow month given the 'month' provided 164func (he *he) MonthNarrow(month time.Month) string { 165 return he.monthsNarrow[month] 166} 167 168// MonthsNarrow returns the locales narrow months 169func (he *he) MonthsNarrow() []string { 170 return he.monthsNarrow[1:] 171} 172 173// MonthWide returns the locales wide month given the 'month' provided 174func (he *he) MonthWide(month time.Month) string { 175 return he.monthsWide[month] 176} 177 178// MonthsWide returns the locales wide months 179func (he *he) MonthsWide() []string { 180 return he.monthsWide[1:] 181} 182 183// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 184func (he *he) WeekdayAbbreviated(weekday time.Weekday) string { 185 return he.daysAbbreviated[weekday] 186} 187 188// WeekdaysAbbreviated returns the locales abbreviated weekdays 189func (he *he) WeekdaysAbbreviated() []string { 190 return he.daysAbbreviated 191} 192 193// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 194func (he *he) WeekdayNarrow(weekday time.Weekday) string { 195 return he.daysNarrow[weekday] 196} 197 198// WeekdaysNarrow returns the locales narrow weekdays 199func (he *he) WeekdaysNarrow() []string { 200 return he.daysNarrow 201} 202 203// WeekdayShort returns the locales short weekday given the 'weekday' provided 204func (he *he) WeekdayShort(weekday time.Weekday) string { 205 return he.daysShort[weekday] 206} 207 208// WeekdaysShort returns the locales short weekdays 209func (he *he) WeekdaysShort() []string { 210 return he.daysShort 211} 212 213// WeekdayWide returns the locales wide weekday given the 'weekday' provided 214func (he *he) WeekdayWide(weekday time.Weekday) string { 215 return he.daysWide[weekday] 216} 217 218// WeekdaysWide returns the locales wide weekdays 219func (he *he) WeekdaysWide() []string { 220 return he.daysWide 221} 222 223// Decimal returns the decimal point of number 224func (he *he) Decimal() string { 225 return he.decimal 226} 227 228// Group returns the group of number 229func (he *he) Group() string { 230 return he.group 231} 232 233// Group returns the minus sign of number 234func (he *he) Minus() string { 235 return he.minus 236} 237 238// FmtNumber returns 'num' with digits/precision of 'v' for 'he' and handles both Whole and Real numbers based on 'v' 239func (he *he) FmtNumber(num float64, v uint64) string { 240 241 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 242 l := len(s) + 5 + 1*len(s[:len(s)-int(v)-1])/3 243 count := 0 244 inWhole := v == 0 245 b := make([]byte, 0, l) 246 247 for i := len(s) - 1; i >= 0; i-- { 248 249 if s[i] == '.' { 250 b = append(b, he.decimal[0]) 251 inWhole = true 252 continue 253 } 254 255 if inWhole { 256 if count == 3 { 257 b = append(b, he.group[0]) 258 count = 1 259 } else { 260 count++ 261 } 262 } 263 264 b = append(b, s[i]) 265 } 266 267 if num < 0 { 268 for j := len(he.minus) - 1; j >= 0; j-- { 269 b = append(b, he.minus[j]) 270 } 271 } 272 273 // reverse 274 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 275 b[i], b[j] = b[j], b[i] 276 } 277 278 return string(b) 279} 280 281// FmtPercent returns 'num' with digits/precision of 'v' for 'he' and handles both Whole and Real numbers based on 'v' 282// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 283func (he *he) FmtPercent(num float64, v uint64) string { 284 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 285 l := len(s) + 6 286 b := make([]byte, 0, l) 287 288 for i := len(s) - 1; i >= 0; i-- { 289 290 if s[i] == '.' { 291 b = append(b, he.decimal[0]) 292 continue 293 } 294 295 b = append(b, s[i]) 296 } 297 298 if num < 0 { 299 for j := len(he.minus) - 1; j >= 0; j-- { 300 b = append(b, he.minus[j]) 301 } 302 } 303 304 // reverse 305 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 306 b[i], b[j] = b[j], b[i] 307 } 308 309 b = append(b, he.percent...) 310 311 return string(b) 312} 313 314// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'he' 315func (he *he) FmtCurrency(num float64, v uint64, currency currency.Type) string { 316 317 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 318 symbol := he.currencies[currency] 319 l := len(s) + len(symbol) + 7 + 1*len(s[:len(s)-int(v)-1])/3 320 count := 0 321 inWhole := v == 0 322 b := make([]byte, 0, l) 323 324 for i := len(s) - 1; i >= 0; i-- { 325 326 if s[i] == '.' { 327 b = append(b, he.decimal[0]) 328 inWhole = true 329 continue 330 } 331 332 if inWhole { 333 if count == 3 { 334 b = append(b, he.group[0]) 335 count = 1 336 } else { 337 count++ 338 } 339 } 340 341 b = append(b, s[i]) 342 } 343 344 if num < 0 { 345 for j := len(he.minus) - 1; j >= 0; j-- { 346 b = append(b, he.minus[j]) 347 } 348 } 349 350 // reverse 351 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 352 b[i], b[j] = b[j], b[i] 353 } 354 355 if int(v) < 2 { 356 357 if v == 0 { 358 b = append(b, he.decimal...) 359 } 360 361 for i := 0; i < 2-int(v); i++ { 362 b = append(b, '0') 363 } 364 } 365 366 b = append(b, he.currencyPositiveSuffix...) 367 368 b = append(b, symbol...) 369 370 return string(b) 371} 372 373// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'he' 374// in accounting notation. 375func (he *he) FmtAccounting(num float64, v uint64, currency currency.Type) string { 376 377 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 378 symbol := he.currencies[currency] 379 l := len(s) + len(symbol) + 7 + 1*len(s[:len(s)-int(v)-1])/3 380 count := 0 381 inWhole := v == 0 382 b := make([]byte, 0, l) 383 384 for i := len(s) - 1; i >= 0; i-- { 385 386 if s[i] == '.' { 387 b = append(b, he.decimal[0]) 388 inWhole = true 389 continue 390 } 391 392 if inWhole { 393 if count == 3 { 394 b = append(b, he.group[0]) 395 count = 1 396 } else { 397 count++ 398 } 399 } 400 401 b = append(b, s[i]) 402 } 403 404 if num < 0 { 405 406 for j := len(he.minus) - 1; j >= 0; j-- { 407 b = append(b, he.minus[j]) 408 } 409 410 } 411 412 // reverse 413 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 414 b[i], b[j] = b[j], b[i] 415 } 416 417 if int(v) < 2 { 418 419 if v == 0 { 420 b = append(b, he.decimal...) 421 } 422 423 for i := 0; i < 2-int(v); i++ { 424 b = append(b, '0') 425 } 426 } 427 428 if num < 0 { 429 b = append(b, he.currencyNegativeSuffix...) 430 b = append(b, symbol...) 431 } else { 432 433 b = append(b, he.currencyPositiveSuffix...) 434 b = append(b, symbol...) 435 } 436 437 return string(b) 438} 439 440// FmtDateShort returns the short date representation of 't' for 'he' 441func (he *he) FmtDateShort(t time.Time) string { 442 443 b := make([]byte, 0, 32) 444 445 b = strconv.AppendInt(b, int64(t.Day()), 10) 446 b = append(b, []byte{0x2e}...) 447 b = strconv.AppendInt(b, int64(t.Month()), 10) 448 b = append(b, []byte{0x2e}...) 449 450 if t.Year() > 0 { 451 b = strconv.AppendInt(b, int64(t.Year()), 10) 452 } else { 453 b = strconv.AppendInt(b, int64(-t.Year()), 10) 454 } 455 456 return string(b) 457} 458 459// FmtDateMedium returns the medium date representation of 't' for 'he' 460func (he *he) FmtDateMedium(t time.Time) string { 461 462 b := make([]byte, 0, 32) 463 464 b = strconv.AppendInt(b, int64(t.Day()), 10) 465 b = append(b, []byte{0x20, 0xd7, 0x91}...) 466 b = append(b, he.monthsAbbreviated[t.Month()]...) 467 b = append(b, []byte{0x20}...) 468 469 if t.Year() > 0 { 470 b = strconv.AppendInt(b, int64(t.Year()), 10) 471 } else { 472 b = strconv.AppendInt(b, int64(-t.Year()), 10) 473 } 474 475 return string(b) 476} 477 478// FmtDateLong returns the long date representation of 't' for 'he' 479func (he *he) FmtDateLong(t time.Time) string { 480 481 b := make([]byte, 0, 32) 482 483 b = strconv.AppendInt(b, int64(t.Day()), 10) 484 b = append(b, []byte{0x20, 0xd7, 0x91}...) 485 b = append(b, he.monthsWide[t.Month()]...) 486 b = append(b, []byte{0x20}...) 487 488 if t.Year() > 0 { 489 b = strconv.AppendInt(b, int64(t.Year()), 10) 490 } else { 491 b = strconv.AppendInt(b, int64(-t.Year()), 10) 492 } 493 494 return string(b) 495} 496 497// FmtDateFull returns the full date representation of 't' for 'he' 498func (he *he) FmtDateFull(t time.Time) string { 499 500 b := make([]byte, 0, 32) 501 502 b = append(b, he.daysWide[t.Weekday()]...) 503 b = append(b, []byte{0x2c, 0x20}...) 504 b = strconv.AppendInt(b, int64(t.Day()), 10) 505 b = append(b, []byte{0x20, 0xd7, 0x91}...) 506 b = append(b, he.monthsWide[t.Month()]...) 507 b = append(b, []byte{0x20}...) 508 509 if t.Year() > 0 { 510 b = strconv.AppendInt(b, int64(t.Year()), 10) 511 } else { 512 b = strconv.AppendInt(b, int64(-t.Year()), 10) 513 } 514 515 return string(b) 516} 517 518// FmtTimeShort returns the short time representation of 't' for 'he' 519func (he *he) FmtTimeShort(t time.Time) string { 520 521 b := make([]byte, 0, 32) 522 523 b = strconv.AppendInt(b, int64(t.Hour()), 10) 524 b = append(b, he.timeSeparator...) 525 526 if t.Minute() < 10 { 527 b = append(b, '0') 528 } 529 530 b = strconv.AppendInt(b, int64(t.Minute()), 10) 531 532 return string(b) 533} 534 535// FmtTimeMedium returns the medium time representation of 't' for 'he' 536func (he *he) FmtTimeMedium(t time.Time) string { 537 538 b := make([]byte, 0, 32) 539 540 b = strconv.AppendInt(b, int64(t.Hour()), 10) 541 b = append(b, he.timeSeparator...) 542 543 if t.Minute() < 10 { 544 b = append(b, '0') 545 } 546 547 b = strconv.AppendInt(b, int64(t.Minute()), 10) 548 b = append(b, he.timeSeparator...) 549 550 if t.Second() < 10 { 551 b = append(b, '0') 552 } 553 554 b = strconv.AppendInt(b, int64(t.Second()), 10) 555 556 return string(b) 557} 558 559// FmtTimeLong returns the long time representation of 't' for 'he' 560func (he *he) FmtTimeLong(t time.Time) string { 561 562 b := make([]byte, 0, 32) 563 564 b = strconv.AppendInt(b, int64(t.Hour()), 10) 565 b = append(b, he.timeSeparator...) 566 567 if t.Minute() < 10 { 568 b = append(b, '0') 569 } 570 571 b = strconv.AppendInt(b, int64(t.Minute()), 10) 572 b = append(b, he.timeSeparator...) 573 574 if t.Second() < 10 { 575 b = append(b, '0') 576 } 577 578 b = strconv.AppendInt(b, int64(t.Second()), 10) 579 b = append(b, []byte{0x20}...) 580 581 tz, _ := t.Zone() 582 b = append(b, tz...) 583 584 return string(b) 585} 586 587// FmtTimeFull returns the full time representation of 't' for 'he' 588func (he *he) FmtTimeFull(t time.Time) string { 589 590 b := make([]byte, 0, 32) 591 592 b = strconv.AppendInt(b, int64(t.Hour()), 10) 593 b = append(b, he.timeSeparator...) 594 595 if t.Minute() < 10 { 596 b = append(b, '0') 597 } 598 599 b = strconv.AppendInt(b, int64(t.Minute()), 10) 600 b = append(b, he.timeSeparator...) 601 602 if t.Second() < 10 { 603 b = append(b, '0') 604 } 605 606 b = strconv.AppendInt(b, int64(t.Second()), 10) 607 b = append(b, []byte{0x20}...) 608 609 tz, _ := t.Zone() 610 611 if btz, ok := he.timezones[tz]; ok { 612 b = append(b, btz...) 613 } else { 614 b = append(b, tz...) 615 } 616 617 return string(b) 618} 619