...

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

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

     1  package it
     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 it 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 'it' locale
    45  func New() locales.Translator {
    46  	return &it{
    47  		locale:                 "it",
    48  		pluralsCardinal:        []locales.PluralRule{2, 6},
    49  		pluralsOrdinal:         []locales.PluralRule{5, 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", "Kz", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "$", "ATS", "A$", "AWG", "AZM", "AZN", "BAD", "KM", "BAN", "$", "৳", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "$", "$", "Bs", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "$", "BTN", "BUK", "P", "BYB", "Br", "BYR", "$", "$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "$", "CNH", "CNX", "¥", "$", "COU", "₡", "CSD", "CSK", "$", "$", "CVE", "CYP", "Kč", "DDM", "DEM", "DJF", "kr", "$", "DZD", "ECS", "ECV", "EEK", "£E", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "$", "£", "FRF", "£", "GEK", "₾", "GHC", "GHS", "£", "GMD", "FG", "GNS", "GQE", "GRD", "Q", "GWE", "GWP", "$", "HKD", "L", "HRD", "kn", "HTG", "Ft", "Rp", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "kr", "ITL", "$", "JOD", "JPY", "KES", "KGS", "៛", "CF", "₩", "KRH", "KRO", "KRW", "KWD", "$", "₸", "₭", "L£", "Rs", "$", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "Ar", "MGF", "MKD", "MKN", "MLF", "K", "₮", "MOP", "MRO", "MRU", "MTL", "MTP", "Rs", "MVP", "MVR", "MWK", "MXN", "MXP", "MXV", "RM", "MZE", "MZM", "MZN", "$", "NGN", "NIC", "C$", "NLG", "NKr", "Rs", "NZ$", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "₱", "Rs", "PLN", "PLZ", "PTE", "₲", "QAR", "RHD", "ROL", "lei", "RSD", "₽", "RUR", "RF", "SAR", "$", "SCR", "SDD", "SDG", "SDP", "kr", "$", "£", "SIT", "SKK", "SLL", "SOS", "$", "SRG", "£", "STD", "STN", "SUR", "SVC", "£", "SZL", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "T$", "TPE", "TRL", "₺", "$", "TWD", "TZS", "₴", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "$", "UYW", "UZS", "VEB", "Bs", "VES", "₫", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "$", "XDR", "XEU", "XFO", "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "R", "ZMK", "ZK", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
    59  		currencyPositiveSuffix: " ",
    60  		currencyNegativeSuffix: " ",
    61  		monthsAbbreviated:      []string{"", "gen", "feb", "mar", "apr", "mag", "giu", "lug", "ago", "set", "ott", "nov", "dic"},
    62  		monthsNarrow:           []string{"", "G", "F", "M", "A", "M", "G", "L", "A", "S", "O", "N", "D"},
    63  		monthsWide:             []string{"", "gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"},
    64  		daysAbbreviated:        []string{"dom", "lun", "mar", "mer", "gio", "ven", "sab"},
    65  		daysNarrow:             []string{"D", "L", "M", "M", "G", "V", "S"},
    66  		daysShort:              []string{"dom", "lun", "mar", "mer", "gio", "ven", "sab"},
    67  		daysWide:               []string{"domenica", "lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato"},
    68  		periodsAbbreviated:     []string{"AM", "PM"},
    69  		periodsNarrow:          []string{"m.", "p."},
    70  		periodsWide:            []string{"AM", "PM"},
    71  		erasAbbreviated:        []string{"a.C.", "d.C."},
    72  		erasNarrow:             []string{"aC", "dC"},
    73  		erasWide:               []string{"avanti Cristo", "dopo Cristo"},
    74  		timezones:              map[string]string{"ACDT": "Ora legale dell’Australia centrale", "ACST": "Ora standard dell’Australia centrale", "ACWDT": "Ora legale dell’Australia centroccidentale", "ACWST": "Ora standard dell’Australia centroccidentale", "ADT": "Ora legale dell’Atlantico", "AEDT": "Ora legale dell’Australia orientale", "AEST": "Ora standard dell’Australia orientale", "AKDT": "Ora legale dell’Alaska", "AKST": "Ora standard dell’Alaska", "ARST": "Ora legale dell’Argentina", "ART": "Ora standard dell’Argentina", "AST": "Ora standard dell’Atlantico", "AWDT": "Ora legale dell’Australia occidentale", "AWST": "Ora standard dell’Australia occidentale", "BOT": "Ora della Bolivia", "BT": "Ora del Bhutan", "CAT": "Ora dell’Africa centrale", "CDT": "Ora legale centrale USA", "CHADT": "Ora legale delle Chatham", "CHAST": "Ora standard delle Chatham", "CLST": "Ora legale del Cile", "CLT": "Ora standard del Cile", "COST": "Ora legale della Colombia", "COT": "Ora standard della Colombia", "CST": "Ora standard centrale USA", "ChST": "Ora di Chamorro", "EAT": "Ora dell’Africa orientale", "ECT": "Ora dell’Ecuador", "EDT": "Ora legale orientale USA", "EST": "Ora standard orientale USA", "GFT": "Ora della Guiana francese", "GMT": "Ora del meridiano di Greenwich", "GST": "Ora del Golfo", "GYT": "Ora della Guyana", "HADT": "Ora legale delle Isole Hawaii-Aleutine", "HAST": "Ora standard delle Isole Hawaii-Aleutine", "HAT": "Ora legale di Terranova", "HECU": "Ora legale di Cuba", "HEEG": "Ora legale della Groenlandia orientale", "HENOMX": "Ora legale del Messico nord-occidentale", "HEOG": "Ora legale della Groenlandia occidentale", "HEPM": "Ora legale di Saint-Pierre e Miquelon", "HEPMX": "Ora legale del Pacifico (Messico)", "HKST": "Ora legale di Hong Kong", "HKT": "Ora standard di Hong Kong", "HNCU": "Ora standard di Cuba", "HNEG": "Ora standard della Groenlandia orientale", "HNNOMX": "Ora standard del Messico nord-occidentale", "HNOG": "Ora standard della Groenlandia occidentale", "HNPM": "Ora standard di Saint-Pierre e Miquelon", "HNPMX": "Ora standard del Pacifico (Messico)", "HNT": "Ora standard di Terranova", "IST": "Ora standard dell’India", "JDT": "Ora legale del Giappone", "JST": "Ora standard del Giappone", "LHDT": "Ora legale di Lord Howe", "LHST": "Ora standard di Lord Howe", "MDT": "Ora legale Montagne Rocciose USA", "MESZ": "Ora legale dell’Europa centrale", "MEZ": "Ora standard dell’Europa centrale", "MST": "Ora standard Montagne Rocciose USA", "MYT": "Ora della Malesia", "NZDT": "Ora legale della Nuova Zelanda", "NZST": "Ora standard della Nuova Zelanda", "OESZ": "Ora legale dell’Europa orientale", "OEZ": "Ora standard dell’Europa orientale", "PDT": "Ora legale del Pacifico USA", "PST": "Ora standard del Pacifico USA", "SAST": "Ora dell’Africa meridionale", "SGT": "Ora di Singapore", "SRT": "Ora del Suriname", "TMST": "Ora legale del Turkmenistan", "TMT": "Ora standard del Turkmenistan", "UYST": "Ora legale dell’Uruguay", "UYT": "Ora standard dell’Uruguay", "VET": "Ora del Venezuela", "WARST": "Ora legale dell’Argentina occidentale", "WART": "Ora standard dell’Argentina occidentale", "WAST": "Ora legale dell’Africa occidentale", "WAT": "Ora standard dell’Africa occidentale", "WESZ": "Ora legale dell’Europa occidentale", "WEZ": "Ora standard dell’Europa occidentale", "WIB": "Ora dell’Indonesia occidentale", "WIT": "Ora dell’Indonesia orientale", "WITA": "Ora dell’Indonesia centrale", "∅∅∅": "Ora legale di Brasilia"},
    75  	}
    76  }
    77  
    78  // Locale returns the current translators string locale
    79  func (it *it) Locale() string {
    80  	return it.locale
    81  }
    82  
    83  // PluralsCardinal returns the list of cardinal plural rules associated with 'it'
    84  func (it *it) PluralsCardinal() []locales.PluralRule {
    85  	return it.pluralsCardinal
    86  }
    87  
    88  // PluralsOrdinal returns the list of ordinal plural rules associated with 'it'
    89  func (it *it) PluralsOrdinal() []locales.PluralRule {
    90  	return it.pluralsOrdinal
    91  }
    92  
    93  // PluralsRange returns the list of range plural rules associated with 'it'
    94  func (it *it) PluralsRange() []locales.PluralRule {
    95  	return it.pluralsRange
    96  }
    97  
    98  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'it'
    99  func (it *it) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
   100  
   101  	n := math.Abs(num)
   102  	i := int64(n)
   103  
   104  	if i == 1 && v == 0 {
   105  		return locales.PluralRuleOne
   106  	}
   107  
   108  	return locales.PluralRuleOther
   109  }
   110  
   111  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'it'
   112  func (it *it) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
   113  
   114  	n := math.Abs(num)
   115  
   116  	if n == 11 || n == 8 || n == 80 || n == 800 {
   117  		return locales.PluralRuleMany
   118  	}
   119  
   120  	return locales.PluralRuleOther
   121  }
   122  
   123  // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'it'
   124  func (it *it) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   125  
   126  	start := it.CardinalPluralRule(num1, v1)
   127  	end := it.CardinalPluralRule(num2, v2)
   128  
   129  	if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
   130  		return locales.PluralRuleOther
   131  	} else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
   132  		return locales.PluralRuleOne
   133  	}
   134  
   135  	return locales.PluralRuleOther
   136  
   137  }
   138  
   139  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   140  func (it *it) MonthAbbreviated(month time.Month) string {
   141  	return it.monthsAbbreviated[month]
   142  }
   143  
   144  // MonthsAbbreviated returns the locales abbreviated months
   145  func (it *it) MonthsAbbreviated() []string {
   146  	return it.monthsAbbreviated[1:]
   147  }
   148  
   149  // MonthNarrow returns the locales narrow month given the 'month' provided
   150  func (it *it) MonthNarrow(month time.Month) string {
   151  	return it.monthsNarrow[month]
   152  }
   153  
   154  // MonthsNarrow returns the locales narrow months
   155  func (it *it) MonthsNarrow() []string {
   156  	return it.monthsNarrow[1:]
   157  }
   158  
   159  // MonthWide returns the locales wide month given the 'month' provided
   160  func (it *it) MonthWide(month time.Month) string {
   161  	return it.monthsWide[month]
   162  }
   163  
   164  // MonthsWide returns the locales wide months
   165  func (it *it) MonthsWide() []string {
   166  	return it.monthsWide[1:]
   167  }
   168  
   169  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   170  func (it *it) WeekdayAbbreviated(weekday time.Weekday) string {
   171  	return it.daysAbbreviated[weekday]
   172  }
   173  
   174  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   175  func (it *it) WeekdaysAbbreviated() []string {
   176  	return it.daysAbbreviated
   177  }
   178  
   179  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   180  func (it *it) WeekdayNarrow(weekday time.Weekday) string {
   181  	return it.daysNarrow[weekday]
   182  }
   183  
   184  // WeekdaysNarrow returns the locales narrow weekdays
   185  func (it *it) WeekdaysNarrow() []string {
   186  	return it.daysNarrow
   187  }
   188  
   189  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   190  func (it *it) WeekdayShort(weekday time.Weekday) string {
   191  	return it.daysShort[weekday]
   192  }
   193  
   194  // WeekdaysShort returns the locales short weekdays
   195  func (it *it) WeekdaysShort() []string {
   196  	return it.daysShort
   197  }
   198  
   199  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   200  func (it *it) WeekdayWide(weekday time.Weekday) string {
   201  	return it.daysWide[weekday]
   202  }
   203  
   204  // WeekdaysWide returns the locales wide weekdays
   205  func (it *it) WeekdaysWide() []string {
   206  	return it.daysWide
   207  }
   208  
   209  // Decimal returns the decimal point of number
   210  func (it *it) Decimal() string {
   211  	return it.decimal
   212  }
   213  
   214  // Group returns the group of number
   215  func (it *it) Group() string {
   216  	return it.group
   217  }
   218  
   219  // Group returns the minus sign of number
   220  func (it *it) Minus() string {
   221  	return it.minus
   222  }
   223  
   224  // FmtNumber returns 'num' with digits/precision of 'v' for 'it' and handles both Whole and Real numbers based on 'v'
   225  func (it *it) FmtNumber(num float64, v uint64) string {
   226  
   227  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   228  	l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
   229  	count := 0
   230  	inWhole := v == 0
   231  	b := make([]byte, 0, l)
   232  
   233  	for i := len(s) - 1; i >= 0; i-- {
   234  
   235  		if s[i] == '.' {
   236  			b = append(b, it.decimal[0])
   237  			inWhole = true
   238  			continue
   239  		}
   240  
   241  		if inWhole {
   242  			if count == 3 {
   243  				b = append(b, it.group[0])
   244  				count = 1
   245  			} else {
   246  				count++
   247  			}
   248  		}
   249  
   250  		b = append(b, s[i])
   251  	}
   252  
   253  	if num < 0 {
   254  		b = append(b, it.minus[0])
   255  	}
   256  
   257  	// reverse
   258  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   259  		b[i], b[j] = b[j], b[i]
   260  	}
   261  
   262  	return string(b)
   263  }
   264  
   265  // FmtPercent returns 'num' with digits/precision of 'v' for 'it' and handles both Whole and Real numbers based on 'v'
   266  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   267  func (it *it) FmtPercent(num float64, v uint64) string {
   268  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   269  	l := len(s) + 3
   270  	b := make([]byte, 0, l)
   271  
   272  	for i := len(s) - 1; i >= 0; i-- {
   273  
   274  		if s[i] == '.' {
   275  			b = append(b, it.decimal[0])
   276  			continue
   277  		}
   278  
   279  		b = append(b, s[i])
   280  	}
   281  
   282  	if num < 0 {
   283  		b = append(b, it.minus[0])
   284  	}
   285  
   286  	// reverse
   287  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   288  		b[i], b[j] = b[j], b[i]
   289  	}
   290  
   291  	b = append(b, it.percent...)
   292  
   293  	return string(b)
   294  }
   295  
   296  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'it'
   297  func (it *it) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   298  
   299  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   300  	symbol := it.currencies[currency]
   301  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   302  	count := 0
   303  	inWhole := v == 0
   304  	b := make([]byte, 0, l)
   305  
   306  	for i := len(s) - 1; i >= 0; i-- {
   307  
   308  		if s[i] == '.' {
   309  			b = append(b, it.decimal[0])
   310  			inWhole = true
   311  			continue
   312  		}
   313  
   314  		if inWhole {
   315  			if count == 3 {
   316  				b = append(b, it.group[0])
   317  				count = 1
   318  			} else {
   319  				count++
   320  			}
   321  		}
   322  
   323  		b = append(b, s[i])
   324  	}
   325  
   326  	if num < 0 {
   327  		b = append(b, it.minus[0])
   328  	}
   329  
   330  	// reverse
   331  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   332  		b[i], b[j] = b[j], b[i]
   333  	}
   334  
   335  	if int(v) < 2 {
   336  
   337  		if v == 0 {
   338  			b = append(b, it.decimal...)
   339  		}
   340  
   341  		for i := 0; i < 2-int(v); i++ {
   342  			b = append(b, '0')
   343  		}
   344  	}
   345  
   346  	b = append(b, it.currencyPositiveSuffix...)
   347  
   348  	b = append(b, symbol...)
   349  
   350  	return string(b)
   351  }
   352  
   353  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'it'
   354  // in accounting notation.
   355  func (it *it) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   356  
   357  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   358  	symbol := it.currencies[currency]
   359  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   360  	count := 0
   361  	inWhole := v == 0
   362  	b := make([]byte, 0, l)
   363  
   364  	for i := len(s) - 1; i >= 0; i-- {
   365  
   366  		if s[i] == '.' {
   367  			b = append(b, it.decimal[0])
   368  			inWhole = true
   369  			continue
   370  		}
   371  
   372  		if inWhole {
   373  			if count == 3 {
   374  				b = append(b, it.group[0])
   375  				count = 1
   376  			} else {
   377  				count++
   378  			}
   379  		}
   380  
   381  		b = append(b, s[i])
   382  	}
   383  
   384  	if num < 0 {
   385  
   386  		b = append(b, it.minus[0])
   387  
   388  	}
   389  
   390  	// reverse
   391  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   392  		b[i], b[j] = b[j], b[i]
   393  	}
   394  
   395  	if int(v) < 2 {
   396  
   397  		if v == 0 {
   398  			b = append(b, it.decimal...)
   399  		}
   400  
   401  		for i := 0; i < 2-int(v); i++ {
   402  			b = append(b, '0')
   403  		}
   404  	}
   405  
   406  	if num < 0 {
   407  		b = append(b, it.currencyNegativeSuffix...)
   408  		b = append(b, symbol...)
   409  	} else {
   410  
   411  		b = append(b, it.currencyPositiveSuffix...)
   412  		b = append(b, symbol...)
   413  	}
   414  
   415  	return string(b)
   416  }
   417  
   418  // FmtDateShort returns the short date representation of 't' for 'it'
   419  func (it *it) FmtDateShort(t time.Time) string {
   420  
   421  	b := make([]byte, 0, 32)
   422  
   423  	if t.Day() < 10 {
   424  		b = append(b, '0')
   425  	}
   426  
   427  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   428  	b = append(b, []byte{0x2f}...)
   429  
   430  	if t.Month() < 10 {
   431  		b = append(b, '0')
   432  	}
   433  
   434  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   435  
   436  	b = append(b, []byte{0x2f}...)
   437  
   438  	if t.Year() > 9 {
   439  		b = append(b, strconv.Itoa(t.Year())[2:]...)
   440  	} else {
   441  		b = append(b, strconv.Itoa(t.Year())[1:]...)
   442  	}
   443  
   444  	return string(b)
   445  }
   446  
   447  // FmtDateMedium returns the medium date representation of 't' for 'it'
   448  func (it *it) FmtDateMedium(t time.Time) string {
   449  
   450  	b := make([]byte, 0, 32)
   451  
   452  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   453  	b = append(b, []byte{0x20}...)
   454  	b = append(b, it.monthsAbbreviated[t.Month()]...)
   455  	b = append(b, []byte{0x20}...)
   456  
   457  	if t.Year() > 0 {
   458  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   459  	} else {
   460  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   461  	}
   462  
   463  	return string(b)
   464  }
   465  
   466  // FmtDateLong returns the long date representation of 't' for 'it'
   467  func (it *it) FmtDateLong(t time.Time) string {
   468  
   469  	b := make([]byte, 0, 32)
   470  
   471  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   472  	b = append(b, []byte{0x20}...)
   473  	b = append(b, it.monthsWide[t.Month()]...)
   474  	b = append(b, []byte{0x20}...)
   475  
   476  	if t.Year() > 0 {
   477  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   478  	} else {
   479  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   480  	}
   481  
   482  	return string(b)
   483  }
   484  
   485  // FmtDateFull returns the full date representation of 't' for 'it'
   486  func (it *it) FmtDateFull(t time.Time) string {
   487  
   488  	b := make([]byte, 0, 32)
   489  
   490  	b = append(b, it.daysWide[t.Weekday()]...)
   491  	b = append(b, []byte{0x20}...)
   492  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   493  	b = append(b, []byte{0x20}...)
   494  	b = append(b, it.monthsWide[t.Month()]...)
   495  	b = append(b, []byte{0x20}...)
   496  
   497  	if t.Year() > 0 {
   498  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   499  	} else {
   500  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   501  	}
   502  
   503  	return string(b)
   504  }
   505  
   506  // FmtTimeShort returns the short time representation of 't' for 'it'
   507  func (it *it) FmtTimeShort(t time.Time) string {
   508  
   509  	b := make([]byte, 0, 32)
   510  
   511  	if t.Hour() < 10 {
   512  		b = append(b, '0')
   513  	}
   514  
   515  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   516  	b = append(b, it.timeSeparator...)
   517  
   518  	if t.Minute() < 10 {
   519  		b = append(b, '0')
   520  	}
   521  
   522  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   523  
   524  	return string(b)
   525  }
   526  
   527  // FmtTimeMedium returns the medium time representation of 't' for 'it'
   528  func (it *it) FmtTimeMedium(t time.Time) string {
   529  
   530  	b := make([]byte, 0, 32)
   531  
   532  	if t.Hour() < 10 {
   533  		b = append(b, '0')
   534  	}
   535  
   536  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   537  	b = append(b, it.timeSeparator...)
   538  
   539  	if t.Minute() < 10 {
   540  		b = append(b, '0')
   541  	}
   542  
   543  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   544  	b = append(b, it.timeSeparator...)
   545  
   546  	if t.Second() < 10 {
   547  		b = append(b, '0')
   548  	}
   549  
   550  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   551  
   552  	return string(b)
   553  }
   554  
   555  // FmtTimeLong returns the long time representation of 't' for 'it'
   556  func (it *it) FmtTimeLong(t time.Time) string {
   557  
   558  	b := make([]byte, 0, 32)
   559  
   560  	if t.Hour() < 10 {
   561  		b = append(b, '0')
   562  	}
   563  
   564  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   565  	b = append(b, it.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, it.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 'it'
   588  func (it *it) FmtTimeFull(t time.Time) string {
   589  
   590  	b := make([]byte, 0, 32)
   591  
   592  	if t.Hour() < 10 {
   593  		b = append(b, '0')
   594  	}
   595  
   596  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   597  	b = append(b, it.timeSeparator...)
   598  
   599  	if t.Minute() < 10 {
   600  		b = append(b, '0')
   601  	}
   602  
   603  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   604  	b = append(b, it.timeSeparator...)
   605  
   606  	if t.Second() < 10 {
   607  		b = append(b, '0')
   608  	}
   609  
   610  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   611  	b = append(b, []byte{0x20}...)
   612  
   613  	tz, _ := t.Zone()
   614  
   615  	if btz, ok := it.timezones[tz]; ok {
   616  		b = append(b, btz...)
   617  	} else {
   618  		b = append(b, tz...)
   619  	}
   620  
   621  	return string(b)
   622  }
   623  

View as plain text