...

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

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

     1  package pt
     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 pt 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  	currencyPositivePrefix string
    26  	currencyNegativePrefix 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 'pt' locale
    45  func New() locales.Translator {
    46  	return &pt{
    47  		locale:                 "pt",
    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", "AU$", "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", "GRD", "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", "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", "PLN", "PLZ", "Esc.", "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", "US$", "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"},
    59  		currencyPositivePrefix: " ",
    60  		currencyNegativePrefix: " ",
    61  		monthsAbbreviated:      []string{"", "jan.", "fev.", "mar.", "abr.", "mai.", "jun.", "jul.", "ago.", "set.", "out.", "nov.", "dez."},
    62  		monthsNarrow:           []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
    63  		monthsWide:             []string{"", "janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro"},
    64  		daysAbbreviated:        []string{"dom.", "seg.", "ter.", "qua.", "qui.", "sex.", "sáb."},
    65  		daysNarrow:             []string{"D", "S", "T", "Q", "Q", "S", "S"},
    66  		daysWide:               []string{"domingo", "segunda-feira", "terça-feira", "quarta-feira", "quinta-feira", "sexta-feira", "sábado"},
    67  		periodsAbbreviated:     []string{"AM", "PM"},
    68  		periodsNarrow:          []string{"AM", "PM"},
    69  		periodsWide:            []string{"AM", "PM"},
    70  		erasAbbreviated:        []string{"a.C.", "d.C."},
    71  		erasNarrow:             []string{"", ""},
    72  		erasWide:               []string{"antes de Cristo", "depois de Cristo"},
    73  		timezones:              map[string]string{"ACDT": "Horário de Verão da Austrália Central", "ACST": "Horário Padrão da Austrália Central", "ACWDT": "Horário de Verão da Austrália Centro-Ocidental", "ACWST": "Horário Padrão da Austrália Centro-Ocidental", "ADT": "Horário de Verão do Atlântico", "AEDT": "Horário de Verão da Austrália Oriental", "AEST": "Horário Padrão da Austrália Oriental", "AKDT": "Horário de Verão do Alasca", "AKST": "Horário Padrão do Alasca", "ARST": "Horário de Verão da Argentina", "ART": "Horário Padrão da Argentina", "AST": "Horário Padrão do Atlântico", "AWDT": "Horário de Verão da Austrália Ocidental", "AWST": "Horário Padrão da Austrália Ocidental", "BOT": "Horário da Bolívia", "BT": "Horário do Butão", "CAT": "Horário da África Central", "CDT": "Horário de Verão Central", "CHADT": "Horário de Verão de Chatham", "CHAST": "Horário Padrão de Chatham", "CLST": "Horário de Verão do Chile", "CLT": "Horário Padrão do Chile", "COST": "Horário de Verão da Colômbia", "COT": "Horário Padrão da Colômbia", "CST": "Horário Padrão Central", "ChST": "Horário de Chamorro", "EAT": "Horário da África Oriental", "ECT": "Horário do Equador", "EDT": "Horário de Verão do Leste", "EST": "Horário Padrão do Leste", "GFT": "Horário da Guiana Francesa", "GMT": "Horário do Meridiano de Greenwich", "GST": "Horário do Golfo", "GYT": "Horário da Guiana", "HADT": "Horário de Verão do Havaí e Ilhas Aleutas", "HAST": "Horário Padrão do Havaí e Ilhas Aleutas", "HAT": "Horário de Verão da Terra Nova", "HECU": "Horário de Verão de Cuba", "HEEG": "Horário de Verão da Groelândia Oriental", "HENOMX": "Horário de Verão do Noroeste do México", "HEOG": "Horário de Verão da Groenlândia Ocidental", "HEPM": "Horário Verão de São Pedro e Miquelão", "HEPMX": "Horário de Verão do Pacífico Mexicano", "HKST": "Horário de Verão de Hong Kong", "HKT": "Horário Padrão de Hong Kong", "HNCU": "Horário Padrão de Cuba", "HNEG": "Horário Padrão da Groelândia Oriental", "HNNOMX": "Horário Padrão do Noroeste do México", "HNOG": "Horário Padrão da Groenlândia Ocidental", "HNPM": "Horário Padrão de São Pedro e Miquelão", "HNPMX": "Horário Padrão do Pacífico Mexicano", "HNT": "Horário Padrão da Terra Nova", "IST": "Horário Padrão da Índia", "JDT": "Horário de Verão do Japão", "JST": "Horário Padrão do Japão", "LHDT": "Horário de Verão de Lord Howe", "LHST": "Horário Padrão de Lord Howe", "MDT": "Horário de Verão de Macau", "MESZ": "Horário de Verão da Europa Central", "MEZ": "Horário Padrão da Europa Central", "MST": "Horário Padrão de Macau", "MYT": "Horário da Malásia", "NZDT": "Horário de Verão da Nova Zelândia", "NZST": "Horário Padrão da Nova Zelândia", "OESZ": "Horário de Verão da Europa Oriental", "OEZ": "Horário Padrão da Europa Oriental", "PDT": "Horário de Verão do Pacífico", "PST": "Horário Padrão do Pacífico", "SAST": "Horário da África do Sul", "SGT": "Horário Padrão de Cingapura", "SRT": "Horário do Suriname", "TMST": "Horário de Verão do Turcomenistão", "TMT": "Horário Padrão do Turcomenistão", "UYST": "Horário de Verão do Uruguai", "UYT": "Horário Padrão do Uruguai", "VET": "Horário da Venezuela", "WARST": "Horário de Verão da Argentina Ocidental", "WART": "Horário Padrão da Argentina Ocidental", "WAST": "Horário de Verão da África Ocidental", "WAT": "Horário Padrão da África Ocidental", "WESZ": "Horário de Verão da Europa Ocidental", "WEZ": "Horário Padrão da Europa Ocidental", "WIB": "Horário da Indonésia Ocidental", "WIT": "Horário da Indonésia Oriental", "WITA": "Horário da Indonésia Central", "∅∅∅": "Horário de Verão do Peru"},
    74  	}
    75  }
    76  
    77  // Locale returns the current translators string locale
    78  func (pt *pt) Locale() string {
    79  	return pt.locale
    80  }
    81  
    82  // PluralsCardinal returns the list of cardinal plural rules associated with 'pt'
    83  func (pt *pt) PluralsCardinal() []locales.PluralRule {
    84  	return pt.pluralsCardinal
    85  }
    86  
    87  // PluralsOrdinal returns the list of ordinal plural rules associated with 'pt'
    88  func (pt *pt) PluralsOrdinal() []locales.PluralRule {
    89  	return pt.pluralsOrdinal
    90  }
    91  
    92  // PluralsRange returns the list of range plural rules associated with 'pt'
    93  func (pt *pt) PluralsRange() []locales.PluralRule {
    94  	return pt.pluralsRange
    95  }
    96  
    97  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'pt'
    98  func (pt *pt) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
    99  
   100  	n := math.Abs(num)
   101  	i := int64(n)
   102  
   103  	if i >= 0 && i <= 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 'pt'
   111  func (pt *pt) 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 'pt'
   116  func (pt *pt) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   117  
   118  	start := pt.CardinalPluralRule(num1, v1)
   119  	end := pt.CardinalPluralRule(num2, v2)
   120  
   121  	if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
   122  		return locales.PluralRuleOne
   123  	} else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
   124  		return locales.PluralRuleOther
   125  	}
   126  
   127  	return locales.PluralRuleOther
   128  
   129  }
   130  
   131  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   132  func (pt *pt) MonthAbbreviated(month time.Month) string {
   133  	return pt.monthsAbbreviated[month]
   134  }
   135  
   136  // MonthsAbbreviated returns the locales abbreviated months
   137  func (pt *pt) MonthsAbbreviated() []string {
   138  	return pt.monthsAbbreviated[1:]
   139  }
   140  
   141  // MonthNarrow returns the locales narrow month given the 'month' provided
   142  func (pt *pt) MonthNarrow(month time.Month) string {
   143  	return pt.monthsNarrow[month]
   144  }
   145  
   146  // MonthsNarrow returns the locales narrow months
   147  func (pt *pt) MonthsNarrow() []string {
   148  	return pt.monthsNarrow[1:]
   149  }
   150  
   151  // MonthWide returns the locales wide month given the 'month' provided
   152  func (pt *pt) MonthWide(month time.Month) string {
   153  	return pt.monthsWide[month]
   154  }
   155  
   156  // MonthsWide returns the locales wide months
   157  func (pt *pt) MonthsWide() []string {
   158  	return pt.monthsWide[1:]
   159  }
   160  
   161  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   162  func (pt *pt) WeekdayAbbreviated(weekday time.Weekday) string {
   163  	return pt.daysAbbreviated[weekday]
   164  }
   165  
   166  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   167  func (pt *pt) WeekdaysAbbreviated() []string {
   168  	return pt.daysAbbreviated
   169  }
   170  
   171  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   172  func (pt *pt) WeekdayNarrow(weekday time.Weekday) string {
   173  	return pt.daysNarrow[weekday]
   174  }
   175  
   176  // WeekdaysNarrow returns the locales narrow weekdays
   177  func (pt *pt) WeekdaysNarrow() []string {
   178  	return pt.daysNarrow
   179  }
   180  
   181  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   182  func (pt *pt) WeekdayShort(weekday time.Weekday) string {
   183  	return pt.daysShort[weekday]
   184  }
   185  
   186  // WeekdaysShort returns the locales short weekdays
   187  func (pt *pt) WeekdaysShort() []string {
   188  	return pt.daysShort
   189  }
   190  
   191  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   192  func (pt *pt) WeekdayWide(weekday time.Weekday) string {
   193  	return pt.daysWide[weekday]
   194  }
   195  
   196  // WeekdaysWide returns the locales wide weekdays
   197  func (pt *pt) WeekdaysWide() []string {
   198  	return pt.daysWide
   199  }
   200  
   201  // Decimal returns the decimal point of number
   202  func (pt *pt) Decimal() string {
   203  	return pt.decimal
   204  }
   205  
   206  // Group returns the group of number
   207  func (pt *pt) Group() string {
   208  	return pt.group
   209  }
   210  
   211  // Group returns the minus sign of number
   212  func (pt *pt) Minus() string {
   213  	return pt.minus
   214  }
   215  
   216  // FmtNumber returns 'num' with digits/precision of 'v' for 'pt' and handles both Whole and Real numbers based on 'v'
   217  func (pt *pt) 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, pt.decimal[0])
   229  			inWhole = true
   230  			continue
   231  		}
   232  
   233  		if inWhole {
   234  			if count == 3 {
   235  				b = append(b, pt.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, pt.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 'pt' and handles both Whole and Real numbers based on 'v'
   258  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   259  func (pt *pt) 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, pt.decimal[0])
   268  			continue
   269  		}
   270  
   271  		b = append(b, s[i])
   272  	}
   273  
   274  	if num < 0 {
   275  		b = append(b, pt.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, pt.percent...)
   284  
   285  	return string(b)
   286  }
   287  
   288  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'pt'
   289  func (pt *pt) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   290  
   291  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   292  	symbol := pt.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, pt.decimal[0])
   302  			inWhole = true
   303  			continue
   304  		}
   305  
   306  		if inWhole {
   307  			if count == 3 {
   308  				b = append(b, pt.group[0])
   309  				count = 1
   310  			} else {
   311  				count++
   312  			}
   313  		}
   314  
   315  		b = append(b, s[i])
   316  	}
   317  
   318  	for j := len(symbol) - 1; j >= 0; j-- {
   319  		b = append(b, symbol[j])
   320  	}
   321  
   322  	for j := len(pt.currencyPositivePrefix) - 1; j >= 0; j-- {
   323  		b = append(b, pt.currencyPositivePrefix[j])
   324  	}
   325  
   326  	if num < 0 {
   327  		b = append(b, pt.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, pt.decimal...)
   339  		}
   340  
   341  		for i := 0; i < 2-int(v); i++ {
   342  			b = append(b, '0')
   343  		}
   344  	}
   345  
   346  	return string(b)
   347  }
   348  
   349  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'pt'
   350  // in accounting notation.
   351  func (pt *pt) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   352  
   353  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   354  	symbol := pt.currencies[currency]
   355  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   356  	count := 0
   357  	inWhole := v == 0
   358  	b := make([]byte, 0, l)
   359  
   360  	for i := len(s) - 1; i >= 0; i-- {
   361  
   362  		if s[i] == '.' {
   363  			b = append(b, pt.decimal[0])
   364  			inWhole = true
   365  			continue
   366  		}
   367  
   368  		if inWhole {
   369  			if count == 3 {
   370  				b = append(b, pt.group[0])
   371  				count = 1
   372  			} else {
   373  				count++
   374  			}
   375  		}
   376  
   377  		b = append(b, s[i])
   378  	}
   379  
   380  	if num < 0 {
   381  
   382  		for j := len(symbol) - 1; j >= 0; j-- {
   383  			b = append(b, symbol[j])
   384  		}
   385  
   386  		for j := len(pt.currencyNegativePrefix) - 1; j >= 0; j-- {
   387  			b = append(b, pt.currencyNegativePrefix[j])
   388  		}
   389  
   390  		b = append(b, pt.minus[0])
   391  
   392  	} else {
   393  
   394  		for j := len(symbol) - 1; j >= 0; j-- {
   395  			b = append(b, symbol[j])
   396  		}
   397  
   398  		for j := len(pt.currencyPositivePrefix) - 1; j >= 0; j-- {
   399  			b = append(b, pt.currencyPositivePrefix[j])
   400  		}
   401  
   402  	}
   403  
   404  	// reverse
   405  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   406  		b[i], b[j] = b[j], b[i]
   407  	}
   408  
   409  	if int(v) < 2 {
   410  
   411  		if v == 0 {
   412  			b = append(b, pt.decimal...)
   413  		}
   414  
   415  		for i := 0; i < 2-int(v); i++ {
   416  			b = append(b, '0')
   417  		}
   418  	}
   419  
   420  	return string(b)
   421  }
   422  
   423  // FmtDateShort returns the short date representation of 't' for 'pt'
   424  func (pt *pt) FmtDateShort(t time.Time) string {
   425  
   426  	b := make([]byte, 0, 32)
   427  
   428  	if t.Day() < 10 {
   429  		b = append(b, '0')
   430  	}
   431  
   432  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   433  	b = append(b, []byte{0x2f}...)
   434  
   435  	if t.Month() < 10 {
   436  		b = append(b, '0')
   437  	}
   438  
   439  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   440  
   441  	b = append(b, []byte{0x2f}...)
   442  
   443  	if t.Year() > 0 {
   444  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   445  	} else {
   446  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   447  	}
   448  
   449  	return string(b)
   450  }
   451  
   452  // FmtDateMedium returns the medium date representation of 't' for 'pt'
   453  func (pt *pt) FmtDateMedium(t time.Time) string {
   454  
   455  	b := make([]byte, 0, 32)
   456  
   457  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   458  	b = append(b, []byte{0x20, 0x64, 0x65}...)
   459  	b = append(b, []byte{0x20}...)
   460  	b = append(b, pt.monthsAbbreviated[t.Month()]...)
   461  	b = append(b, []byte{0x20, 0x64, 0x65}...)
   462  	b = append(b, []byte{0x20}...)
   463  
   464  	if t.Year() > 0 {
   465  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   466  	} else {
   467  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   468  	}
   469  
   470  	return string(b)
   471  }
   472  
   473  // FmtDateLong returns the long date representation of 't' for 'pt'
   474  func (pt *pt) FmtDateLong(t time.Time) string {
   475  
   476  	b := make([]byte, 0, 32)
   477  
   478  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   479  	b = append(b, []byte{0x20, 0x64, 0x65}...)
   480  	b = append(b, []byte{0x20}...)
   481  	b = append(b, pt.monthsWide[t.Month()]...)
   482  	b = append(b, []byte{0x20, 0x64, 0x65}...)
   483  	b = append(b, []byte{0x20}...)
   484  
   485  	if t.Year() > 0 {
   486  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   487  	} else {
   488  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   489  	}
   490  
   491  	return string(b)
   492  }
   493  
   494  // FmtDateFull returns the full date representation of 't' for 'pt'
   495  func (pt *pt) FmtDateFull(t time.Time) string {
   496  
   497  	b := make([]byte, 0, 32)
   498  
   499  	b = append(b, pt.daysWide[t.Weekday()]...)
   500  	b = append(b, []byte{0x2c, 0x20}...)
   501  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   502  	b = append(b, []byte{0x20, 0x64, 0x65}...)
   503  	b = append(b, []byte{0x20}...)
   504  	b = append(b, pt.monthsWide[t.Month()]...)
   505  	b = append(b, []byte{0x20, 0x64, 0x65}...)
   506  	b = append(b, []byte{0x20}...)
   507  
   508  	if t.Year() > 0 {
   509  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   510  	} else {
   511  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   512  	}
   513  
   514  	return string(b)
   515  }
   516  
   517  // FmtTimeShort returns the short time representation of 't' for 'pt'
   518  func (pt *pt) FmtTimeShort(t time.Time) string {
   519  
   520  	b := make([]byte, 0, 32)
   521  
   522  	if t.Hour() < 10 {
   523  		b = append(b, '0')
   524  	}
   525  
   526  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   527  	b = append(b, pt.timeSeparator...)
   528  
   529  	if t.Minute() < 10 {
   530  		b = append(b, '0')
   531  	}
   532  
   533  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   534  
   535  	return string(b)
   536  }
   537  
   538  // FmtTimeMedium returns the medium time representation of 't' for 'pt'
   539  func (pt *pt) FmtTimeMedium(t time.Time) string {
   540  
   541  	b := make([]byte, 0, 32)
   542  
   543  	if t.Hour() < 10 {
   544  		b = append(b, '0')
   545  	}
   546  
   547  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   548  	b = append(b, pt.timeSeparator...)
   549  
   550  	if t.Minute() < 10 {
   551  		b = append(b, '0')
   552  	}
   553  
   554  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   555  	b = append(b, pt.timeSeparator...)
   556  
   557  	if t.Second() < 10 {
   558  		b = append(b, '0')
   559  	}
   560  
   561  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   562  
   563  	return string(b)
   564  }
   565  
   566  // FmtTimeLong returns the long time representation of 't' for 'pt'
   567  func (pt *pt) FmtTimeLong(t time.Time) string {
   568  
   569  	b := make([]byte, 0, 32)
   570  
   571  	if t.Hour() < 10 {
   572  		b = append(b, '0')
   573  	}
   574  
   575  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   576  	b = append(b, pt.timeSeparator...)
   577  
   578  	if t.Minute() < 10 {
   579  		b = append(b, '0')
   580  	}
   581  
   582  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   583  	b = append(b, pt.timeSeparator...)
   584  
   585  	if t.Second() < 10 {
   586  		b = append(b, '0')
   587  	}
   588  
   589  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   590  	b = append(b, []byte{0x20}...)
   591  
   592  	tz, _ := t.Zone()
   593  	b = append(b, tz...)
   594  
   595  	return string(b)
   596  }
   597  
   598  // FmtTimeFull returns the full time representation of 't' for 'pt'
   599  func (pt *pt) FmtTimeFull(t time.Time) string {
   600  
   601  	b := make([]byte, 0, 32)
   602  
   603  	if t.Hour() < 10 {
   604  		b = append(b, '0')
   605  	}
   606  
   607  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   608  	b = append(b, pt.timeSeparator...)
   609  
   610  	if t.Minute() < 10 {
   611  		b = append(b, '0')
   612  	}
   613  
   614  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   615  	b = append(b, pt.timeSeparator...)
   616  
   617  	if t.Second() < 10 {
   618  		b = append(b, '0')
   619  	}
   620  
   621  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   622  	b = append(b, []byte{0x20}...)
   623  
   624  	tz, _ := t.Zone()
   625  
   626  	if btz, ok := pt.timezones[tz]; ok {
   627  		b = append(b, btz...)
   628  	} else {
   629  		b = append(b, tz...)
   630  	}
   631  
   632  	return string(b)
   633  }
   634  

View as plain text