...

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

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

     1  package dyo
     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 dyo 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  	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 'dyo' locale
    45  func New() locales.Translator {
    46  	return &dyo{
    47  		locale:                 "dyo",
    48  		pluralsCardinal:        nil,
    49  		pluralsOrdinal:         nil,
    50  		pluralsRange:           nil,
    51  		decimal:                ",",
    52  		group:                  " ",
    53  		timeSeparator:          ":",
    54  		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"},
    55  		currencyPositiveSuffix: " ",
    56  		currencyNegativeSuffix: " ",
    57  		monthsAbbreviated:      []string{"", "Sa", "Fe", "Ma", "Ab", "Me", "Su", "Sú", "Ut", "Se", "Ok", "No", "De"},
    58  		monthsNarrow:           []string{"", "S", "F", "M", "A", "M", "S", "S", "U", "S", "O", "N", "D"},
    59  		monthsWide:             []string{"", "Sanvie", "Fébirie", "Mars", "Aburil", "Mee", "Sueŋ", "Súuyee", "Ut", "Settembar", "Oktobar", "Novembar", "Disambar"},
    60  		daysAbbreviated:        []string{"Dim", "Ten", "Tal", "Ala", "Ara", "Arj", "Sib"},
    61  		daysNarrow:             []string{"D", "T", "T", "A", "A", "A", "S"},
    62  		daysWide:               []string{"Dimas", "Teneŋ", "Talata", "Alarbay", "Aramisay", "Arjuma", "Sibiti"},
    63  		erasAbbreviated:        []string{"ArY", "AtY"},
    64  		erasNarrow:             []string{"", ""},
    65  		erasWide:               []string{"Ariŋuu Yeesu", "Atooŋe Yeesu"},
    66  		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", "∅∅∅": "∅∅∅"},
    67  	}
    68  }
    69  
    70  // Locale returns the current translators string locale
    71  func (dyo *dyo) Locale() string {
    72  	return dyo.locale
    73  }
    74  
    75  // PluralsCardinal returns the list of cardinal plural rules associated with 'dyo'
    76  func (dyo *dyo) PluralsCardinal() []locales.PluralRule {
    77  	return dyo.pluralsCardinal
    78  }
    79  
    80  // PluralsOrdinal returns the list of ordinal plural rules associated with 'dyo'
    81  func (dyo *dyo) PluralsOrdinal() []locales.PluralRule {
    82  	return dyo.pluralsOrdinal
    83  }
    84  
    85  // PluralsRange returns the list of range plural rules associated with 'dyo'
    86  func (dyo *dyo) PluralsRange() []locales.PluralRule {
    87  	return dyo.pluralsRange
    88  }
    89  
    90  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'dyo'
    91  func (dyo *dyo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
    92  	return locales.PluralRuleUnknown
    93  }
    94  
    95  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'dyo'
    96  func (dyo *dyo) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
    97  	return locales.PluralRuleUnknown
    98  }
    99  
   100  // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'dyo'
   101  func (dyo *dyo) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   102  	return locales.PluralRuleUnknown
   103  }
   104  
   105  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   106  func (dyo *dyo) MonthAbbreviated(month time.Month) string {
   107  	return dyo.monthsAbbreviated[month]
   108  }
   109  
   110  // MonthsAbbreviated returns the locales abbreviated months
   111  func (dyo *dyo) MonthsAbbreviated() []string {
   112  	return dyo.monthsAbbreviated[1:]
   113  }
   114  
   115  // MonthNarrow returns the locales narrow month given the 'month' provided
   116  func (dyo *dyo) MonthNarrow(month time.Month) string {
   117  	return dyo.monthsNarrow[month]
   118  }
   119  
   120  // MonthsNarrow returns the locales narrow months
   121  func (dyo *dyo) MonthsNarrow() []string {
   122  	return dyo.monthsNarrow[1:]
   123  }
   124  
   125  // MonthWide returns the locales wide month given the 'month' provided
   126  func (dyo *dyo) MonthWide(month time.Month) string {
   127  	return dyo.monthsWide[month]
   128  }
   129  
   130  // MonthsWide returns the locales wide months
   131  func (dyo *dyo) MonthsWide() []string {
   132  	return dyo.monthsWide[1:]
   133  }
   134  
   135  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   136  func (dyo *dyo) WeekdayAbbreviated(weekday time.Weekday) string {
   137  	return dyo.daysAbbreviated[weekday]
   138  }
   139  
   140  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   141  func (dyo *dyo) WeekdaysAbbreviated() []string {
   142  	return dyo.daysAbbreviated
   143  }
   144  
   145  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   146  func (dyo *dyo) WeekdayNarrow(weekday time.Weekday) string {
   147  	return dyo.daysNarrow[weekday]
   148  }
   149  
   150  // WeekdaysNarrow returns the locales narrow weekdays
   151  func (dyo *dyo) WeekdaysNarrow() []string {
   152  	return dyo.daysNarrow
   153  }
   154  
   155  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   156  func (dyo *dyo) WeekdayShort(weekday time.Weekday) string {
   157  	return dyo.daysShort[weekday]
   158  }
   159  
   160  // WeekdaysShort returns the locales short weekdays
   161  func (dyo *dyo) WeekdaysShort() []string {
   162  	return dyo.daysShort
   163  }
   164  
   165  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   166  func (dyo *dyo) WeekdayWide(weekday time.Weekday) string {
   167  	return dyo.daysWide[weekday]
   168  }
   169  
   170  // WeekdaysWide returns the locales wide weekdays
   171  func (dyo *dyo) WeekdaysWide() []string {
   172  	return dyo.daysWide
   173  }
   174  
   175  // Decimal returns the decimal point of number
   176  func (dyo *dyo) Decimal() string {
   177  	return dyo.decimal
   178  }
   179  
   180  // Group returns the group of number
   181  func (dyo *dyo) Group() string {
   182  	return dyo.group
   183  }
   184  
   185  // Group returns the minus sign of number
   186  func (dyo *dyo) Minus() string {
   187  	return dyo.minus
   188  }
   189  
   190  // FmtNumber returns 'num' with digits/precision of 'v' for 'dyo' and handles both Whole and Real numbers based on 'v'
   191  func (dyo *dyo) FmtNumber(num float64, v uint64) string {
   192  
   193  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   194  	l := len(s) + 1 + 2*len(s[:len(s)-int(v)-1])/3
   195  	count := 0
   196  	inWhole := v == 0
   197  	b := make([]byte, 0, l)
   198  
   199  	for i := len(s) - 1; i >= 0; i-- {
   200  
   201  		if s[i] == '.' {
   202  			b = append(b, dyo.decimal[0])
   203  			inWhole = true
   204  			continue
   205  		}
   206  
   207  		if inWhole {
   208  			if count == 3 {
   209  				for j := len(dyo.group) - 1; j >= 0; j-- {
   210  					b = append(b, dyo.group[j])
   211  				}
   212  				count = 1
   213  			} else {
   214  				count++
   215  			}
   216  		}
   217  
   218  		b = append(b, s[i])
   219  	}
   220  
   221  	if num < 0 {
   222  		b = append(b, dyo.minus[0])
   223  	}
   224  
   225  	// reverse
   226  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   227  		b[i], b[j] = b[j], b[i]
   228  	}
   229  
   230  	return string(b)
   231  }
   232  
   233  // FmtPercent returns 'num' with digits/precision of 'v' for 'dyo' and handles both Whole and Real numbers based on 'v'
   234  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   235  func (dyo *dyo) FmtPercent(num float64, v uint64) string {
   236  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   237  	l := len(s) + 1
   238  	b := make([]byte, 0, l)
   239  
   240  	for i := len(s) - 1; i >= 0; i-- {
   241  
   242  		if s[i] == '.' {
   243  			b = append(b, dyo.decimal[0])
   244  			continue
   245  		}
   246  
   247  		b = append(b, s[i])
   248  	}
   249  
   250  	if num < 0 {
   251  		b = append(b, dyo.minus[0])
   252  	}
   253  
   254  	// reverse
   255  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   256  		b[i], b[j] = b[j], b[i]
   257  	}
   258  
   259  	b = append(b, dyo.percent...)
   260  
   261  	return string(b)
   262  }
   263  
   264  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'dyo'
   265  func (dyo *dyo) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   266  
   267  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   268  	symbol := dyo.currencies[currency]
   269  	l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
   270  	count := 0
   271  	inWhole := v == 0
   272  	b := make([]byte, 0, l)
   273  
   274  	for i := len(s) - 1; i >= 0; i-- {
   275  
   276  		if s[i] == '.' {
   277  			b = append(b, dyo.decimal[0])
   278  			inWhole = true
   279  			continue
   280  		}
   281  
   282  		if inWhole {
   283  			if count == 3 {
   284  				for j := len(dyo.group) - 1; j >= 0; j-- {
   285  					b = append(b, dyo.group[j])
   286  				}
   287  				count = 1
   288  			} else {
   289  				count++
   290  			}
   291  		}
   292  
   293  		b = append(b, s[i])
   294  	}
   295  
   296  	if num < 0 {
   297  		b = append(b, dyo.minus[0])
   298  	}
   299  
   300  	// reverse
   301  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   302  		b[i], b[j] = b[j], b[i]
   303  	}
   304  
   305  	if int(v) < 2 {
   306  
   307  		if v == 0 {
   308  			b = append(b, dyo.decimal...)
   309  		}
   310  
   311  		for i := 0; i < 2-int(v); i++ {
   312  			b = append(b, '0')
   313  		}
   314  	}
   315  
   316  	b = append(b, dyo.currencyPositiveSuffix...)
   317  
   318  	b = append(b, symbol...)
   319  
   320  	return string(b)
   321  }
   322  
   323  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'dyo'
   324  // in accounting notation.
   325  func (dyo *dyo) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   326  
   327  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   328  	symbol := dyo.currencies[currency]
   329  	l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
   330  	count := 0
   331  	inWhole := v == 0
   332  	b := make([]byte, 0, l)
   333  
   334  	for i := len(s) - 1; i >= 0; i-- {
   335  
   336  		if s[i] == '.' {
   337  			b = append(b, dyo.decimal[0])
   338  			inWhole = true
   339  			continue
   340  		}
   341  
   342  		if inWhole {
   343  			if count == 3 {
   344  				for j := len(dyo.group) - 1; j >= 0; j-- {
   345  					b = append(b, dyo.group[j])
   346  				}
   347  				count = 1
   348  			} else {
   349  				count++
   350  			}
   351  		}
   352  
   353  		b = append(b, s[i])
   354  	}
   355  
   356  	if num < 0 {
   357  
   358  		b = append(b, dyo.minus[0])
   359  
   360  	}
   361  
   362  	// reverse
   363  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   364  		b[i], b[j] = b[j], b[i]
   365  	}
   366  
   367  	if int(v) < 2 {
   368  
   369  		if v == 0 {
   370  			b = append(b, dyo.decimal...)
   371  		}
   372  
   373  		for i := 0; i < 2-int(v); i++ {
   374  			b = append(b, '0')
   375  		}
   376  	}
   377  
   378  	if num < 0 {
   379  		b = append(b, dyo.currencyNegativeSuffix...)
   380  		b = append(b, symbol...)
   381  	} else {
   382  
   383  		b = append(b, dyo.currencyPositiveSuffix...)
   384  		b = append(b, symbol...)
   385  	}
   386  
   387  	return string(b)
   388  }
   389  
   390  // FmtDateShort returns the short date representation of 't' for 'dyo'
   391  func (dyo *dyo) FmtDateShort(t time.Time) string {
   392  
   393  	b := make([]byte, 0, 32)
   394  
   395  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   396  	b = append(b, []byte{0x2f}...)
   397  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   398  	b = append(b, []byte{0x2f}...)
   399  
   400  	if t.Year() > 0 {
   401  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   402  	} else {
   403  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   404  	}
   405  
   406  	return string(b)
   407  }
   408  
   409  // FmtDateMedium returns the medium date representation of 't' for 'dyo'
   410  func (dyo *dyo) FmtDateMedium(t time.Time) string {
   411  
   412  	b := make([]byte, 0, 32)
   413  
   414  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   415  	b = append(b, []byte{0x20}...)
   416  	b = append(b, dyo.monthsAbbreviated[t.Month()]...)
   417  	b = append(b, []byte{0x20}...)
   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  // FmtDateLong returns the long date representation of 't' for 'dyo'
   429  func (dyo *dyo) FmtDateLong(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, dyo.monthsWide[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  // FmtDateFull returns the full date representation of 't' for 'dyo'
   448  func (dyo *dyo) FmtDateFull(t time.Time) string {
   449  
   450  	b := make([]byte, 0, 32)
   451  
   452  	b = append(b, dyo.daysWide[t.Weekday()]...)
   453  	b = append(b, []byte{0x20}...)
   454  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   455  	b = append(b, []byte{0x20}...)
   456  	b = append(b, dyo.monthsWide[t.Month()]...)
   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  // FmtTimeShort returns the short time representation of 't' for 'dyo'
   469  func (dyo *dyo) FmtTimeShort(t time.Time) string {
   470  
   471  	b := make([]byte, 0, 32)
   472  
   473  	if t.Hour() < 10 {
   474  		b = append(b, '0')
   475  	}
   476  
   477  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   478  	b = append(b, dyo.timeSeparator...)
   479  
   480  	if t.Minute() < 10 {
   481  		b = append(b, '0')
   482  	}
   483  
   484  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   485  
   486  	return string(b)
   487  }
   488  
   489  // FmtTimeMedium returns the medium time representation of 't' for 'dyo'
   490  func (dyo *dyo) FmtTimeMedium(t time.Time) string {
   491  
   492  	b := make([]byte, 0, 32)
   493  
   494  	if t.Hour() < 10 {
   495  		b = append(b, '0')
   496  	}
   497  
   498  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   499  	b = append(b, dyo.timeSeparator...)
   500  
   501  	if t.Minute() < 10 {
   502  		b = append(b, '0')
   503  	}
   504  
   505  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   506  	b = append(b, dyo.timeSeparator...)
   507  
   508  	if t.Second() < 10 {
   509  		b = append(b, '0')
   510  	}
   511  
   512  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   513  
   514  	return string(b)
   515  }
   516  
   517  // FmtTimeLong returns the long time representation of 't' for 'dyo'
   518  func (dyo *dyo) FmtTimeLong(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, dyo.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, dyo.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  	b = append(b, tz...)
   545  
   546  	return string(b)
   547  }
   548  
   549  // FmtTimeFull returns the full time representation of 't' for 'dyo'
   550  func (dyo *dyo) FmtTimeFull(t time.Time) string {
   551  
   552  	b := make([]byte, 0, 32)
   553  
   554  	if t.Hour() < 10 {
   555  		b = append(b, '0')
   556  	}
   557  
   558  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   559  	b = append(b, dyo.timeSeparator...)
   560  
   561  	if t.Minute() < 10 {
   562  		b = append(b, '0')
   563  	}
   564  
   565  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   566  	b = append(b, dyo.timeSeparator...)
   567  
   568  	if t.Second() < 10 {
   569  		b = append(b, '0')
   570  	}
   571  
   572  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   573  	b = append(b, []byte{0x20}...)
   574  
   575  	tz, _ := t.Zone()
   576  
   577  	if btz, ok := dyo.timezones[tz]; ok {
   578  		b = append(b, btz...)
   579  	} else {
   580  		b = append(b, tz...)
   581  	}
   582  
   583  	return string(b)
   584  }
   585  

View as plain text