...

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

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

     1  package tr
     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 tr 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  	currencyNegativePrefix 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 'tr' locale
    45  func New() locales.Translator {
    46  	return &tr{
    47  		locale:                 "tr",
    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", "¥", "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", "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", "₺", "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"},
    59  		currencyNegativePrefix: "(",
    60  		currencyNegativeSuffix: ")",
    61  		monthsAbbreviated:      []string{"", "Oca", "Şub", "Mar", "Nis", "May", "Haz", "Tem", "Ağu", "Eyl", "Eki", "Kas", "Ara"},
    62  		monthsNarrow:           []string{"", "O", "Ş", "M", "N", "M", "H", "T", "A", "E", "E", "K", "A"},
    63  		monthsWide:             []string{"", "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"},
    64  		daysAbbreviated:        []string{"Paz", "Pzt", "Sal", "Çar", "Per", "Cum", "Cmt"},
    65  		daysNarrow:             []string{"P", "P", "S", "Ç", "P", "C", "C"},
    66  		daysShort:              []string{"Pa", "Pt", "Sa", "Ça", "Pe", "Cu", "Ct"},
    67  		daysWide:               []string{"Pazar", "Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi"},
    68  		periodsAbbreviated:     []string{"ÖÖ", "ÖS"},
    69  		periodsNarrow:          []string{"öö", "ös"},
    70  		periodsWide:            []string{"ÖÖ", "ÖS"},
    71  		erasAbbreviated:        []string{"MÖ", "MS"},
    72  		erasNarrow:             []string{"", ""},
    73  		erasWide:               []string{"Milattan Önce", "Milattan Sonra"},
    74  		timezones:              map[string]string{"ACDT": "Orta Avustralya Yaz Saati", "ACST": "Orta Avustralya Standart Saati", "ACWDT": "İç Batı Avustralya Yaz Saati", "ACWST": "İç Batı Avustralya Standart Saati", "ADT": "Atlantik Yaz Saati", "AEDT": "Doğu Avustralya Yaz Saati", "AEST": "Doğu Avustralya Standart Saati", "AKDT": "Alaska Yaz Saati", "AKST": "Alaska Standart Saati", "ARST": "Arjantin Yaz Saati", "ART": "Arjantin Standart Saati", "AST": "Atlantik Standart Saati", "AWDT": "Batı Avustralya Yaz Saati", "AWST": "Batı Avustralya Standart Saati", "BOT": "Bolivya Saati", "BT": "Butan Saati", "CAT": "Orta Afrika Saati", "CDT": "Kuzey Amerika Merkezi Yaz Saati", "CHADT": "Chatham Yaz Saati", "CHAST": "Chatham Standart Saati", "CLST": "Şili Yaz Saati", "CLT": "Şili Standart Saati", "COST": "Kolombiya Yaz Saati", "COT": "Kolombiya Standart Saati", "CST": "Kuzey Amerika Merkezi Standart Saati", "ChST": "Chamorro Saati", "EAT": "Doğu Afrika Saati", "ECT": "Ekvador Saati", "EDT": "Kuzey Amerika Doğu Yaz Saati", "EST": "Kuzey Amerika Doğu Standart Saati", "GFT": "Fransız Guyanası Saati", "GMT": "Greenwich Ortalama Saati", "GST": "Körfez Saati", "GYT": "Guyana Saati", "HADT": "Hawaii-Aleut Yaz Saati", "HAST": "Hawaii-Aleut Standart Saati", "HAT": "Newfoundland Yaz Saati", "HECU": "Küba Yaz Saati", "HEEG": "Doğu Grönland Yaz Saati", "HENOMX": "Kuzeybatı Meksika Yaz Saati", "HEOG": "Batı Grönland Yaz Saati", "HEPM": "Saint Pierre ve Miquelon Yaz Saati", "HEPMX": "Meksika Pasifik Kıyısı Yaz Saati", "HKST": "Hong Kong Yaz Saati", "HKT": "Hong Kong Standart Saati", "HNCU": "Küba Standart Saati", "HNEG": "Doğu Grönland Standart Saati", "HNNOMX": "Kuzeybatı Meksika Standart Saati", "HNOG": "Batı Grönland Standart Saati", "HNPM": "Saint Pierre ve Miquelon Standart Saati", "HNPMX": "Meksika Pasifik Kıyısı Standart Saati", "HNT": "Newfoundland Standart Saati", "IST": "Hindistan Standart Saati", "JDT": "Japonya Yaz Saati", "JST": "Japonya Standart Saati", "LHDT": "Lord Howe Yaz Saati", "LHST": "Lord Howe Standart Saati", "MDT": "Kuzey Amerika Dağ Yaz Saati", "MESZ": "Orta Avrupa Yaz Saati", "MEZ": "Orta Avrupa Standart Saati", "MST": "Kuzey Amerika Dağ Standart Saati", "MYT": "Malezya Saati", "NZDT": "Yeni Zelanda Yaz Saati", "NZST": "Yeni Zelanda Standart Saati", "OESZ": "Doğu Avrupa Yaz Saati", "OEZ": "Doğu Avrupa Standart Saati", "PDT": "Kuzey Amerika Pasifik Yaz Saati", "PST": "Kuzey Amerika Pasifik Standart Saati", "SAST": "Güney Afrika Standart Saati", "SGT": "Singapur Standart Saati", "SRT": "Surinam Saati", "TMST": "Türkmenistan Yaz Saati", "TMT": "Türkmenistan Standart Saati", "UYST": "Uruguay Yaz Saati", "UYT": "Uruguay Standart Saati", "VET": "Venezuela Saati", "WARST": "Batı Arjantin Yaz Saati", "WART": "Batı Arjantin Standart Saati", "WAST": "Batı Afrika Yaz Saati", "WAT": "Batı Afrika Standart Saati", "WESZ": "Batı Avrupa Yaz Saati", "WEZ": "Batı Avrupa Standart Saati", "WIB": "Batı Endonezya Saati", "WIT": "Doğu Endonezya Saati", "WITA": "Orta Endonezya Saati", "∅∅∅": "Azorlar Yaz Saati"},
    75  	}
    76  }
    77  
    78  // Locale returns the current translators string locale
    79  func (tr *tr) Locale() string {
    80  	return tr.locale
    81  }
    82  
    83  // PluralsCardinal returns the list of cardinal plural rules associated with 'tr'
    84  func (tr *tr) PluralsCardinal() []locales.PluralRule {
    85  	return tr.pluralsCardinal
    86  }
    87  
    88  // PluralsOrdinal returns the list of ordinal plural rules associated with 'tr'
    89  func (tr *tr) PluralsOrdinal() []locales.PluralRule {
    90  	return tr.pluralsOrdinal
    91  }
    92  
    93  // PluralsRange returns the list of range plural rules associated with 'tr'
    94  func (tr *tr) PluralsRange() []locales.PluralRule {
    95  	return tr.pluralsRange
    96  }
    97  
    98  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'tr'
    99  func (tr *tr) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
   100  
   101  	n := math.Abs(num)
   102  
   103  	if n == 1 {
   104  		return locales.PluralRuleOne
   105  	}
   106  
   107  	return locales.PluralRuleOther
   108  }
   109  
   110  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'tr'
   111  func (tr *tr) 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 'tr'
   116  func (tr *tr) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   117  
   118  	start := tr.CardinalPluralRule(num1, v1)
   119  	end := tr.CardinalPluralRule(num2, v2)
   120  
   121  	if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
   122  		return locales.PluralRuleOther
   123  	} else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
   124  		return locales.PluralRuleOne
   125  	}
   126  
   127  	return locales.PluralRuleOther
   128  
   129  }
   130  
   131  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   132  func (tr *tr) MonthAbbreviated(month time.Month) string {
   133  	return tr.monthsAbbreviated[month]
   134  }
   135  
   136  // MonthsAbbreviated returns the locales abbreviated months
   137  func (tr *tr) MonthsAbbreviated() []string {
   138  	return tr.monthsAbbreviated[1:]
   139  }
   140  
   141  // MonthNarrow returns the locales narrow month given the 'month' provided
   142  func (tr *tr) MonthNarrow(month time.Month) string {
   143  	return tr.monthsNarrow[month]
   144  }
   145  
   146  // MonthsNarrow returns the locales narrow months
   147  func (tr *tr) MonthsNarrow() []string {
   148  	return tr.monthsNarrow[1:]
   149  }
   150  
   151  // MonthWide returns the locales wide month given the 'month' provided
   152  func (tr *tr) MonthWide(month time.Month) string {
   153  	return tr.monthsWide[month]
   154  }
   155  
   156  // MonthsWide returns the locales wide months
   157  func (tr *tr) MonthsWide() []string {
   158  	return tr.monthsWide[1:]
   159  }
   160  
   161  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   162  func (tr *tr) WeekdayAbbreviated(weekday time.Weekday) string {
   163  	return tr.daysAbbreviated[weekday]
   164  }
   165  
   166  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   167  func (tr *tr) WeekdaysAbbreviated() []string {
   168  	return tr.daysAbbreviated
   169  }
   170  
   171  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   172  func (tr *tr) WeekdayNarrow(weekday time.Weekday) string {
   173  	return tr.daysNarrow[weekday]
   174  }
   175  
   176  // WeekdaysNarrow returns the locales narrow weekdays
   177  func (tr *tr) WeekdaysNarrow() []string {
   178  	return tr.daysNarrow
   179  }
   180  
   181  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   182  func (tr *tr) WeekdayShort(weekday time.Weekday) string {
   183  	return tr.daysShort[weekday]
   184  }
   185  
   186  // WeekdaysShort returns the locales short weekdays
   187  func (tr *tr) WeekdaysShort() []string {
   188  	return tr.daysShort
   189  }
   190  
   191  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   192  func (tr *tr) WeekdayWide(weekday time.Weekday) string {
   193  	return tr.daysWide[weekday]
   194  }
   195  
   196  // WeekdaysWide returns the locales wide weekdays
   197  func (tr *tr) WeekdaysWide() []string {
   198  	return tr.daysWide
   199  }
   200  
   201  // Decimal returns the decimal point of number
   202  func (tr *tr) Decimal() string {
   203  	return tr.decimal
   204  }
   205  
   206  // Group returns the group of number
   207  func (tr *tr) Group() string {
   208  	return tr.group
   209  }
   210  
   211  // Group returns the minus sign of number
   212  func (tr *tr) Minus() string {
   213  	return tr.minus
   214  }
   215  
   216  // FmtNumber returns 'num' with digits/precision of 'v' for 'tr' and handles both Whole and Real numbers based on 'v'
   217  func (tr *tr) 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, tr.decimal[0])
   229  			inWhole = true
   230  			continue
   231  		}
   232  
   233  		if inWhole {
   234  			if count == 3 {
   235  				b = append(b, tr.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, tr.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 'tr' 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 (tr *tr) FmtPercent(num float64, v uint64) string {
   260  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   261  	l := len(s) + 3 + 1*len(s[:len(s)-int(v)-1])/3
   262  	count := 0
   263  	inWhole := v == 0
   264  	b := make([]byte, 0, l)
   265  
   266  	for i := len(s) - 1; i >= 0; i-- {
   267  
   268  		if s[i] == '.' {
   269  			b = append(b, tr.decimal[0])
   270  			inWhole = true
   271  
   272  			continue
   273  		}
   274  
   275  		if inWhole {
   276  			if count == 3 {
   277  				b = append(b, tr.group[0])
   278  				count = 1
   279  			} else {
   280  				count++
   281  			}
   282  		}
   283  
   284  		b = append(b, s[i])
   285  	}
   286  
   287  	if num < 0 {
   288  		b = append(b, tr.minus[0])
   289  	}
   290  
   291  	b = append(b, tr.percent[0])
   292  
   293  	// reverse
   294  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   295  		b[i], b[j] = b[j], b[i]
   296  	}
   297  
   298  	return string(b)
   299  }
   300  
   301  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'tr'
   302  func (tr *tr) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   303  
   304  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   305  	symbol := tr.currencies[currency]
   306  	l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
   307  	count := 0
   308  	inWhole := v == 0
   309  	b := make([]byte, 0, l)
   310  
   311  	for i := len(s) - 1; i >= 0; i-- {
   312  
   313  		if s[i] == '.' {
   314  			b = append(b, tr.decimal[0])
   315  			inWhole = true
   316  			continue
   317  		}
   318  
   319  		if inWhole {
   320  			if count == 3 {
   321  				b = append(b, tr.group[0])
   322  				count = 1
   323  			} else {
   324  				count++
   325  			}
   326  		}
   327  
   328  		b = append(b, s[i])
   329  	}
   330  
   331  	for j := len(symbol) - 1; j >= 0; j-- {
   332  		b = append(b, symbol[j])
   333  	}
   334  
   335  	if num < 0 {
   336  		b = append(b, tr.minus[0])
   337  	}
   338  
   339  	// reverse
   340  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   341  		b[i], b[j] = b[j], b[i]
   342  	}
   343  
   344  	if int(v) < 2 {
   345  
   346  		if v == 0 {
   347  			b = append(b, tr.decimal...)
   348  		}
   349  
   350  		for i := 0; i < 2-int(v); i++ {
   351  			b = append(b, '0')
   352  		}
   353  	}
   354  
   355  	return string(b)
   356  }
   357  
   358  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'tr'
   359  // in accounting notation.
   360  func (tr *tr) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   361  
   362  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   363  	symbol := tr.currencies[currency]
   364  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   365  	count := 0
   366  	inWhole := v == 0
   367  	b := make([]byte, 0, l)
   368  
   369  	for i := len(s) - 1; i >= 0; i-- {
   370  
   371  		if s[i] == '.' {
   372  			b = append(b, tr.decimal[0])
   373  			inWhole = true
   374  			continue
   375  		}
   376  
   377  		if inWhole {
   378  			if count == 3 {
   379  				b = append(b, tr.group[0])
   380  				count = 1
   381  			} else {
   382  				count++
   383  			}
   384  		}
   385  
   386  		b = append(b, s[i])
   387  	}
   388  
   389  	if num < 0 {
   390  
   391  		for j := len(symbol) - 1; j >= 0; j-- {
   392  			b = append(b, symbol[j])
   393  		}
   394  
   395  		b = append(b, tr.currencyNegativePrefix[0])
   396  
   397  	} else {
   398  
   399  		for j := len(symbol) - 1; j >= 0; j-- {
   400  			b = append(b, symbol[j])
   401  		}
   402  
   403  	}
   404  
   405  	// reverse
   406  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   407  		b[i], b[j] = b[j], b[i]
   408  	}
   409  
   410  	if int(v) < 2 {
   411  
   412  		if v == 0 {
   413  			b = append(b, tr.decimal...)
   414  		}
   415  
   416  		for i := 0; i < 2-int(v); i++ {
   417  			b = append(b, '0')
   418  		}
   419  	}
   420  
   421  	if num < 0 {
   422  		b = append(b, tr.currencyNegativeSuffix...)
   423  	}
   424  
   425  	return string(b)
   426  }
   427  
   428  // FmtDateShort returns the short date representation of 't' for 'tr'
   429  func (tr *tr) FmtDateShort(t time.Time) string {
   430  
   431  	b := make([]byte, 0, 32)
   432  
   433  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   434  	b = append(b, []byte{0x2e}...)
   435  
   436  	if t.Month() < 10 {
   437  		b = append(b, '0')
   438  	}
   439  
   440  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   441  
   442  	b = append(b, []byte{0x2e}...)
   443  
   444  	if t.Year() > 0 {
   445  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   446  	} else {
   447  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   448  	}
   449  
   450  	return string(b)
   451  }
   452  
   453  // FmtDateMedium returns the medium date representation of 't' for 'tr'
   454  func (tr *tr) FmtDateMedium(t time.Time) string {
   455  
   456  	b := make([]byte, 0, 32)
   457  
   458  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   459  	b = append(b, []byte{0x20}...)
   460  	b = append(b, tr.monthsAbbreviated[t.Month()]...)
   461  	b = append(b, []byte{0x20}...)
   462  
   463  	if t.Year() > 0 {
   464  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   465  	} else {
   466  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   467  	}
   468  
   469  	return string(b)
   470  }
   471  
   472  // FmtDateLong returns the long date representation of 't' for 'tr'
   473  func (tr *tr) FmtDateLong(t time.Time) string {
   474  
   475  	b := make([]byte, 0, 32)
   476  
   477  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   478  	b = append(b, []byte{0x20}...)
   479  	b = append(b, tr.monthsWide[t.Month()]...)
   480  	b = append(b, []byte{0x20}...)
   481  
   482  	if t.Year() > 0 {
   483  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   484  	} else {
   485  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   486  	}
   487  
   488  	return string(b)
   489  }
   490  
   491  // FmtDateFull returns the full date representation of 't' for 'tr'
   492  func (tr *tr) FmtDateFull(t time.Time) string {
   493  
   494  	b := make([]byte, 0, 32)
   495  
   496  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   497  	b = append(b, []byte{0x20}...)
   498  	b = append(b, tr.monthsWide[t.Month()]...)
   499  	b = append(b, []byte{0x20}...)
   500  
   501  	if t.Year() > 0 {
   502  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   503  	} else {
   504  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   505  	}
   506  
   507  	b = append(b, []byte{0x20}...)
   508  	b = append(b, tr.daysWide[t.Weekday()]...)
   509  
   510  	return string(b)
   511  }
   512  
   513  // FmtTimeShort returns the short time representation of 't' for 'tr'
   514  func (tr *tr) FmtTimeShort(t time.Time) string {
   515  
   516  	b := make([]byte, 0, 32)
   517  
   518  	if t.Hour() < 10 {
   519  		b = append(b, '0')
   520  	}
   521  
   522  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   523  	b = append(b, tr.timeSeparator...)
   524  
   525  	if t.Minute() < 10 {
   526  		b = append(b, '0')
   527  	}
   528  
   529  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   530  
   531  	return string(b)
   532  }
   533  
   534  // FmtTimeMedium returns the medium time representation of 't' for 'tr'
   535  func (tr *tr) FmtTimeMedium(t time.Time) string {
   536  
   537  	b := make([]byte, 0, 32)
   538  
   539  	if t.Hour() < 10 {
   540  		b = append(b, '0')
   541  	}
   542  
   543  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   544  	b = append(b, tr.timeSeparator...)
   545  
   546  	if t.Minute() < 10 {
   547  		b = append(b, '0')
   548  	}
   549  
   550  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   551  	b = append(b, tr.timeSeparator...)
   552  
   553  	if t.Second() < 10 {
   554  		b = append(b, '0')
   555  	}
   556  
   557  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   558  
   559  	return string(b)
   560  }
   561  
   562  // FmtTimeLong returns the long time representation of 't' for 'tr'
   563  func (tr *tr) FmtTimeLong(t time.Time) string {
   564  
   565  	b := make([]byte, 0, 32)
   566  
   567  	if t.Hour() < 10 {
   568  		b = append(b, '0')
   569  	}
   570  
   571  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   572  	b = append(b, tr.timeSeparator...)
   573  
   574  	if t.Minute() < 10 {
   575  		b = append(b, '0')
   576  	}
   577  
   578  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   579  	b = append(b, tr.timeSeparator...)
   580  
   581  	if t.Second() < 10 {
   582  		b = append(b, '0')
   583  	}
   584  
   585  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   586  	b = append(b, []byte{0x20}...)
   587  
   588  	tz, _ := t.Zone()
   589  	b = append(b, tz...)
   590  
   591  	return string(b)
   592  }
   593  
   594  // FmtTimeFull returns the full time representation of 't' for 'tr'
   595  func (tr *tr) FmtTimeFull(t time.Time) string {
   596  
   597  	b := make([]byte, 0, 32)
   598  
   599  	if t.Hour() < 10 {
   600  		b = append(b, '0')
   601  	}
   602  
   603  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   604  	b = append(b, tr.timeSeparator...)
   605  
   606  	if t.Minute() < 10 {
   607  		b = append(b, '0')
   608  	}
   609  
   610  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   611  	b = append(b, tr.timeSeparator...)
   612  
   613  	if t.Second() < 10 {
   614  		b = append(b, '0')
   615  	}
   616  
   617  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   618  	b = append(b, []byte{0x20}...)
   619  
   620  	tz, _ := t.Zone()
   621  
   622  	if btz, ok := tr.timezones[tz]; ok {
   623  		b = append(b, btz...)
   624  	} else {
   625  		b = append(b, tz...)
   626  	}
   627  
   628  	return string(b)
   629  }
   630  

View as plain text