...

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

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

     1  package kea
     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 kea 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  	currencyNegativePrefix 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 'kea' locale
    46  func New() locales.Translator {
    47  	return &kea{
    48  		locale:                 "kea",
    49  		pluralsCardinal:        []locales.PluralRule{6},
    50  		pluralsOrdinal:         nil,
    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", "AU$", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "৳", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "$", "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", "\u200b", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "$", "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", "៛", "KMF", "KPW", "KRH", "KRO", "₩", "KWD", "KYD", "₸", "₭", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "₮", "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", "₱", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "$", "SCR", "SDD", "SDG", "SDP", "SEK", "$", "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", "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"},
    60  		currencyPositiveSuffix: " ",
    61  		currencyNegativePrefix: "(",
    62  		currencyNegativeSuffix: " )",
    63  		monthsAbbreviated:      []string{"", "Jan", "Feb", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Otu", "Nuv", "Diz"},
    64  		monthsNarrow:           []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
    65  		monthsWide:             []string{"", "Janeru", "Febreru", "Marsu", "Abril", "Maiu", "Junhu", "Julhu", "Agostu", "Setenbru", "Otubru", "Nuvenbru", "Dizenbru"},
    66  		daysAbbreviated:        []string{"dum", "sig", "ter", "kua", "kin", "ses", "sab"},
    67  		daysNarrow:             []string{"D", "S", "T", "K", "K", "S", "S"},
    68  		daysShort:              []string{"du", "si", "te", "ku", "ki", "se", "sa"},
    69  		daysWide:               []string{"dumingu", "sigunda-fera", "tersa-fera", "kuarta-fera", "kinta-fera", "sesta-fera", "sabadu"},
    70  		periodsAbbreviated:     []string{"am", "pm"},
    71  		periodsWide:            []string{"am", "pm"},
    72  		erasAbbreviated:        []string{"AK", "DK"},
    73  		erasNarrow:             []string{"", ""},
    74  		erasWide:               []string{"antis di Kristu", "dispos di Kristu"},
    75  		timezones:              map[string]string{"ACDT": "Ora di Veron di Austrália Sentral", "ACST": "Ora Padron di Austrália Sentral", "ACWDT": "Ora di Veron di Austrália Sentru-Osidental", "ACWST": "Ora Padron di Austrália Sentru-Osidental", "ADT": "Ora di Veron di Atlántiku", "AEDT": "Ora di Veron di Austrália Oriental", "AEST": "Ora Padron di Austrália Oriental", "AKDT": "Ora di Veron di Alaska", "AKST": "Ora Padron di Alaska", "ARST": "ARST", "ART": "ART", "AST": "Ora Padron di Atlántiku", "AWDT": "Ora di Veron di Austrália Osidental", "AWST": "Ora Padron di Austrália Osidental", "BOT": "BOT", "BT": "BT", "CAT": "Ora di Áfrika Sentral", "CDT": "Ora di Veron Sentral", "CHADT": "CHADT", "CHAST": "CHAST", "CLST": "CLST", "CLT": "CLT", "COST": "COST", "COT": "COT", "CST": "Ora Padron Sentral", "ChST": "ChST", "EAT": "Ora di Áfrika Oriental", "ECT": "ECT", "EDT": "Ora di Veron Oriental", "EST": "Ora Padron Oriental", "GFT": "GFT", "GMT": "Ora Médiu di Greenwich", "GST": "GST", "GYT": "GYT", "HADT": "HADT", "HAST": "HAST", "HAT": "HAT", "HECU": "Ora di Veron di Kuba", "HEEG": "HEEG", "HENOMX": "HENOMX", "HEOG": "HEOG", "HEPM": "HEPM", "HEPMX": "HEPMX", "HKST": "HKST", "HKT": "HKT", "HNCU": "Ora Padron di Kuba", "HNEG": "HNEG", "HNNOMX": "HNNOMX", "HNOG": "HNOG", "HNPM": "HNPM", "HNPMX": "HNPMX", "HNT": "HNT", "IST": "IST", "JDT": "JDT", "JST": "JST", "LHDT": "LHDT", "LHST": "LHST", "MDT": "Ora di Veron di Montanha", "MESZ": "Ora di Veron di Europa Sentral", "MEZ": "Ora Padron di Europa Sentral", "MST": "Ora Padron di Montanha", "MYT": "MYT", "NZDT": "NZDT", "NZST": "NZST", "OESZ": "Ora di Veron di Europa Oriental", "OEZ": "Ora Padron di Europa Oriental", "PDT": "Ora di Veron di Pasífiku", "PST": "Ora Padron di Pasífiku", "SAST": "Ora di Sul di Áfrika", "SGT": "SGT", "SRT": "SRT", "TMST": "TMST", "TMT": "TMT", "UYST": "UYST", "UYT": "UYT", "VET": "VET", "WARST": "WARST", "WART": "WART", "WAST": "Ora di Veron di Áfrika Osidental", "WAT": "Ora Padron di Áfrika Osidental", "WESZ": "Ora di Veron di Europa Osidental", "WEZ": "Ora Padron di Europa Osidental", "WIB": "WIB", "WIT": "WIT", "WITA": "WITA", "∅∅∅": "∅∅∅"},
    76  	}
    77  }
    78  
    79  // Locale returns the current translators string locale
    80  func (kea *kea) Locale() string {
    81  	return kea.locale
    82  }
    83  
    84  // PluralsCardinal returns the list of cardinal plural rules associated with 'kea'
    85  func (kea *kea) PluralsCardinal() []locales.PluralRule {
    86  	return kea.pluralsCardinal
    87  }
    88  
    89  // PluralsOrdinal returns the list of ordinal plural rules associated with 'kea'
    90  func (kea *kea) PluralsOrdinal() []locales.PluralRule {
    91  	return kea.pluralsOrdinal
    92  }
    93  
    94  // PluralsRange returns the list of range plural rules associated with 'kea'
    95  func (kea *kea) PluralsRange() []locales.PluralRule {
    96  	return kea.pluralsRange
    97  }
    98  
    99  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'kea'
   100  func (kea *kea) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
   101  	return locales.PluralRuleOther
   102  }
   103  
   104  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'kea'
   105  func (kea *kea) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
   106  	return locales.PluralRuleUnknown
   107  }
   108  
   109  // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'kea'
   110  func (kea *kea) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   111  	return locales.PluralRuleUnknown
   112  }
   113  
   114  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   115  func (kea *kea) MonthAbbreviated(month time.Month) string {
   116  	return kea.monthsAbbreviated[month]
   117  }
   118  
   119  // MonthsAbbreviated returns the locales abbreviated months
   120  func (kea *kea) MonthsAbbreviated() []string {
   121  	return kea.monthsAbbreviated[1:]
   122  }
   123  
   124  // MonthNarrow returns the locales narrow month given the 'month' provided
   125  func (kea *kea) MonthNarrow(month time.Month) string {
   126  	return kea.monthsNarrow[month]
   127  }
   128  
   129  // MonthsNarrow returns the locales narrow months
   130  func (kea *kea) MonthsNarrow() []string {
   131  	return kea.monthsNarrow[1:]
   132  }
   133  
   134  // MonthWide returns the locales wide month given the 'month' provided
   135  func (kea *kea) MonthWide(month time.Month) string {
   136  	return kea.monthsWide[month]
   137  }
   138  
   139  // MonthsWide returns the locales wide months
   140  func (kea *kea) MonthsWide() []string {
   141  	return kea.monthsWide[1:]
   142  }
   143  
   144  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   145  func (kea *kea) WeekdayAbbreviated(weekday time.Weekday) string {
   146  	return kea.daysAbbreviated[weekday]
   147  }
   148  
   149  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   150  func (kea *kea) WeekdaysAbbreviated() []string {
   151  	return kea.daysAbbreviated
   152  }
   153  
   154  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   155  func (kea *kea) WeekdayNarrow(weekday time.Weekday) string {
   156  	return kea.daysNarrow[weekday]
   157  }
   158  
   159  // WeekdaysNarrow returns the locales narrow weekdays
   160  func (kea *kea) WeekdaysNarrow() []string {
   161  	return kea.daysNarrow
   162  }
   163  
   164  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   165  func (kea *kea) WeekdayShort(weekday time.Weekday) string {
   166  	return kea.daysShort[weekday]
   167  }
   168  
   169  // WeekdaysShort returns the locales short weekdays
   170  func (kea *kea) WeekdaysShort() []string {
   171  	return kea.daysShort
   172  }
   173  
   174  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   175  func (kea *kea) WeekdayWide(weekday time.Weekday) string {
   176  	return kea.daysWide[weekday]
   177  }
   178  
   179  // WeekdaysWide returns the locales wide weekdays
   180  func (kea *kea) WeekdaysWide() []string {
   181  	return kea.daysWide
   182  }
   183  
   184  // Decimal returns the decimal point of number
   185  func (kea *kea) Decimal() string {
   186  	return kea.decimal
   187  }
   188  
   189  // Group returns the group of number
   190  func (kea *kea) Group() string {
   191  	return kea.group
   192  }
   193  
   194  // Group returns the minus sign of number
   195  func (kea *kea) Minus() string {
   196  	return kea.minus
   197  }
   198  
   199  // FmtNumber returns 'num' with digits/precision of 'v' for 'kea' and handles both Whole and Real numbers based on 'v'
   200  func (kea *kea) FmtNumber(num float64, v uint64) string {
   201  
   202  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   203  	l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
   204  	count := 0
   205  	inWhole := v == 0
   206  	b := make([]byte, 0, l)
   207  
   208  	for i := len(s) - 1; i >= 0; i-- {
   209  
   210  		if s[i] == '.' {
   211  			b = append(b, kea.decimal[0])
   212  			inWhole = true
   213  			continue
   214  		}
   215  
   216  		if inWhole {
   217  			if count == 3 {
   218  				for j := len(kea.group) - 1; j >= 0; j-- {
   219  					b = append(b, kea.group[j])
   220  				}
   221  				count = 1
   222  			} else {
   223  				count++
   224  			}
   225  		}
   226  
   227  		b = append(b, s[i])
   228  	}
   229  
   230  	if num < 0 {
   231  		b = append(b, kea.minus[0])
   232  	}
   233  
   234  	// reverse
   235  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   236  		b[i], b[j] = b[j], b[i]
   237  	}
   238  
   239  	return string(b)
   240  }
   241  
   242  // FmtPercent returns 'num' with digits/precision of 'v' for 'kea' and handles both Whole and Real numbers based on 'v'
   243  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   244  func (kea *kea) FmtPercent(num float64, v uint64) string {
   245  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   246  	l := len(s) + 3
   247  	b := make([]byte, 0, l)
   248  
   249  	for i := len(s) - 1; i >= 0; i-- {
   250  
   251  		if s[i] == '.' {
   252  			b = append(b, kea.decimal[0])
   253  			continue
   254  		}
   255  
   256  		b = append(b, s[i])
   257  	}
   258  
   259  	if num < 0 {
   260  		b = append(b, kea.minus[0])
   261  	}
   262  
   263  	// reverse
   264  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   265  		b[i], b[j] = b[j], b[i]
   266  	}
   267  
   268  	b = append(b, kea.percent...)
   269  
   270  	return string(b)
   271  }
   272  
   273  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'kea'
   274  func (kea *kea) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   275  
   276  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   277  	symbol := kea.currencies[currency]
   278  	l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
   279  	count := 0
   280  	inWhole := v == 0
   281  	b := make([]byte, 0, l)
   282  
   283  	for i := len(s) - 1; i >= 0; i-- {
   284  
   285  		if s[i] == '.' {
   286  			b = append(b, kea.decimal[0])
   287  			inWhole = true
   288  			continue
   289  		}
   290  
   291  		if inWhole {
   292  			if count == 3 {
   293  				for j := len(kea.group) - 1; j >= 0; j-- {
   294  					b = append(b, kea.group[j])
   295  				}
   296  				count = 1
   297  			} else {
   298  				count++
   299  			}
   300  		}
   301  
   302  		b = append(b, s[i])
   303  	}
   304  
   305  	if num < 0 {
   306  		b = append(b, kea.minus[0])
   307  	}
   308  
   309  	// reverse
   310  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   311  		b[i], b[j] = b[j], b[i]
   312  	}
   313  
   314  	if int(v) < 2 {
   315  
   316  		if v == 0 {
   317  			b = append(b, kea.decimal...)
   318  		}
   319  
   320  		for i := 0; i < 2-int(v); i++ {
   321  			b = append(b, '0')
   322  		}
   323  	}
   324  
   325  	b = append(b, kea.currencyPositiveSuffix...)
   326  
   327  	b = append(b, symbol...)
   328  
   329  	return string(b)
   330  }
   331  
   332  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'kea'
   333  // in accounting notation.
   334  func (kea *kea) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   335  
   336  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   337  	symbol := kea.currencies[currency]
   338  	l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
   339  	count := 0
   340  	inWhole := v == 0
   341  	b := make([]byte, 0, l)
   342  
   343  	for i := len(s) - 1; i >= 0; i-- {
   344  
   345  		if s[i] == '.' {
   346  			b = append(b, kea.decimal[0])
   347  			inWhole = true
   348  			continue
   349  		}
   350  
   351  		if inWhole {
   352  			if count == 3 {
   353  				for j := len(kea.group) - 1; j >= 0; j-- {
   354  					b = append(b, kea.group[j])
   355  				}
   356  				count = 1
   357  			} else {
   358  				count++
   359  			}
   360  		}
   361  
   362  		b = append(b, s[i])
   363  	}
   364  
   365  	if num < 0 {
   366  
   367  		b = append(b, kea.currencyNegativePrefix[0])
   368  
   369  	}
   370  
   371  	// reverse
   372  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   373  		b[i], b[j] = b[j], b[i]
   374  	}
   375  
   376  	if int(v) < 2 {
   377  
   378  		if v == 0 {
   379  			b = append(b, kea.decimal...)
   380  		}
   381  
   382  		for i := 0; i < 2-int(v); i++ {
   383  			b = append(b, '0')
   384  		}
   385  	}
   386  
   387  	if num < 0 {
   388  		b = append(b, kea.currencyNegativeSuffix...)
   389  		b = append(b, symbol...)
   390  	} else {
   391  
   392  		b = append(b, kea.currencyPositiveSuffix...)
   393  		b = append(b, symbol...)
   394  	}
   395  
   396  	return string(b)
   397  }
   398  
   399  // FmtDateShort returns the short date representation of 't' for 'kea'
   400  func (kea *kea) FmtDateShort(t time.Time) string {
   401  
   402  	b := make([]byte, 0, 32)
   403  
   404  	if t.Day() < 10 {
   405  		b = append(b, '0')
   406  	}
   407  
   408  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   409  	b = append(b, []byte{0x2f}...)
   410  
   411  	if t.Month() < 10 {
   412  		b = append(b, '0')
   413  	}
   414  
   415  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   416  
   417  	b = append(b, []byte{0x2f}...)
   418  
   419  	if t.Year() > 0 {
   420  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   421  	} else {
   422  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   423  	}
   424  
   425  	return string(b)
   426  }
   427  
   428  // FmtDateMedium returns the medium date representation of 't' for 'kea'
   429  func (kea *kea) FmtDateMedium(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{0x20}...)
   435  	b = append(b, kea.monthsAbbreviated[t.Month()]...)
   436  	b = append(b, []byte{0x20}...)
   437  
   438  	if t.Year() > 0 {
   439  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   440  	} else {
   441  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   442  	}
   443  
   444  	return string(b)
   445  }
   446  
   447  // FmtDateLong returns the long date representation of 't' for 'kea'
   448  func (kea *kea) FmtDateLong(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, 0x64, 0x69}...)
   454  	b = append(b, []byte{0x20}...)
   455  	b = append(b, kea.monthsWide[t.Month()]...)
   456  	b = append(b, []byte{0x20, 0x64, 0x69}...)
   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 'kea'
   469  func (kea *kea) FmtDateFull(t time.Time) string {
   470  
   471  	b := make([]byte, 0, 32)
   472  
   473  	b = append(b, kea.daysWide[t.Weekday()]...)
   474  	b = append(b, []byte{0x2c, 0x20}...)
   475  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   476  	b = append(b, []byte{0x20, 0x64, 0x69}...)
   477  	b = append(b, []byte{0x20}...)
   478  	b = append(b, kea.monthsWide[t.Month()]...)
   479  	b = append(b, []byte{0x20, 0x64, 0x69}...)
   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  // FmtTimeShort returns the short time representation of 't' for 'kea'
   492  func (kea *kea) FmtTimeShort(t time.Time) string {
   493  
   494  	b := make([]byte, 0, 32)
   495  
   496  	if t.Hour() < 10 {
   497  		b = append(b, '0')
   498  	}
   499  
   500  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   501  	b = append(b, kea.timeSeparator...)
   502  
   503  	if t.Minute() < 10 {
   504  		b = append(b, '0')
   505  	}
   506  
   507  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   508  
   509  	return string(b)
   510  }
   511  
   512  // FmtTimeMedium returns the medium time representation of 't' for 'kea'
   513  func (kea *kea) FmtTimeMedium(t time.Time) string {
   514  
   515  	b := make([]byte, 0, 32)
   516  
   517  	if t.Hour() < 10 {
   518  		b = append(b, '0')
   519  	}
   520  
   521  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   522  	b = append(b, kea.timeSeparator...)
   523  
   524  	if t.Minute() < 10 {
   525  		b = append(b, '0')
   526  	}
   527  
   528  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   529  	b = append(b, kea.timeSeparator...)
   530  
   531  	if t.Second() < 10 {
   532  		b = append(b, '0')
   533  	}
   534  
   535  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   536  
   537  	return string(b)
   538  }
   539  
   540  // FmtTimeLong returns the long time representation of 't' for 'kea'
   541  func (kea *kea) FmtTimeLong(t time.Time) string {
   542  
   543  	b := make([]byte, 0, 32)
   544  
   545  	if t.Hour() < 10 {
   546  		b = append(b, '0')
   547  	}
   548  
   549  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   550  	b = append(b, kea.timeSeparator...)
   551  
   552  	if t.Minute() < 10 {
   553  		b = append(b, '0')
   554  	}
   555  
   556  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   557  	b = append(b, kea.timeSeparator...)
   558  
   559  	if t.Second() < 10 {
   560  		b = append(b, '0')
   561  	}
   562  
   563  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   564  	b = append(b, []byte{0x20}...)
   565  
   566  	tz, _ := t.Zone()
   567  	b = append(b, tz...)
   568  
   569  	return string(b)
   570  }
   571  
   572  // FmtTimeFull returns the full time representation of 't' for 'kea'
   573  func (kea *kea) FmtTimeFull(t time.Time) string {
   574  
   575  	b := make([]byte, 0, 32)
   576  
   577  	if t.Hour() < 10 {
   578  		b = append(b, '0')
   579  	}
   580  
   581  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   582  	b = append(b, kea.timeSeparator...)
   583  
   584  	if t.Minute() < 10 {
   585  		b = append(b, '0')
   586  	}
   587  
   588  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   589  	b = append(b, kea.timeSeparator...)
   590  
   591  	if t.Second() < 10 {
   592  		b = append(b, '0')
   593  	}
   594  
   595  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   596  	b = append(b, []byte{0x20}...)
   597  
   598  	tz, _ := t.Zone()
   599  
   600  	if btz, ok := kea.timezones[tz]; ok {
   601  		b = append(b, btz...)
   602  	} else {
   603  		b = append(b, tz...)
   604  	}
   605  
   606  	return string(b)
   607  }
   608  

View as plain text