...

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

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

     1  package fy
     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 fy 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  	currencyPositivePrefix 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 'fy' locale
    46  func New() locales.Translator {
    47  	return &fy{
    48  		locale:                 "fy",
    49  		pluralsCardinal:        []locales.PluralRule{2, 6},
    50  		pluralsOrdinal:         []locales.PluralRule{6},
    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", "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", "C$", "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", "FJ$", "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", "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", "SI$", "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", "TRY", "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", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
    60  		currencyPositivePrefix: " ",
    61  		currencyNegativePrefix: "( ",
    62  		currencyNegativeSuffix: ")",
    63  		monthsAbbreviated:      []string{"", "Jan", "Feb", "Mrt", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Des"},
    64  		monthsNarrow:           []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
    65  		monthsWide:             []string{"", "Jannewaris", "Febrewaris", "Maart", "April", "Maaie", "Juny", "July", "Augustus", "Septimber", "Oktober", "Novimber", "Desimber"},
    66  		daysAbbreviated:        []string{"si", "mo", "ti", "wo", "to", "fr", "so"},
    67  		daysNarrow:             []string{"S", "M", "T", "W", "T", "F", "S"},
    68  		daysShort:              []string{"si", "mo", "ti", "wo", "to", "fr", "so"},
    69  		daysWide:               []string{"snein", "moandei", "tiisdei", "woansdei", "tongersdei", "freed", "sneon"},
    70  		periodsAbbreviated:     []string{"AM", "PM"},
    71  		periodsNarrow:          []string{"AM", "PM"},
    72  		periodsWide:            []string{"AM", "PM"},
    73  		erasAbbreviated:        []string{"f.Kr.", "n.Kr."},
    74  		erasNarrow:             []string{"f.K.", "n.K."},
    75  		erasWide:               []string{"Foar Kristus", "nei Kristus"},
    76  		timezones:              map[string]string{"ACDT": "Midden-Australyske simmertiid", "ACST": "Midden-Australyske standerttiid", "ACWDT": "Midden-Australyske westelijke simmertiid", "ACWST": "Midden-Australyske westelijke standerttiid", "ADT": "Atlantic-simmertiid", "AEDT": "East-Australyske simmertiid", "AEST": "East-Australyske standerttiid", "AKDT": "Alaska-simmertiid", "AKST": "Alaska-standerttiid", "ARST": "Argentynske simmertiid", "ART": "Argentynske standerttiid", "AST": "Atlantic-standerttiid", "AWDT": "West-Australyske simmertiid", "AWST": "West-Australyske standerttiid", "BOT": "Boliviaanske tiid", "BT": "Bhutaanske tiid", "CAT": "Sintraal-Afrikaanske tiid", "CDT": "Central-simmertiid", "CHADT": "Chatham simmertiid", "CHAST": "Chatham standerttiid", "CLST": "Sileenske simmertiid", "CLT": "Sileenske standerttiid", "COST": "Kolombiaanske simmertiid", "COT": "Kolombiaanske standerttiid", "CST": "Central-standerttiid", "ChST": "Chamorro-tiid", "EAT": "East-Afrikaanske tiid", "ECT": "Ecuadoraanske tiid", "EDT": "Eastern-simmertiid", "EST": "Eastern-standerttiid", "GFT": "Frâns-Guyaanske tiid", "GMT": "Greenwich Mean Time", "GST": "Golf standerttiid", "GYT": "Guyaanske tiid", "HADT": "Hawaii-Aleoetyske simmertiid", "HAST": "Hawaii-Aleoetyske standerttiid", "HAT": "Newfoundlânske-simmertiid", "HECU": "Kubaanske simmertiid", "HEEG": "East-Groenlânske simmertiid", "HENOMX": "HENOMX", "HEOG": "West-Groenlânske simmertiid", "HEPM": "Saint Pierre en Miquelon-simmertiid", "HEPMX": "HEPMX", "HKST": "Hongkongse simmertiid", "HKT": "Hongkongse standerttiid", "HNCU": "Kubaanske standerttiid", "HNEG": "East-Groenlânske standerttiid", "HNNOMX": "HNNOMX", "HNOG": "West-Groenlânske standerttiid", "HNPM": "Saint Pierre en Miquelon-standerttiid", "HNPMX": "HNPMX", "HNT": "Newfoundlânske-standerttiid", "IST": "Yndiaaske tiid", "JDT": "Japanske simmertiid", "JST": "Japanske standerttiid", "LHDT": "Lord Howe-eilânske simmertiid", "LHST": "Lord Howe-eilânske standerttiid", "MDT": "Mountain-simmertiid", "MESZ": "Midden-Europeeske simmertiid", "MEZ": "Midden-Europeeske standerttiid", "MST": "Mountain-standerttiid", "MYT": "Maleisyske tiid", "NZDT": "Nij-Seelânske simmertiid", "NZST": "Nij-Seelânske standerttiid", "OESZ": "East-Europeeske simmertiid", "OEZ": "East-Europeeske standerttiid", "PDT": "Pasifik-simmertiid", "PST": "Pasifik-standerttiid", "SAST": "Sûd-Afrikaanske tiid", "SGT": "Singaporese standerttiid", "SRT": "Surinaamske tiid", "TMST": "Turkmeense simmertiid", "TMT": "Turkmeense standerttiid", "UYST": "Uruguayaanske simmertiid", "UYT": "Uruguayaanske standerttiid", "VET": "Fenezolaanske tiid", "WARST": "West-Argentynske simmertiid", "WART": "West-Argentynske standerttiid", "WAST": "West-Afrikaanske simmertiid", "WAT": "West-Afrikaanske standerttiid", "WESZ": "West-Europeeske simmertiid", "WEZ": "West-Europeeske standerttiid", "WIB": "West-Yndonezyske tiid", "WIT": "East-Yndonezyske tiid", "WITA": "Sintraal-Yndonezyske tiid", "∅∅∅": "Brazyljaanske simmertiid"},
    77  	}
    78  }
    79  
    80  // Locale returns the current translators string locale
    81  func (fy *fy) Locale() string {
    82  	return fy.locale
    83  }
    84  
    85  // PluralsCardinal returns the list of cardinal plural rules associated with 'fy'
    86  func (fy *fy) PluralsCardinal() []locales.PluralRule {
    87  	return fy.pluralsCardinal
    88  }
    89  
    90  // PluralsOrdinal returns the list of ordinal plural rules associated with 'fy'
    91  func (fy *fy) PluralsOrdinal() []locales.PluralRule {
    92  	return fy.pluralsOrdinal
    93  }
    94  
    95  // PluralsRange returns the list of range plural rules associated with 'fy'
    96  func (fy *fy) PluralsRange() []locales.PluralRule {
    97  	return fy.pluralsRange
    98  }
    99  
   100  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'fy'
   101  func (fy *fy) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
   102  
   103  	n := math.Abs(num)
   104  	i := int64(n)
   105  
   106  	if i == 1 && v == 0 {
   107  		return locales.PluralRuleOne
   108  	}
   109  
   110  	return locales.PluralRuleOther
   111  }
   112  
   113  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'fy'
   114  func (fy *fy) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
   115  	return locales.PluralRuleOther
   116  }
   117  
   118  // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'fy'
   119  func (fy *fy) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   120  	return locales.PluralRuleUnknown
   121  }
   122  
   123  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   124  func (fy *fy) MonthAbbreviated(month time.Month) string {
   125  	return fy.monthsAbbreviated[month]
   126  }
   127  
   128  // MonthsAbbreviated returns the locales abbreviated months
   129  func (fy *fy) MonthsAbbreviated() []string {
   130  	return fy.monthsAbbreviated[1:]
   131  }
   132  
   133  // MonthNarrow returns the locales narrow month given the 'month' provided
   134  func (fy *fy) MonthNarrow(month time.Month) string {
   135  	return fy.monthsNarrow[month]
   136  }
   137  
   138  // MonthsNarrow returns the locales narrow months
   139  func (fy *fy) MonthsNarrow() []string {
   140  	return fy.monthsNarrow[1:]
   141  }
   142  
   143  // MonthWide returns the locales wide month given the 'month' provided
   144  func (fy *fy) MonthWide(month time.Month) string {
   145  	return fy.monthsWide[month]
   146  }
   147  
   148  // MonthsWide returns the locales wide months
   149  func (fy *fy) MonthsWide() []string {
   150  	return fy.monthsWide[1:]
   151  }
   152  
   153  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   154  func (fy *fy) WeekdayAbbreviated(weekday time.Weekday) string {
   155  	return fy.daysAbbreviated[weekday]
   156  }
   157  
   158  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   159  func (fy *fy) WeekdaysAbbreviated() []string {
   160  	return fy.daysAbbreviated
   161  }
   162  
   163  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   164  func (fy *fy) WeekdayNarrow(weekday time.Weekday) string {
   165  	return fy.daysNarrow[weekday]
   166  }
   167  
   168  // WeekdaysNarrow returns the locales narrow weekdays
   169  func (fy *fy) WeekdaysNarrow() []string {
   170  	return fy.daysNarrow
   171  }
   172  
   173  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   174  func (fy *fy) WeekdayShort(weekday time.Weekday) string {
   175  	return fy.daysShort[weekday]
   176  }
   177  
   178  // WeekdaysShort returns the locales short weekdays
   179  func (fy *fy) WeekdaysShort() []string {
   180  	return fy.daysShort
   181  }
   182  
   183  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   184  func (fy *fy) WeekdayWide(weekday time.Weekday) string {
   185  	return fy.daysWide[weekday]
   186  }
   187  
   188  // WeekdaysWide returns the locales wide weekdays
   189  func (fy *fy) WeekdaysWide() []string {
   190  	return fy.daysWide
   191  }
   192  
   193  // Decimal returns the decimal point of number
   194  func (fy *fy) Decimal() string {
   195  	return fy.decimal
   196  }
   197  
   198  // Group returns the group of number
   199  func (fy *fy) Group() string {
   200  	return fy.group
   201  }
   202  
   203  // Group returns the minus sign of number
   204  func (fy *fy) Minus() string {
   205  	return fy.minus
   206  }
   207  
   208  // FmtNumber returns 'num' with digits/precision of 'v' for 'fy' and handles both Whole and Real numbers based on 'v'
   209  func (fy *fy) FmtNumber(num float64, v uint64) string {
   210  
   211  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   212  	l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
   213  	count := 0
   214  	inWhole := v == 0
   215  	b := make([]byte, 0, l)
   216  
   217  	for i := len(s) - 1; i >= 0; i-- {
   218  
   219  		if s[i] == '.' {
   220  			b = append(b, fy.decimal[0])
   221  			inWhole = true
   222  			continue
   223  		}
   224  
   225  		if inWhole {
   226  			if count == 3 {
   227  				b = append(b, fy.group[0])
   228  				count = 1
   229  			} else {
   230  				count++
   231  			}
   232  		}
   233  
   234  		b = append(b, s[i])
   235  	}
   236  
   237  	if num < 0 {
   238  		b = append(b, fy.minus[0])
   239  	}
   240  
   241  	// reverse
   242  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   243  		b[i], b[j] = b[j], b[i]
   244  	}
   245  
   246  	return string(b)
   247  }
   248  
   249  // FmtPercent returns 'num' with digits/precision of 'v' for 'fy' and handles both Whole and Real numbers based on 'v'
   250  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   251  func (fy *fy) FmtPercent(num float64, v uint64) string {
   252  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   253  	l := len(s) + 3
   254  	b := make([]byte, 0, l)
   255  
   256  	for i := len(s) - 1; i >= 0; i-- {
   257  
   258  		if s[i] == '.' {
   259  			b = append(b, fy.decimal[0])
   260  			continue
   261  		}
   262  
   263  		b = append(b, s[i])
   264  	}
   265  
   266  	if num < 0 {
   267  		b = append(b, fy.minus[0])
   268  	}
   269  
   270  	// reverse
   271  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   272  		b[i], b[j] = b[j], b[i]
   273  	}
   274  
   275  	b = append(b, fy.percent...)
   276  
   277  	return string(b)
   278  }
   279  
   280  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'fy'
   281  func (fy *fy) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   282  
   283  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   284  	symbol := fy.currencies[currency]
   285  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   286  	count := 0
   287  	inWhole := v == 0
   288  	b := make([]byte, 0, l)
   289  
   290  	for i := len(s) - 1; i >= 0; i-- {
   291  
   292  		if s[i] == '.' {
   293  			b = append(b, fy.decimal[0])
   294  			inWhole = true
   295  			continue
   296  		}
   297  
   298  		if inWhole {
   299  			if count == 3 {
   300  				b = append(b, fy.group[0])
   301  				count = 1
   302  			} else {
   303  				count++
   304  			}
   305  		}
   306  
   307  		b = append(b, s[i])
   308  	}
   309  
   310  	for j := len(symbol) - 1; j >= 0; j-- {
   311  		b = append(b, symbol[j])
   312  	}
   313  
   314  	for j := len(fy.currencyPositivePrefix) - 1; j >= 0; j-- {
   315  		b = append(b, fy.currencyPositivePrefix[j])
   316  	}
   317  
   318  	if num < 0 {
   319  		b = append(b, fy.minus[0])
   320  	}
   321  
   322  	// reverse
   323  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   324  		b[i], b[j] = b[j], b[i]
   325  	}
   326  
   327  	if int(v) < 2 {
   328  
   329  		if v == 0 {
   330  			b = append(b, fy.decimal...)
   331  		}
   332  
   333  		for i := 0; i < 2-int(v); i++ {
   334  			b = append(b, '0')
   335  		}
   336  	}
   337  
   338  	return string(b)
   339  }
   340  
   341  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'fy'
   342  // in accounting notation.
   343  func (fy *fy) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   344  
   345  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   346  	symbol := fy.currencies[currency]
   347  	l := len(s) + len(symbol) + 6 + 1*len(s[:len(s)-int(v)-1])/3
   348  	count := 0
   349  	inWhole := v == 0
   350  	b := make([]byte, 0, l)
   351  
   352  	for i := len(s) - 1; i >= 0; i-- {
   353  
   354  		if s[i] == '.' {
   355  			b = append(b, fy.decimal[0])
   356  			inWhole = true
   357  			continue
   358  		}
   359  
   360  		if inWhole {
   361  			if count == 3 {
   362  				b = append(b, fy.group[0])
   363  				count = 1
   364  			} else {
   365  				count++
   366  			}
   367  		}
   368  
   369  		b = append(b, s[i])
   370  	}
   371  
   372  	if num < 0 {
   373  
   374  		for j := len(symbol) - 1; j >= 0; j-- {
   375  			b = append(b, symbol[j])
   376  		}
   377  
   378  		for j := len(fy.currencyNegativePrefix) - 1; j >= 0; j-- {
   379  			b = append(b, fy.currencyNegativePrefix[j])
   380  		}
   381  
   382  	} else {
   383  
   384  		for j := len(symbol) - 1; j >= 0; j-- {
   385  			b = append(b, symbol[j])
   386  		}
   387  
   388  		for j := len(fy.currencyPositivePrefix) - 1; j >= 0; j-- {
   389  			b = append(b, fy.currencyPositivePrefix[j])
   390  		}
   391  
   392  	}
   393  
   394  	// reverse
   395  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   396  		b[i], b[j] = b[j], b[i]
   397  	}
   398  
   399  	if int(v) < 2 {
   400  
   401  		if v == 0 {
   402  			b = append(b, fy.decimal...)
   403  		}
   404  
   405  		for i := 0; i < 2-int(v); i++ {
   406  			b = append(b, '0')
   407  		}
   408  	}
   409  
   410  	if num < 0 {
   411  		b = append(b, fy.currencyNegativeSuffix...)
   412  	}
   413  
   414  	return string(b)
   415  }
   416  
   417  // FmtDateShort returns the short date representation of 't' for 'fy'
   418  func (fy *fy) FmtDateShort(t time.Time) string {
   419  
   420  	b := make([]byte, 0, 32)
   421  
   422  	if t.Day() < 10 {
   423  		b = append(b, '0')
   424  	}
   425  
   426  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   427  	b = append(b, []byte{0x2d}...)
   428  
   429  	if t.Month() < 10 {
   430  		b = append(b, '0')
   431  	}
   432  
   433  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   434  
   435  	b = append(b, []byte{0x2d}...)
   436  
   437  	if t.Year() > 9 {
   438  		b = append(b, strconv.Itoa(t.Year())[2:]...)
   439  	} else {
   440  		b = append(b, strconv.Itoa(t.Year())[1:]...)
   441  	}
   442  
   443  	return string(b)
   444  }
   445  
   446  // FmtDateMedium returns the medium date representation of 't' for 'fy'
   447  func (fy *fy) FmtDateMedium(t time.Time) string {
   448  
   449  	b := make([]byte, 0, 32)
   450  
   451  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   452  	b = append(b, []byte{0x20}...)
   453  	b = append(b, fy.monthsAbbreviated[t.Month()]...)
   454  	b = append(b, []byte{0x20}...)
   455  
   456  	if t.Year() > 0 {
   457  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   458  	} else {
   459  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   460  	}
   461  
   462  	return string(b)
   463  }
   464  
   465  // FmtDateLong returns the long date representation of 't' for 'fy'
   466  func (fy *fy) FmtDateLong(t time.Time) string {
   467  
   468  	b := make([]byte, 0, 32)
   469  
   470  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   471  	b = append(b, []byte{0x20}...)
   472  	b = append(b, fy.monthsWide[t.Month()]...)
   473  	b = append(b, []byte{0x20}...)
   474  
   475  	if t.Year() > 0 {
   476  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   477  	} else {
   478  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   479  	}
   480  
   481  	return string(b)
   482  }
   483  
   484  // FmtDateFull returns the full date representation of 't' for 'fy'
   485  func (fy *fy) FmtDateFull(t time.Time) string {
   486  
   487  	b := make([]byte, 0, 32)
   488  
   489  	b = append(b, fy.daysWide[t.Weekday()]...)
   490  	b = append(b, []byte{0x20}...)
   491  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   492  	b = append(b, []byte{0x20}...)
   493  	b = append(b, fy.monthsWide[t.Month()]...)
   494  	b = append(b, []byte{0x20}...)
   495  
   496  	if t.Year() > 0 {
   497  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   498  	} else {
   499  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   500  	}
   501  
   502  	return string(b)
   503  }
   504  
   505  // FmtTimeShort returns the short time representation of 't' for 'fy'
   506  func (fy *fy) FmtTimeShort(t time.Time) string {
   507  
   508  	b := make([]byte, 0, 32)
   509  
   510  	if t.Hour() < 10 {
   511  		b = append(b, '0')
   512  	}
   513  
   514  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   515  	b = append(b, fy.timeSeparator...)
   516  
   517  	if t.Minute() < 10 {
   518  		b = append(b, '0')
   519  	}
   520  
   521  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   522  
   523  	return string(b)
   524  }
   525  
   526  // FmtTimeMedium returns the medium time representation of 't' for 'fy'
   527  func (fy *fy) FmtTimeMedium(t time.Time) string {
   528  
   529  	b := make([]byte, 0, 32)
   530  
   531  	if t.Hour() < 10 {
   532  		b = append(b, '0')
   533  	}
   534  
   535  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   536  	b = append(b, fy.timeSeparator...)
   537  
   538  	if t.Minute() < 10 {
   539  		b = append(b, '0')
   540  	}
   541  
   542  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   543  	b = append(b, fy.timeSeparator...)
   544  
   545  	if t.Second() < 10 {
   546  		b = append(b, '0')
   547  	}
   548  
   549  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   550  
   551  	return string(b)
   552  }
   553  
   554  // FmtTimeLong returns the long time representation of 't' for 'fy'
   555  func (fy *fy) FmtTimeLong(t time.Time) string {
   556  
   557  	b := make([]byte, 0, 32)
   558  
   559  	if t.Hour() < 10 {
   560  		b = append(b, '0')
   561  	}
   562  
   563  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   564  	b = append(b, fy.timeSeparator...)
   565  
   566  	if t.Minute() < 10 {
   567  		b = append(b, '0')
   568  	}
   569  
   570  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   571  	b = append(b, fy.timeSeparator...)
   572  
   573  	if t.Second() < 10 {
   574  		b = append(b, '0')
   575  	}
   576  
   577  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   578  	b = append(b, []byte{0x20}...)
   579  
   580  	tz, _ := t.Zone()
   581  	b = append(b, tz...)
   582  
   583  	return string(b)
   584  }
   585  
   586  // FmtTimeFull returns the full time representation of 't' for 'fy'
   587  func (fy *fy) FmtTimeFull(t time.Time) string {
   588  
   589  	b := make([]byte, 0, 32)
   590  
   591  	if t.Hour() < 10 {
   592  		b = append(b, '0')
   593  	}
   594  
   595  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   596  	b = append(b, fy.timeSeparator...)
   597  
   598  	if t.Minute() < 10 {
   599  		b = append(b, '0')
   600  	}
   601  
   602  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   603  	b = append(b, fy.timeSeparator...)
   604  
   605  	if t.Second() < 10 {
   606  		b = append(b, '0')
   607  	}
   608  
   609  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   610  	b = append(b, []byte{0x20}...)
   611  
   612  	tz, _ := t.Zone()
   613  
   614  	if btz, ok := fy.timezones[tz]; ok {
   615  		b = append(b, btz...)
   616  	} else {
   617  		b = append(b, tz...)
   618  	}
   619  
   620  	return string(b)
   621  }
   622  

View as plain text