...

Source file src/github.com/go-playground/locales/hsb/hsb.go

Documentation: github.com/go-playground/locales/hsb

     1  package hsb
     2  
     3  import (
     4  	"math"
     5  	"strconv"
     6  	"time"
     7  
     8  	"github.com/go-playground/locales"
     9  	"github.com/go-playground/locales/currency"
    10  )
    11  
    12  type hsb 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  	percentSuffix          string
    22  	perMille               string
    23  	timeSeparator          string
    24  	inifinity              string
    25  	currencies             []string // idx = enum of currency code
    26  	currencyPositiveSuffix string
    27  	currencyNegativeSuffix string
    28  	monthsAbbreviated      []string
    29  	monthsNarrow           []string
    30  	monthsWide             []string
    31  	daysAbbreviated        []string
    32  	daysNarrow             []string
    33  	daysShort              []string
    34  	daysWide               []string
    35  	periodsAbbreviated     []string
    36  	periodsNarrow          []string
    37  	periodsShort           []string
    38  	periodsWide            []string
    39  	erasAbbreviated        []string
    40  	erasNarrow             []string
    41  	erasWide               []string
    42  	timezones              map[string]string
    43  }
    44  
    45  // New returns a new instance of translator for the 'hsb' locale
    46  func New() locales.Translator {
    47  	return &hsb{
    48  		locale:                 "hsb",
    49  		pluralsCardinal:        []locales.PluralRule{2, 3, 4, 6},
    50  		pluralsOrdinal:         []locales.PluralRule{6},
    51  		pluralsRange:           nil,
    52  		decimal:                ",",
    53  		group:                  ".",
    54  		minus:                  "-",
    55  		percent:                "%",
    56  		perMille:               "‰",
    57  		timeSeparator:          ":",
    58  		inifinity:              "∞",
    59  		currencies:             []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "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", "BRL", "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", "GRD", "GTQ", "GWE", "GWP", "GYD", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "₪", "INR", "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", "MRU", "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", "zł", "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", "UYW", "UZS", "VEB", "VEF", "VES", "₫", "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"},
    60  		percentSuffix:          " ",
    61  		currencyPositiveSuffix: " ",
    62  		currencyNegativeSuffix: " ",
    63  		monthsAbbreviated:      []string{"", "jan.", "feb.", "měr.", "apr.", "mej.", "jun.", "jul.", "awg.", "sep.", "okt.", "now.", "dec."},
    64  		monthsNarrow:           []string{"", "j", "f", "m", "a", "m", "j", "j", "a", "s", "o", "n", "d"},
    65  		monthsWide:             []string{"", "januara", "februara", "měrca", "apryla", "meje", "junija", "julija", "awgusta", "septembra", "oktobra", "nowembra", "decembra"},
    66  		daysAbbreviated:        []string{"nje", "pón", "wut", "srj", "štw", "pja", "sob"},
    67  		daysNarrow:             []string{"n", "p", "w", "s", "š", "p", "s"},
    68  		daysShort:              []string{"nj", "pó", "wu", "sr", "št", "pj", "so"},
    69  		daysWide:               []string{"njedźela", "póndźela", "wutora", "srjeda", "štwórtk", "pjatk", "sobota"},
    70  		periodsAbbreviated:     []string{"dopołdnja", "popołdnju"},
    71  		periodsNarrow:          []string{"dop.", "pop."},
    72  		periodsWide:            []string{"dopołdnja", "popołdnju"},
    73  		erasAbbreviated:        []string{"př.Chr.n.", "po Chr.n."},
    74  		erasNarrow:             []string{"", ""},
    75  		erasWide:               []string{"před Chrystowym narodźenjom", "po Chrystowym narodźenju"},
    76  		timezones:              map[string]string{"ACDT": "srjedźoawstralski lětni čas", "ACST": "srjedźoawstralski standardny čas", "ACWDT": "sjedźozapadny awstralski lětni čas", "ACWST": "srjedźozapadny awstralski standardny čas", "ADT": "atlantiski lětni čas", "AEDT": "wuchodoawstralski lětni čas", "AEST": "wuchodoawstralski standardny čas", "AKDT": "alaskaski lětni čas", "AKST": "alaskaski standardny čas", "ARST": "argentinski lětni čas", "ART": "argentinski standardny čas", "AST": "atlantiski standardny čas", "AWDT": "zapadoawstralski lětni čas", "AWST": "zapadoawstralski standardny čas", "BOT": "boliwiski čas", "BT": "bhutanski čas", "CAT": "centralnoafriski čas", "CDT": "sewjeroameriski centralny lětni čas", "CHADT": "chathamski lětni čas", "CHAST": "chathamski standardny čas", "CLST": "chilski lětni čas", "CLT": "chilski standardny čas", "COST": "kolumbiski lětni čas", "COT": "kolumbiski standardny čas", "CST": "sewjeroameriski centralny standardny čas", "ChST": "chamorroski čas", "EAT": "wuchodoafriski čas", "ECT": "ekwadorski čas", "EDT": "sewjeroameriski wuchodny lětni čas", "EST": "sewjeroameriski wuchodny standardny čas", "GFT": "francoskoguyanski čas", "GMT": "Greenwichski čas", "GST": "čas Persiskeho golfa", "GYT": "guyanski čas", "HADT": "hawaiisko-aleutski lětni čas", "HAST": "hawaiisko-aleutski standardny čas", "HAT": "nowofundlandski lětni čas", "HECU": "kubaski lětni čas", "HEEG": "wuchodogrönlandski lětni čas", "HENOMX": "mexiski sewjerozapadny lětni čas", "HEOG": "zapadogrönlandski lětni čas", "HEPM": "lětni čas kupow St. Pierre a Miquelon", "HEPMX": "mexiski pacifiski lětni čas", "HKST": "Hongkongski lětni čas", "HKT": "Hongkongski standardny čas", "HNCU": "kubaski standardny čas", "HNEG": "wuchodogrönlandski standardny čas", "HNNOMX": "mexiski sewjerozapadny standardny čas", "HNOG": "zapadogrönlandski standardny čas", "HNPM": "standardny čas kupow St. Pierre a Miquelon", "HNPMX": "mexiski pacifiski standardny čas", "HNT": "nowofundlandski standardny čas", "IST": "indiski čas", "JDT": "japanski lětni čas", "JST": "japanski standardny čas", "LHDT": "lětni čas kupy Lord-Howe", "LHST": "standardny čas kupy Lord-Howe", "MDT": "sewjeroameriski hórski lětni čas", "MESZ": "srjedźoeuropski lětni čas", "MEZ": "srjedźoeuropski standardny čas", "MST": "sewjeroameriski hórski standardny čas", "MYT": "malajziski čas", "NZDT": "nowoseelandski lětni čas", "NZST": "nowoseelandski standardny čas", "OESZ": "wuchodoeuropski lětni čas", "OEZ": "wuchodoeuropski standardny čas", "PDT": "sewjeroameriski pacifiski lětni čas", "PST": "sewjeroameriski pacifiski standardny čas", "SAST": "južnoafriski čas", "SGT": "Singapurski čas", "SRT": "surinamski čas", "TMST": "turkmenski lětni čas", "TMT": "turkmenski standardny čas", "UYST": "uruguayski lětni čas", "UYT": "uruguayski standardny čas", "VET": "venezuelski čas", "WARST": "zapadoargentinski lětni čas", "WART": "zapadoargentinski standardny čas", "WAST": "zapadoafriski lětni čas", "WAT": "zapadoafriski standardny čas", "WESZ": "zapadoeuropski lětni čas", "WEZ": "zapadoeuropski standardny čas", "WIB": "zapadoindoneski čas", "WIT": "wuchodoindoneski", "WITA": "srjedźoindoneski čas", "∅∅∅": "Brasiliski lětni čas"},
    77  	}
    78  }
    79  
    80  // Locale returns the current translators string locale
    81  func (hsb *hsb) Locale() string {
    82  	return hsb.locale
    83  }
    84  
    85  // PluralsCardinal returns the list of cardinal plural rules associated with 'hsb'
    86  func (hsb *hsb) PluralsCardinal() []locales.PluralRule {
    87  	return hsb.pluralsCardinal
    88  }
    89  
    90  // PluralsOrdinal returns the list of ordinal plural rules associated with 'hsb'
    91  func (hsb *hsb) PluralsOrdinal() []locales.PluralRule {
    92  	return hsb.pluralsOrdinal
    93  }
    94  
    95  // PluralsRange returns the list of range plural rules associated with 'hsb'
    96  func (hsb *hsb) PluralsRange() []locales.PluralRule {
    97  	return hsb.pluralsRange
    98  }
    99  
   100  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'hsb'
   101  func (hsb *hsb) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
   102  
   103  	n := math.Abs(num)
   104  	i := int64(n)
   105  	f := locales.F(n, v)
   106  	iMod100 := i % 100
   107  	fMod100 := f % 100
   108  
   109  	if (v == 0 && iMod100 == 1) || (fMod100 == 1) {
   110  		return locales.PluralRuleOne
   111  	} else if (v == 0 && iMod100 == 2) || (fMod100 == 2) {
   112  		return locales.PluralRuleTwo
   113  	} else if (v == 0 && iMod100 >= 3 && iMod100 <= 4) || (fMod100 >= 3 && fMod100 <= 4) {
   114  		return locales.PluralRuleFew
   115  	}
   116  
   117  	return locales.PluralRuleOther
   118  }
   119  
   120  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'hsb'
   121  func (hsb *hsb) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
   122  	return locales.PluralRuleOther
   123  }
   124  
   125  // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'hsb'
   126  func (hsb *hsb) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   127  	return locales.PluralRuleUnknown
   128  }
   129  
   130  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   131  func (hsb *hsb) MonthAbbreviated(month time.Month) string {
   132  	return hsb.monthsAbbreviated[month]
   133  }
   134  
   135  // MonthsAbbreviated returns the locales abbreviated months
   136  func (hsb *hsb) MonthsAbbreviated() []string {
   137  	return hsb.monthsAbbreviated[1:]
   138  }
   139  
   140  // MonthNarrow returns the locales narrow month given the 'month' provided
   141  func (hsb *hsb) MonthNarrow(month time.Month) string {
   142  	return hsb.monthsNarrow[month]
   143  }
   144  
   145  // MonthsNarrow returns the locales narrow months
   146  func (hsb *hsb) MonthsNarrow() []string {
   147  	return hsb.monthsNarrow[1:]
   148  }
   149  
   150  // MonthWide returns the locales wide month given the 'month' provided
   151  func (hsb *hsb) MonthWide(month time.Month) string {
   152  	return hsb.monthsWide[month]
   153  }
   154  
   155  // MonthsWide returns the locales wide months
   156  func (hsb *hsb) MonthsWide() []string {
   157  	return hsb.monthsWide[1:]
   158  }
   159  
   160  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   161  func (hsb *hsb) WeekdayAbbreviated(weekday time.Weekday) string {
   162  	return hsb.daysAbbreviated[weekday]
   163  }
   164  
   165  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   166  func (hsb *hsb) WeekdaysAbbreviated() []string {
   167  	return hsb.daysAbbreviated
   168  }
   169  
   170  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   171  func (hsb *hsb) WeekdayNarrow(weekday time.Weekday) string {
   172  	return hsb.daysNarrow[weekday]
   173  }
   174  
   175  // WeekdaysNarrow returns the locales narrow weekdays
   176  func (hsb *hsb) WeekdaysNarrow() []string {
   177  	return hsb.daysNarrow
   178  }
   179  
   180  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   181  func (hsb *hsb) WeekdayShort(weekday time.Weekday) string {
   182  	return hsb.daysShort[weekday]
   183  }
   184  
   185  // WeekdaysShort returns the locales short weekdays
   186  func (hsb *hsb) WeekdaysShort() []string {
   187  	return hsb.daysShort
   188  }
   189  
   190  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   191  func (hsb *hsb) WeekdayWide(weekday time.Weekday) string {
   192  	return hsb.daysWide[weekday]
   193  }
   194  
   195  // WeekdaysWide returns the locales wide weekdays
   196  func (hsb *hsb) WeekdaysWide() []string {
   197  	return hsb.daysWide
   198  }
   199  
   200  // Decimal returns the decimal point of number
   201  func (hsb *hsb) Decimal() string {
   202  	return hsb.decimal
   203  }
   204  
   205  // Group returns the group of number
   206  func (hsb *hsb) Group() string {
   207  	return hsb.group
   208  }
   209  
   210  // Group returns the minus sign of number
   211  func (hsb *hsb) Minus() string {
   212  	return hsb.minus
   213  }
   214  
   215  // FmtNumber returns 'num' with digits/precision of 'v' for 'hsb' and handles both Whole and Real numbers based on 'v'
   216  func (hsb *hsb) FmtNumber(num float64, v uint64) string {
   217  
   218  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   219  	l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
   220  	count := 0
   221  	inWhole := v == 0
   222  	b := make([]byte, 0, l)
   223  
   224  	for i := len(s) - 1; i >= 0; i-- {
   225  
   226  		if s[i] == '.' {
   227  			b = append(b, hsb.decimal[0])
   228  			inWhole = true
   229  			continue
   230  		}
   231  
   232  		if inWhole {
   233  			if count == 3 {
   234  				b = append(b, hsb.group[0])
   235  				count = 1
   236  			} else {
   237  				count++
   238  			}
   239  		}
   240  
   241  		b = append(b, s[i])
   242  	}
   243  
   244  	if num < 0 {
   245  		b = append(b, hsb.minus[0])
   246  	}
   247  
   248  	// reverse
   249  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   250  		b[i], b[j] = b[j], b[i]
   251  	}
   252  
   253  	return string(b)
   254  }
   255  
   256  // FmtPercent returns 'num' with digits/precision of 'v' for 'hsb' and handles both Whole and Real numbers based on 'v'
   257  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   258  func (hsb *hsb) FmtPercent(num float64, v uint64) string {
   259  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   260  	l := len(s) + 5
   261  	b := make([]byte, 0, l)
   262  
   263  	for i := len(s) - 1; i >= 0; i-- {
   264  
   265  		if s[i] == '.' {
   266  			b = append(b, hsb.decimal[0])
   267  			continue
   268  		}
   269  
   270  		b = append(b, s[i])
   271  	}
   272  
   273  	if num < 0 {
   274  		b = append(b, hsb.minus[0])
   275  	}
   276  
   277  	// reverse
   278  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   279  		b[i], b[j] = b[j], b[i]
   280  	}
   281  
   282  	b = append(b, hsb.percentSuffix...)
   283  
   284  	b = append(b, hsb.percent...)
   285  
   286  	return string(b)
   287  }
   288  
   289  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'hsb'
   290  func (hsb *hsb) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   291  
   292  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   293  	symbol := hsb.currencies[currency]
   294  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   295  	count := 0
   296  	inWhole := v == 0
   297  	b := make([]byte, 0, l)
   298  
   299  	for i := len(s) - 1; i >= 0; i-- {
   300  
   301  		if s[i] == '.' {
   302  			b = append(b, hsb.decimal[0])
   303  			inWhole = true
   304  			continue
   305  		}
   306  
   307  		if inWhole {
   308  			if count == 3 {
   309  				b = append(b, hsb.group[0])
   310  				count = 1
   311  			} else {
   312  				count++
   313  			}
   314  		}
   315  
   316  		b = append(b, s[i])
   317  	}
   318  
   319  	if num < 0 {
   320  		b = append(b, hsb.minus[0])
   321  	}
   322  
   323  	// reverse
   324  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   325  		b[i], b[j] = b[j], b[i]
   326  	}
   327  
   328  	if int(v) < 2 {
   329  
   330  		if v == 0 {
   331  			b = append(b, hsb.decimal...)
   332  		}
   333  
   334  		for i := 0; i < 2-int(v); i++ {
   335  			b = append(b, '0')
   336  		}
   337  	}
   338  
   339  	b = append(b, hsb.currencyPositiveSuffix...)
   340  
   341  	b = append(b, symbol...)
   342  
   343  	return string(b)
   344  }
   345  
   346  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'hsb'
   347  // in accounting notation.
   348  func (hsb *hsb) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   349  
   350  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   351  	symbol := hsb.currencies[currency]
   352  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   353  	count := 0
   354  	inWhole := v == 0
   355  	b := make([]byte, 0, l)
   356  
   357  	for i := len(s) - 1; i >= 0; i-- {
   358  
   359  		if s[i] == '.' {
   360  			b = append(b, hsb.decimal[0])
   361  			inWhole = true
   362  			continue
   363  		}
   364  
   365  		if inWhole {
   366  			if count == 3 {
   367  				b = append(b, hsb.group[0])
   368  				count = 1
   369  			} else {
   370  				count++
   371  			}
   372  		}
   373  
   374  		b = append(b, s[i])
   375  	}
   376  
   377  	if num < 0 {
   378  
   379  		b = append(b, hsb.minus[0])
   380  
   381  	}
   382  
   383  	// reverse
   384  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   385  		b[i], b[j] = b[j], b[i]
   386  	}
   387  
   388  	if int(v) < 2 {
   389  
   390  		if v == 0 {
   391  			b = append(b, hsb.decimal...)
   392  		}
   393  
   394  		for i := 0; i < 2-int(v); i++ {
   395  			b = append(b, '0')
   396  		}
   397  	}
   398  
   399  	if num < 0 {
   400  		b = append(b, hsb.currencyNegativeSuffix...)
   401  		b = append(b, symbol...)
   402  	} else {
   403  
   404  		b = append(b, hsb.currencyPositiveSuffix...)
   405  		b = append(b, symbol...)
   406  	}
   407  
   408  	return string(b)
   409  }
   410  
   411  // FmtDateShort returns the short date representation of 't' for 'hsb'
   412  func (hsb *hsb) FmtDateShort(t time.Time) string {
   413  
   414  	b := make([]byte, 0, 32)
   415  
   416  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   417  	b = append(b, []byte{0x2e}...)
   418  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   419  	b = append(b, []byte{0x2e}...)
   420  
   421  	if t.Year() > 9 {
   422  		b = append(b, strconv.Itoa(t.Year())[2:]...)
   423  	} else {
   424  		b = append(b, strconv.Itoa(t.Year())[1:]...)
   425  	}
   426  
   427  	return string(b)
   428  }
   429  
   430  // FmtDateMedium returns the medium date representation of 't' for 'hsb'
   431  func (hsb *hsb) FmtDateMedium(t time.Time) string {
   432  
   433  	b := make([]byte, 0, 32)
   434  
   435  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   436  	b = append(b, []byte{0x2e}...)
   437  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   438  	b = append(b, []byte{0x2e}...)
   439  
   440  	if t.Year() > 0 {
   441  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   442  	} else {
   443  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   444  	}
   445  
   446  	return string(b)
   447  }
   448  
   449  // FmtDateLong returns the long date representation of 't' for 'hsb'
   450  func (hsb *hsb) FmtDateLong(t time.Time) string {
   451  
   452  	b := make([]byte, 0, 32)
   453  
   454  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   455  	b = append(b, []byte{0x2e, 0x20}...)
   456  	b = append(b, hsb.monthsWide[t.Month()]...)
   457  	b = append(b, []byte{0x20}...)
   458  
   459  	if t.Year() > 0 {
   460  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   461  	} else {
   462  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   463  	}
   464  
   465  	return string(b)
   466  }
   467  
   468  // FmtDateFull returns the full date representation of 't' for 'hsb'
   469  func (hsb *hsb) FmtDateFull(t time.Time) string {
   470  
   471  	b := make([]byte, 0, 32)
   472  
   473  	b = append(b, hsb.daysWide[t.Weekday()]...)
   474  	b = append(b, []byte{0x2c, 0x20}...)
   475  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   476  	b = append(b, []byte{0x2e, 0x20}...)
   477  	b = append(b, hsb.monthsWide[t.Month()]...)
   478  	b = append(b, []byte{0x20}...)
   479  
   480  	if t.Year() > 0 {
   481  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   482  	} else {
   483  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   484  	}
   485  
   486  	return string(b)
   487  }
   488  
   489  // FmtTimeShort returns the short time representation of 't' for 'hsb'
   490  func (hsb *hsb) FmtTimeShort(t time.Time) string {
   491  
   492  	b := make([]byte, 0, 32)
   493  
   494  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   495  	b = append(b, hsb.timeSeparator...)
   496  
   497  	if t.Minute() < 10 {
   498  		b = append(b, '0')
   499  	}
   500  
   501  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   502  	b = append(b, []byte{0x20, 0x68, 0x6f, 0x64, 0xc5, 0xba}...)
   503  	b = append(b, []byte{0x2e}...)
   504  
   505  	return string(b)
   506  }
   507  
   508  // FmtTimeMedium returns the medium time representation of 't' for 'hsb'
   509  func (hsb *hsb) FmtTimeMedium(t time.Time) string {
   510  
   511  	b := make([]byte, 0, 32)
   512  
   513  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   514  	b = append(b, hsb.timeSeparator...)
   515  
   516  	if t.Minute() < 10 {
   517  		b = append(b, '0')
   518  	}
   519  
   520  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   521  	b = append(b, hsb.timeSeparator...)
   522  
   523  	if t.Second() < 10 {
   524  		b = append(b, '0')
   525  	}
   526  
   527  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   528  
   529  	return string(b)
   530  }
   531  
   532  // FmtTimeLong returns the long time representation of 't' for 'hsb'
   533  func (hsb *hsb) FmtTimeLong(t time.Time) string {
   534  
   535  	b := make([]byte, 0, 32)
   536  
   537  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   538  	b = append(b, hsb.timeSeparator...)
   539  
   540  	if t.Minute() < 10 {
   541  		b = append(b, '0')
   542  	}
   543  
   544  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   545  	b = append(b, hsb.timeSeparator...)
   546  
   547  	if t.Second() < 10 {
   548  		b = append(b, '0')
   549  	}
   550  
   551  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   552  	b = append(b, []byte{0x20}...)
   553  
   554  	tz, _ := t.Zone()
   555  	b = append(b, tz...)
   556  
   557  	return string(b)
   558  }
   559  
   560  // FmtTimeFull returns the full time representation of 't' for 'hsb'
   561  func (hsb *hsb) FmtTimeFull(t time.Time) string {
   562  
   563  	b := make([]byte, 0, 32)
   564  
   565  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   566  	b = append(b, hsb.timeSeparator...)
   567  
   568  	if t.Minute() < 10 {
   569  		b = append(b, '0')
   570  	}
   571  
   572  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   573  	b = append(b, hsb.timeSeparator...)
   574  
   575  	if t.Second() < 10 {
   576  		b = append(b, '0')
   577  	}
   578  
   579  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   580  	b = append(b, []byte{0x20}...)
   581  
   582  	tz, _ := t.Zone()
   583  
   584  	if btz, ok := hsb.timezones[tz]; ok {
   585  		b = append(b, btz...)
   586  	} else {
   587  		b = append(b, tz...)
   588  	}
   589  
   590  	return string(b)
   591  }
   592  

View as plain text