...

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

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

     1  package kw
     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 kw 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  	monthsAbbreviated  []string
    26  	monthsNarrow       []string
    27  	monthsWide         []string
    28  	daysAbbreviated    []string
    29  	daysNarrow         []string
    30  	daysShort          []string
    31  	daysWide           []string
    32  	periodsAbbreviated []string
    33  	periodsNarrow      []string
    34  	periodsShort       []string
    35  	periodsWide        []string
    36  	erasAbbreviated    []string
    37  	erasNarrow         []string
    38  	erasWide           []string
    39  	timezones          map[string]string
    40  }
    41  
    42  // New returns a new instance of translator for the 'kw' locale
    43  func New() locales.Translator {
    44  	return &kw{
    45  		locale:             "kw",
    46  		pluralsCardinal:    []locales.PluralRule{1, 2, 3, 4, 5, 6},
    47  		pluralsOrdinal:     []locales.PluralRule{2, 5, 6},
    48  		pluralsRange:       nil,
    49  		timeSeparator:      ":",
    50  		currencies:         []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CNY", "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", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "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", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZD", "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", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UYW", "UZS", "VEB", "VEF", "VES", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
    51  		monthsAbbreviated:  []string{"", "Gen", "Hwe", "Meu", "Ebr", "Me", "Met", "Gor", "Est", "Gwn", "Hed", "Du", "Kev"},
    52  		monthsWide:         []string{"", "mis Genver", "mis Hwevrer", "mis Meurth", "mis Ebrel", "mis Me", "mis Metheven", "mis Gortheren", "mis Est", "mis Gwynngala", "mis Hedra", "mis Du", "mis Kevardhu"},
    53  		daysAbbreviated:    []string{"Sul", "Lun", "Mth", "Mhr", "Yow", "Gwe", "Sad"},
    54  		daysWide:           []string{"dy Sul", "dy Lun", "dy Meurth", "dy Merher", "dy Yow", "dy Gwener", "dy Sadorn"},
    55  		periodsAbbreviated: []string{"a.m.", "p.m."},
    56  		periodsWide:        []string{"a.m.", "p.m."},
    57  		erasAbbreviated:    []string{"RC", "AD"},
    58  		erasNarrow:         []string{"", ""},
    59  		erasWide:           []string{"", ""},
    60  		timezones:          map[string]string{"ACDT": "ACDT", "ACST": "ACST", "ACWDT": "ACWDT", "ACWST": "ACWST", "ADT": "ADT", "AEDT": "AEDT", "AEST": "AEST", "AKDT": "AKDT", "AKST": "AKST", "ARST": "ARST", "ART": "ART", "AST": "AST", "AWDT": "AWDT", "AWST": "AWST", "BOT": "BOT", "BT": "BT", "CAT": "CAT", "CDT": "CDT", "CHADT": "CHADT", "CHAST": "CHAST", "CLST": "CLST", "CLT": "CLT", "COST": "COST", "COT": "COT", "CST": "CST", "ChST": "ChST", "EAT": "EAT", "ECT": "ECT", "EDT": "EDT", "EST": "EST", "GFT": "GFT", "GMT": "GMT", "GST": "GST", "GYT": "GYT", "HADT": "HADT", "HAST": "HAST", "HAT": "HAT", "HECU": "HECU", "HEEG": "HEEG", "HENOMX": "HENOMX", "HEOG": "HEOG", "HEPM": "HEPM", "HEPMX": "HEPMX", "HKST": "HKST", "HKT": "HKT", "HNCU": "HNCU", "HNEG": "HNEG", "HNNOMX": "HNNOMX", "HNOG": "HNOG", "HNPM": "HNPM", "HNPMX": "HNPMX", "HNT": "HNT", "IST": "IST", "JDT": "JDT", "JST": "JST", "LHDT": "LHDT", "LHST": "LHST", "MDT": "MDT", "MESZ": "MESZ", "MEZ": "MEZ", "MST": "MST", "MYT": "MYT", "NZDT": "NZDT", "NZST": "NZST", "OESZ": "OESZ", "OEZ": "OEZ", "PDT": "PDT", "PST": "PST", "SAST": "SAST", "SGT": "SGT", "SRT": "SRT", "TMST": "TMST", "TMT": "TMT", "UYST": "UYST", "UYT": "UYT", "VET": "VET", "WARST": "WARST", "WART": "WART", "WAST": "WAST", "WAT": "WAT", "WESZ": "WESZ", "WEZ": "WEZ", "WIB": "WIB", "WIT": "WIT", "WITA": "WITA", "∅∅∅": "∅∅∅"},
    61  	}
    62  }
    63  
    64  // Locale returns the current translators string locale
    65  func (kw *kw) Locale() string {
    66  	return kw.locale
    67  }
    68  
    69  // PluralsCardinal returns the list of cardinal plural rules associated with 'kw'
    70  func (kw *kw) PluralsCardinal() []locales.PluralRule {
    71  	return kw.pluralsCardinal
    72  }
    73  
    74  // PluralsOrdinal returns the list of ordinal plural rules associated with 'kw'
    75  func (kw *kw) PluralsOrdinal() []locales.PluralRule {
    76  	return kw.pluralsOrdinal
    77  }
    78  
    79  // PluralsRange returns the list of range plural rules associated with 'kw'
    80  func (kw *kw) PluralsRange() []locales.PluralRule {
    81  	return kw.pluralsRange
    82  }
    83  
    84  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'kw'
    85  func (kw *kw) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
    86  
    87  	n := math.Abs(num)
    88  	nMod100 := math.Mod(n, 100)
    89  	nMod1000 := math.Mod(n, 1000)
    90  	nMod100000 := math.Mod(n, 100000)
    91  	nMod1000000 := math.Mod(n, 1000000)
    92  
    93  	if n == 0 {
    94  		return locales.PluralRuleZero
    95  	} else if n == 1 {
    96  		return locales.PluralRuleOne
    97  	} else if (nMod100 == 2 || nMod100 == 22 || nMod100 == 42 || nMod100 == 62 || nMod100 == 82) || (nMod1000 == 0 && nMod100000 >= 1000 && nMod100000 <= 20000 && (nMod100000 == 40000 || nMod100000 == 60000 || nMod100000 == 80000)) || (n != 0 && nMod1000000 == 100000) {
    98  		return locales.PluralRuleTwo
    99  	} else if nMod100 == 3 || nMod100 == 23 || nMod100 == 43 || nMod100 == 63 || nMod100 == 83 {
   100  		return locales.PluralRuleFew
   101  	} else if n != 1 && (nMod100 == 1 || nMod100 == 21 || nMod100 == 41 || nMod100 == 61 || nMod100 == 81) {
   102  		return locales.PluralRuleMany
   103  	}
   104  
   105  	return locales.PluralRuleOther
   106  }
   107  
   108  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'kw'
   109  func (kw *kw) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
   110  
   111  	n := math.Abs(num)
   112  	nMod100 := math.Mod(n, 100)
   113  
   114  	if (n >= 1 && n <= 4) || ((nMod100 >= 1 && nMod100 <= 4) || (nMod100 >= 21 && nMod100 <= 24) || (nMod100 >= 41 && nMod100 <= 44) || (nMod100 >= 61 && nMod100 <= 64) || (nMod100 >= 81 && nMod100 <= 84)) {
   115  		return locales.PluralRuleOne
   116  	} else if (n == 5) || (nMod100 == 5) {
   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 'kw'
   124  func (kw *kw) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   125  	return locales.PluralRuleUnknown
   126  }
   127  
   128  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   129  func (kw *kw) MonthAbbreviated(month time.Month) string {
   130  	return kw.monthsAbbreviated[month]
   131  }
   132  
   133  // MonthsAbbreviated returns the locales abbreviated months
   134  func (kw *kw) MonthsAbbreviated() []string {
   135  	return kw.monthsAbbreviated[1:]
   136  }
   137  
   138  // MonthNarrow returns the locales narrow month given the 'month' provided
   139  func (kw *kw) MonthNarrow(month time.Month) string {
   140  	return kw.monthsNarrow[month]
   141  }
   142  
   143  // MonthsNarrow returns the locales narrow months
   144  func (kw *kw) MonthsNarrow() []string {
   145  	return nil
   146  }
   147  
   148  // MonthWide returns the locales wide month given the 'month' provided
   149  func (kw *kw) MonthWide(month time.Month) string {
   150  	return kw.monthsWide[month]
   151  }
   152  
   153  // MonthsWide returns the locales wide months
   154  func (kw *kw) MonthsWide() []string {
   155  	return kw.monthsWide[1:]
   156  }
   157  
   158  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   159  func (kw *kw) WeekdayAbbreviated(weekday time.Weekday) string {
   160  	return kw.daysAbbreviated[weekday]
   161  }
   162  
   163  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   164  func (kw *kw) WeekdaysAbbreviated() []string {
   165  	return kw.daysAbbreviated
   166  }
   167  
   168  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   169  func (kw *kw) WeekdayNarrow(weekday time.Weekday) string {
   170  	return kw.daysNarrow[weekday]
   171  }
   172  
   173  // WeekdaysNarrow returns the locales narrow weekdays
   174  func (kw *kw) WeekdaysNarrow() []string {
   175  	return kw.daysNarrow
   176  }
   177  
   178  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   179  func (kw *kw) WeekdayShort(weekday time.Weekday) string {
   180  	return kw.daysShort[weekday]
   181  }
   182  
   183  // WeekdaysShort returns the locales short weekdays
   184  func (kw *kw) WeekdaysShort() []string {
   185  	return kw.daysShort
   186  }
   187  
   188  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   189  func (kw *kw) WeekdayWide(weekday time.Weekday) string {
   190  	return kw.daysWide[weekday]
   191  }
   192  
   193  // WeekdaysWide returns the locales wide weekdays
   194  func (kw *kw) WeekdaysWide() []string {
   195  	return kw.daysWide
   196  }
   197  
   198  // Decimal returns the decimal point of number
   199  func (kw *kw) Decimal() string {
   200  	return kw.decimal
   201  }
   202  
   203  // Group returns the group of number
   204  func (kw *kw) Group() string {
   205  	return kw.group
   206  }
   207  
   208  // Group returns the minus sign of number
   209  func (kw *kw) Minus() string {
   210  	return kw.minus
   211  }
   212  
   213  // FmtNumber returns 'num' with digits/precision of 'v' for 'kw' and handles both Whole and Real numbers based on 'v'
   214  func (kw *kw) FmtNumber(num float64, v uint64) string {
   215  
   216  	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   217  }
   218  
   219  // FmtPercent returns 'num' with digits/precision of 'v' for 'kw' and handles both Whole and Real numbers based on 'v'
   220  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   221  func (kw *kw) FmtPercent(num float64, v uint64) string {
   222  	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   223  }
   224  
   225  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'kw'
   226  func (kw *kw) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   227  
   228  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   229  	symbol := kw.currencies[currency]
   230  	l := len(s) + len(symbol) + 0
   231  	count := 0
   232  	inWhole := v == 0
   233  	b := make([]byte, 0, l)
   234  
   235  	for i := len(s) - 1; i >= 0; i-- {
   236  
   237  		if s[i] == '.' {
   238  			b = append(b, kw.decimal[0])
   239  			inWhole = true
   240  			continue
   241  		}
   242  
   243  		if inWhole {
   244  			if count == 3 {
   245  				b = append(b, kw.group[0])
   246  				count = 1
   247  			} else {
   248  				count++
   249  			}
   250  		}
   251  
   252  		b = append(b, s[i])
   253  	}
   254  
   255  	for j := len(symbol) - 1; j >= 0; j-- {
   256  		b = append(b, symbol[j])
   257  	}
   258  
   259  	if num < 0 {
   260  		b = append(b, kw.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  	if int(v) < 2 {
   269  
   270  		if v == 0 {
   271  			b = append(b, kw.decimal...)
   272  		}
   273  
   274  		for i := 0; i < 2-int(v); i++ {
   275  			b = append(b, '0')
   276  		}
   277  	}
   278  
   279  	return string(b)
   280  }
   281  
   282  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'kw'
   283  // in accounting notation.
   284  func (kw *kw) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   285  
   286  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   287  	symbol := kw.currencies[currency]
   288  	l := len(s) + len(symbol) + 0
   289  	count := 0
   290  	inWhole := v == 0
   291  	b := make([]byte, 0, l)
   292  
   293  	for i := len(s) - 1; i >= 0; i-- {
   294  
   295  		if s[i] == '.' {
   296  			b = append(b, kw.decimal[0])
   297  			inWhole = true
   298  			continue
   299  		}
   300  
   301  		if inWhole {
   302  			if count == 3 {
   303  				b = append(b, kw.group[0])
   304  				count = 1
   305  			} else {
   306  				count++
   307  			}
   308  		}
   309  
   310  		b = append(b, s[i])
   311  	}
   312  
   313  	if num < 0 {
   314  
   315  		for j := len(symbol) - 1; j >= 0; j-- {
   316  			b = append(b, symbol[j])
   317  		}
   318  
   319  		b = append(b, kw.minus[0])
   320  
   321  	} else {
   322  
   323  		for j := len(symbol) - 1; j >= 0; j-- {
   324  			b = append(b, symbol[j])
   325  		}
   326  
   327  	}
   328  
   329  	// reverse
   330  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   331  		b[i], b[j] = b[j], b[i]
   332  	}
   333  
   334  	if int(v) < 2 {
   335  
   336  		if v == 0 {
   337  			b = append(b, kw.decimal...)
   338  		}
   339  
   340  		for i := 0; i < 2-int(v); i++ {
   341  			b = append(b, '0')
   342  		}
   343  	}
   344  
   345  	return string(b)
   346  }
   347  
   348  // FmtDateShort returns the short date representation of 't' for 'kw'
   349  func (kw *kw) FmtDateShort(t time.Time) string {
   350  
   351  	b := make([]byte, 0, 32)
   352  
   353  	if t.Day() < 10 {
   354  		b = append(b, '0')
   355  	}
   356  
   357  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   358  	b = append(b, []byte{0x2f}...)
   359  
   360  	if t.Month() < 10 {
   361  		b = append(b, '0')
   362  	}
   363  
   364  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   365  
   366  	b = append(b, []byte{0x2f}...)
   367  
   368  	if t.Year() > 0 {
   369  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   370  	} else {
   371  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   372  	}
   373  
   374  	return string(b)
   375  }
   376  
   377  // FmtDateMedium returns the medium date representation of 't' for 'kw'
   378  func (kw *kw) FmtDateMedium(t time.Time) string {
   379  
   380  	b := make([]byte, 0, 32)
   381  
   382  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   383  	b = append(b, []byte{0x20}...)
   384  	b = append(b, kw.monthsAbbreviated[t.Month()]...)
   385  	b = append(b, []byte{0x20}...)
   386  
   387  	if t.Year() > 0 {
   388  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   389  	} else {
   390  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   391  	}
   392  
   393  	return string(b)
   394  }
   395  
   396  // FmtDateLong returns the long date representation of 't' for 'kw'
   397  func (kw *kw) FmtDateLong(t time.Time) string {
   398  
   399  	b := make([]byte, 0, 32)
   400  
   401  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   402  	b = append(b, []byte{0x20}...)
   403  	b = append(b, kw.monthsWide[t.Month()]...)
   404  	b = append(b, []byte{0x20}...)
   405  
   406  	if t.Year() > 0 {
   407  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   408  	} else {
   409  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   410  	}
   411  
   412  	return string(b)
   413  }
   414  
   415  // FmtDateFull returns the full date representation of 't' for 'kw'
   416  func (kw *kw) FmtDateFull(t time.Time) string {
   417  
   418  	b := make([]byte, 0, 32)
   419  
   420  	b = append(b, kw.daysWide[t.Weekday()]...)
   421  	b = append(b, []byte{0x20}...)
   422  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   423  	b = append(b, []byte{0x20}...)
   424  	b = append(b, kw.monthsWide[t.Month()]...)
   425  	b = append(b, []byte{0x20}...)
   426  
   427  	if t.Year() > 0 {
   428  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   429  	} else {
   430  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   431  	}
   432  
   433  	return string(b)
   434  }
   435  
   436  // FmtTimeShort returns the short time representation of 't' for 'kw'
   437  func (kw *kw) FmtTimeShort(t time.Time) string {
   438  
   439  	b := make([]byte, 0, 32)
   440  
   441  	if t.Hour() < 10 {
   442  		b = append(b, '0')
   443  	}
   444  
   445  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   446  	b = append(b, kw.timeSeparator...)
   447  
   448  	if t.Minute() < 10 {
   449  		b = append(b, '0')
   450  	}
   451  
   452  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   453  
   454  	return string(b)
   455  }
   456  
   457  // FmtTimeMedium returns the medium time representation of 't' for 'kw'
   458  func (kw *kw) FmtTimeMedium(t time.Time) string {
   459  
   460  	b := make([]byte, 0, 32)
   461  
   462  	if t.Hour() < 10 {
   463  		b = append(b, '0')
   464  	}
   465  
   466  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   467  	b = append(b, kw.timeSeparator...)
   468  
   469  	if t.Minute() < 10 {
   470  		b = append(b, '0')
   471  	}
   472  
   473  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   474  	b = append(b, kw.timeSeparator...)
   475  
   476  	if t.Second() < 10 {
   477  		b = append(b, '0')
   478  	}
   479  
   480  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   481  
   482  	return string(b)
   483  }
   484  
   485  // FmtTimeLong returns the long time representation of 't' for 'kw'
   486  func (kw *kw) FmtTimeLong(t time.Time) string {
   487  
   488  	b := make([]byte, 0, 32)
   489  
   490  	if t.Hour() < 10 {
   491  		b = append(b, '0')
   492  	}
   493  
   494  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   495  	b = append(b, kw.timeSeparator...)
   496  
   497  	if t.Minute() < 10 {
   498  		b = append(b, '0')
   499  	}
   500  
   501  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   502  	b = append(b, kw.timeSeparator...)
   503  
   504  	if t.Second() < 10 {
   505  		b = append(b, '0')
   506  	}
   507  
   508  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   509  	b = append(b, []byte{0x20}...)
   510  
   511  	tz, _ := t.Zone()
   512  	b = append(b, tz...)
   513  
   514  	return string(b)
   515  }
   516  
   517  // FmtTimeFull returns the full time representation of 't' for 'kw'
   518  func (kw *kw) FmtTimeFull(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, kw.timeSeparator...)
   528  
   529  	if t.Minute() < 10 {
   530  		b = append(b, '0')
   531  	}
   532  
   533  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   534  	b = append(b, kw.timeSeparator...)
   535  
   536  	if t.Second() < 10 {
   537  		b = append(b, '0')
   538  	}
   539  
   540  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   541  	b = append(b, []byte{0x20}...)
   542  
   543  	tz, _ := t.Zone()
   544  
   545  	if btz, ok := kw.timezones[tz]; ok {
   546  		b = append(b, btz...)
   547  	} else {
   548  		b = append(b, tz...)
   549  	}
   550  
   551  	return string(b)
   552  }
   553  

View as plain text