...

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

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

     1  package cu
     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 cu 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  	percentSuffix          string
    22  	perMille               string
    23  	timeSeparator          string
    24  	inifinity              string
    25  	currencies             []string // idx = enum of currency code
    26  	currencyPositiveSuffix 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 'cu' locale
    46  func New() locales.Translator {
    47  	return &cu{
    48  		locale:                 "cu",
    49  		pluralsCardinal:        nil,
    50  		pluralsOrdinal:         nil,
    51  		pluralsRange:           nil,
    52  		decimal:                ",",
    53  		group:                  " ",
    54  		minus:                  "-",
    55  		percent:                "%",
    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", "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", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "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", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JP¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD", "₸", "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", "₽", "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", "₴", "UAK", "UGS", "UGX", "$", "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"},
    59  		percentSuffix:          " ",
    60  		currencyPositiveSuffix: " ",
    61  		currencyNegativeSuffix: " ",
    62  		monthsAbbreviated:      []string{"", "і҆аⷩ҇", "феⷡ҇", "маⷬ҇", "а҆пⷬ҇", "маꙵ", "і҆ꙋⷩ҇", "і҆ꙋⷧ҇", "а҆́ѵⷢ҇", "сеⷫ҇", "ѻ҆кⷮ", "ноеⷨ", "деⷦ҇"},
    63  		monthsNarrow:           []string{"", "І҆", "Ф", "М", "А҆", "М", "І҆", "І҆", "А҆", "С", "Ѻ҆", "Н", "Д"},
    64  		monthsWide:             []string{"", "і҆аннꙋа́рїа", "феврꙋа́рїа", "ма́рта", "а҆прі́ллїа", "ма́їа", "і҆ꙋ́нїа", "і҆ꙋ́лїа", "а҆́ѵгꙋста", "септе́мврїа", "ѻ҆ктѡ́врїа", "ное́мврїа", "деке́мврїа"},
    65  		daysAbbreviated:        []string{"ндⷧ҇ѧ", "пнⷣе", "втоⷬ҇", "срⷣе", "чеⷦ҇", "пѧⷦ҇", "сꙋⷠ҇"},
    66  		daysNarrow:             []string{"Н", "П", "В", "С", "Ч", "П", "С"},
    67  		daysShort:              []string{"ндⷧ҇ѧ", "пнⷣе", "втоⷬ҇", "срⷣе", "чеⷦ҇", "пѧⷦ҇", "сꙋⷠ҇"},
    68  		daysWide:               []string{"недѣ́лѧ", "понедѣ́льникъ", "вто́рникъ", "среда̀", "четверто́къ", "пѧто́къ", "сꙋббѡ́та"},
    69  		periodsAbbreviated:     []string{"ДП", "ПП"},
    70  		periodsNarrow:          []string{"ДП", "ПП"},
    71  		periodsWide:            []string{"ДП", "ПП"},
    72  		erasAbbreviated:        []string{"пре́дъ р.\u00a0х.", "ѿ р. х."},
    73  		erasNarrow:             []string{"", ""},
    74  		erasWide:               []string{"пре́дъ р.\u00a0х.", "по р.\u00a0х."},
    75  		timezones:              map[string]string{"ACDT": "ACDT", "ACST": "ACST", "ACWDT": "ACWDT", "ACWST": "ACWST", "ADT": "а҆тланті́ческое лѣ́тнее вре́мѧ", "AEDT": "AEDT", "AEST": "AEST", "AKDT": "AKDT", "AKST": "AKST", "ARST": "ARST", "ART": "ART", "AST": "а҆тланті́ческое зи́мнее вре́мѧ", "AWDT": "AWDT", "AWST": "AWST", "BOT": "BOT", "BT": "BT", "CAT": "CAT", "CDT": "среднеамерїка́нское лѣ́тнее вре́мѧ", "CHADT": "CHADT", "CHAST": "CHAST", "CLST": "CLST", "CLT": "CLT", "COST": "COST", "COT": "COT", "CST": "среднеамерїка́нское зи́мнее вре́мѧ", "ChST": "ChST", "EAT": "EAT", "ECT": "ECT", "EDT": "восточноамерїка́нское лѣ́тнее вре́мѧ", "EST": "восточноамерїка́нское зи́мнее вре́мѧ", "GFT": "GFT", "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": "а҆мерїка́нское наго́рнее лѣ́тнее вре́мѧ", "MESZ": "среднеєѵрѡпе́йское лѣ́тнее вре́мѧ", "MEZ": "среднеєѵрѡпе́йское зи́мнее вре́мѧ", "MST": "а҆мерїка́нское наго́рнее зи́мнее вре́мѧ", "MYT": "MYT", "NZDT": "NZDT", "NZST": "NZST", "OESZ": "восточноєѵрѡпе́йское лѣ́тнее вре́мѧ", "OEZ": "восточноєѵрѡпе́йское зи́мнее вре́мѧ", "PDT": "тихоѻкеа́нское лѣ́тнее вре́мѧ", "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": "западноєѵрѡпе́йское лѣ́тнее вре́мѧ", "WEZ": "западноєѵрѡпе́йское зи́мнее вре́мѧ", "WIB": "WIB", "WIT": "WIT", "WITA": "WITA", "∅∅∅": "∅∅∅"},
    76  	}
    77  }
    78  
    79  // Locale returns the current translators string locale
    80  func (cu *cu) Locale() string {
    81  	return cu.locale
    82  }
    83  
    84  // PluralsCardinal returns the list of cardinal plural rules associated with 'cu'
    85  func (cu *cu) PluralsCardinal() []locales.PluralRule {
    86  	return cu.pluralsCardinal
    87  }
    88  
    89  // PluralsOrdinal returns the list of ordinal plural rules associated with 'cu'
    90  func (cu *cu) PluralsOrdinal() []locales.PluralRule {
    91  	return cu.pluralsOrdinal
    92  }
    93  
    94  // PluralsRange returns the list of range plural rules associated with 'cu'
    95  func (cu *cu) PluralsRange() []locales.PluralRule {
    96  	return cu.pluralsRange
    97  }
    98  
    99  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'cu'
   100  func (cu *cu) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
   101  	return locales.PluralRuleUnknown
   102  }
   103  
   104  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'cu'
   105  func (cu *cu) 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 'cu'
   110  func (cu *cu) 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 (cu *cu) MonthAbbreviated(month time.Month) string {
   116  	return cu.monthsAbbreviated[month]
   117  }
   118  
   119  // MonthsAbbreviated returns the locales abbreviated months
   120  func (cu *cu) MonthsAbbreviated() []string {
   121  	return cu.monthsAbbreviated[1:]
   122  }
   123  
   124  // MonthNarrow returns the locales narrow month given the 'month' provided
   125  func (cu *cu) MonthNarrow(month time.Month) string {
   126  	return cu.monthsNarrow[month]
   127  }
   128  
   129  // MonthsNarrow returns the locales narrow months
   130  func (cu *cu) MonthsNarrow() []string {
   131  	return cu.monthsNarrow[1:]
   132  }
   133  
   134  // MonthWide returns the locales wide month given the 'month' provided
   135  func (cu *cu) MonthWide(month time.Month) string {
   136  	return cu.monthsWide[month]
   137  }
   138  
   139  // MonthsWide returns the locales wide months
   140  func (cu *cu) MonthsWide() []string {
   141  	return cu.monthsWide[1:]
   142  }
   143  
   144  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   145  func (cu *cu) WeekdayAbbreviated(weekday time.Weekday) string {
   146  	return cu.daysAbbreviated[weekday]
   147  }
   148  
   149  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   150  func (cu *cu) WeekdaysAbbreviated() []string {
   151  	return cu.daysAbbreviated
   152  }
   153  
   154  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   155  func (cu *cu) WeekdayNarrow(weekday time.Weekday) string {
   156  	return cu.daysNarrow[weekday]
   157  }
   158  
   159  // WeekdaysNarrow returns the locales narrow weekdays
   160  func (cu *cu) WeekdaysNarrow() []string {
   161  	return cu.daysNarrow
   162  }
   163  
   164  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   165  func (cu *cu) WeekdayShort(weekday time.Weekday) string {
   166  	return cu.daysShort[weekday]
   167  }
   168  
   169  // WeekdaysShort returns the locales short weekdays
   170  func (cu *cu) WeekdaysShort() []string {
   171  	return cu.daysShort
   172  }
   173  
   174  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   175  func (cu *cu) WeekdayWide(weekday time.Weekday) string {
   176  	return cu.daysWide[weekday]
   177  }
   178  
   179  // WeekdaysWide returns the locales wide weekdays
   180  func (cu *cu) WeekdaysWide() []string {
   181  	return cu.daysWide
   182  }
   183  
   184  // Decimal returns the decimal point of number
   185  func (cu *cu) Decimal() string {
   186  	return cu.decimal
   187  }
   188  
   189  // Group returns the group of number
   190  func (cu *cu) Group() string {
   191  	return cu.group
   192  }
   193  
   194  // Group returns the minus sign of number
   195  func (cu *cu) Minus() string {
   196  	return cu.minus
   197  }
   198  
   199  // FmtNumber returns 'num' with digits/precision of 'v' for 'cu' and handles both Whole and Real numbers based on 'v'
   200  func (cu *cu) 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, cu.decimal[0])
   212  			inWhole = true
   213  			continue
   214  		}
   215  
   216  		if inWhole {
   217  			if count == 3 {
   218  				for j := len(cu.group) - 1; j >= 0; j-- {
   219  					b = append(b, cu.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, cu.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 'cu' 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 (cu *cu) FmtPercent(num float64, v uint64) string {
   245  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   246  	l := len(s) + 5
   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, cu.decimal[0])
   253  			continue
   254  		}
   255  
   256  		b = append(b, s[i])
   257  	}
   258  
   259  	if num < 0 {
   260  		b = append(b, cu.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, cu.percentSuffix...)
   269  
   270  	b = append(b, cu.percent...)
   271  
   272  	return string(b)
   273  }
   274  
   275  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'cu'
   276  func (cu *cu) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   277  
   278  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   279  	symbol := cu.currencies[currency]
   280  	l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
   281  	count := 0
   282  	inWhole := v == 0
   283  	b := make([]byte, 0, l)
   284  
   285  	for i := len(s) - 1; i >= 0; i-- {
   286  
   287  		if s[i] == '.' {
   288  			b = append(b, cu.decimal[0])
   289  			inWhole = true
   290  			continue
   291  		}
   292  
   293  		if inWhole {
   294  			if count == 3 {
   295  				for j := len(cu.group) - 1; j >= 0; j-- {
   296  					b = append(b, cu.group[j])
   297  				}
   298  				count = 1
   299  			} else {
   300  				count++
   301  			}
   302  		}
   303  
   304  		b = append(b, s[i])
   305  	}
   306  
   307  	if num < 0 {
   308  		b = append(b, cu.minus[0])
   309  	}
   310  
   311  	// reverse
   312  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   313  		b[i], b[j] = b[j], b[i]
   314  	}
   315  
   316  	if int(v) < 2 {
   317  
   318  		if v == 0 {
   319  			b = append(b, cu.decimal...)
   320  		}
   321  
   322  		for i := 0; i < 2-int(v); i++ {
   323  			b = append(b, '0')
   324  		}
   325  	}
   326  
   327  	b = append(b, cu.currencyPositiveSuffix...)
   328  
   329  	b = append(b, symbol...)
   330  
   331  	return string(b)
   332  }
   333  
   334  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'cu'
   335  // in accounting notation.
   336  func (cu *cu) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   337  
   338  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   339  	symbol := cu.currencies[currency]
   340  	l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
   341  	count := 0
   342  	inWhole := v == 0
   343  	b := make([]byte, 0, l)
   344  
   345  	for i := len(s) - 1; i >= 0; i-- {
   346  
   347  		if s[i] == '.' {
   348  			b = append(b, cu.decimal[0])
   349  			inWhole = true
   350  			continue
   351  		}
   352  
   353  		if inWhole {
   354  			if count == 3 {
   355  				for j := len(cu.group) - 1; j >= 0; j-- {
   356  					b = append(b, cu.group[j])
   357  				}
   358  				count = 1
   359  			} else {
   360  				count++
   361  			}
   362  		}
   363  
   364  		b = append(b, s[i])
   365  	}
   366  
   367  	if num < 0 {
   368  
   369  		b = append(b, cu.minus[0])
   370  
   371  	}
   372  
   373  	// reverse
   374  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   375  		b[i], b[j] = b[j], b[i]
   376  	}
   377  
   378  	if int(v) < 2 {
   379  
   380  		if v == 0 {
   381  			b = append(b, cu.decimal...)
   382  		}
   383  
   384  		for i := 0; i < 2-int(v); i++ {
   385  			b = append(b, '0')
   386  		}
   387  	}
   388  
   389  	if num < 0 {
   390  		b = append(b, cu.currencyNegativeSuffix...)
   391  		b = append(b, symbol...)
   392  	} else {
   393  
   394  		b = append(b, cu.currencyPositiveSuffix...)
   395  		b = append(b, symbol...)
   396  	}
   397  
   398  	return string(b)
   399  }
   400  
   401  // FmtDateShort returns the short date representation of 't' for 'cu'
   402  func (cu *cu) FmtDateShort(t time.Time) string {
   403  
   404  	b := make([]byte, 0, 32)
   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  	b = append(b, []byte{0x2e}...)
   413  
   414  	if t.Month() < 10 {
   415  		b = append(b, '0')
   416  	}
   417  
   418  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   419  
   420  	b = append(b, []byte{0x2e}...)
   421  
   422  	if t.Day() < 10 {
   423  		b = append(b, '0')
   424  	}
   425  
   426  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   427  
   428  	return string(b)
   429  }
   430  
   431  // FmtDateMedium returns the medium date representation of 't' for 'cu'
   432  func (cu *cu) FmtDateMedium(t time.Time) string {
   433  
   434  	b := make([]byte, 0, 32)
   435  
   436  	if t.Year() > 0 {
   437  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   438  	} else {
   439  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   440  	}
   441  
   442  	b = append(b, []byte{0x20}...)
   443  	b = append(b, cu.monthsAbbreviated[t.Month()]...)
   444  	b = append(b, []byte{0x20}...)
   445  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   446  
   447  	return string(b)
   448  }
   449  
   450  // FmtDateLong returns the long date representation of 't' for 'cu'
   451  func (cu *cu) FmtDateLong(t time.Time) string {
   452  
   453  	b := make([]byte, 0, 32)
   454  
   455  	if t.Year() > 0 {
   456  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   457  	} else {
   458  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   459  	}
   460  
   461  	b = append(b, []byte{0x20}...)
   462  	b = append(b, cu.monthsWide[t.Month()]...)
   463  	b = append(b, []byte{0x20}...)
   464  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   465  
   466  	return string(b)
   467  }
   468  
   469  // FmtDateFull returns the full date representation of 't' for 'cu'
   470  func (cu *cu) FmtDateFull(t time.Time) string {
   471  
   472  	b := make([]byte, 0, 32)
   473  
   474  	b = append(b, cu.daysWide[t.Weekday()]...)
   475  	b = append(b, []byte{0x2c, 0x20}...)
   476  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   477  	b = append(b, []byte{0x20}...)
   478  	b = append(b, cu.monthsWide[t.Month()]...)
   479  	b = append(b, []byte{0x20, 0xd0, 0xbb}...)
   480  	b = append(b, []byte{0x2e, 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  	b = append(b, []byte{0x2e}...)
   489  
   490  	return string(b)
   491  }
   492  
   493  // FmtTimeShort returns the short time representation of 't' for 'cu'
   494  func (cu *cu) FmtTimeShort(t time.Time) string {
   495  
   496  	b := make([]byte, 0, 32)
   497  
   498  	if t.Hour() < 10 {
   499  		b = append(b, '0')
   500  	}
   501  
   502  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   503  	b = append(b, cu.timeSeparator...)
   504  
   505  	if t.Minute() < 10 {
   506  		b = append(b, '0')
   507  	}
   508  
   509  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   510  
   511  	return string(b)
   512  }
   513  
   514  // FmtTimeMedium returns the medium time representation of 't' for 'cu'
   515  func (cu *cu) FmtTimeMedium(t time.Time) string {
   516  
   517  	b := make([]byte, 0, 32)
   518  
   519  	if t.Hour() < 10 {
   520  		b = append(b, '0')
   521  	}
   522  
   523  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   524  	b = append(b, cu.timeSeparator...)
   525  
   526  	if t.Minute() < 10 {
   527  		b = append(b, '0')
   528  	}
   529  
   530  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   531  	b = append(b, cu.timeSeparator...)
   532  
   533  	if t.Second() < 10 {
   534  		b = append(b, '0')
   535  	}
   536  
   537  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   538  
   539  	return string(b)
   540  }
   541  
   542  // FmtTimeLong returns the long time representation of 't' for 'cu'
   543  func (cu *cu) FmtTimeLong(t time.Time) string {
   544  
   545  	b := make([]byte, 0, 32)
   546  
   547  	if t.Hour() < 10 {
   548  		b = append(b, '0')
   549  	}
   550  
   551  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   552  	b = append(b, cu.timeSeparator...)
   553  
   554  	if t.Minute() < 10 {
   555  		b = append(b, '0')
   556  	}
   557  
   558  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   559  	b = append(b, cu.timeSeparator...)
   560  
   561  	if t.Second() < 10 {
   562  		b = append(b, '0')
   563  	}
   564  
   565  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   566  	b = append(b, []byte{0x20}...)
   567  
   568  	tz, _ := t.Zone()
   569  	b = append(b, tz...)
   570  
   571  	return string(b)
   572  }
   573  
   574  // FmtTimeFull returns the full time representation of 't' for 'cu'
   575  func (cu *cu) FmtTimeFull(t time.Time) string {
   576  
   577  	b := make([]byte, 0, 32)
   578  
   579  	if t.Hour() < 10 {
   580  		b = append(b, '0')
   581  	}
   582  
   583  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   584  	b = append(b, cu.timeSeparator...)
   585  
   586  	if t.Minute() < 10 {
   587  		b = append(b, '0')
   588  	}
   589  
   590  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   591  	b = append(b, cu.timeSeparator...)
   592  
   593  	if t.Second() < 10 {
   594  		b = append(b, '0')
   595  	}
   596  
   597  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   598  	b = append(b, []byte{0x20}...)
   599  
   600  	tz, _ := t.Zone()
   601  
   602  	if btz, ok := cu.timezones[tz]; ok {
   603  		b = append(b, btz...)
   604  	} else {
   605  		b = append(b, tz...)
   606  	}
   607  
   608  	return string(b)
   609  }
   610  

View as plain text