...

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

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

     1  package sw_CD
     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 sw_CD 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  	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 'sw_CD' locale
    45  func New() locales.Translator {
    46  	return &sw_CD{
    47  		locale:                 "sw_CD",
    48  		pluralsCardinal:        []locales.PluralRule{2, 6},
    49  		pluralsOrdinal:         []locales.PluralRule{6},
    50  		pluralsRange:           []locales.PluralRule{2, 6},
    51  		decimal:                ",",
    52  		group:                  ".",
    53  		minus:                  "-",
    54  		percent:                "%",
    55  		perMille:               "‰",
    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", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "FC", "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"},
    59  		currencyPositivePrefix: " ",
    60  		currencyNegativePrefix: " ",
    61  		monthsAbbreviated:      []string{"", "Jan", "Feb", "Mac", "Apr", "Mei", "Jun", "Jul", "Ago", "Sep", "Okt", "Nov", "Des"},
    62  		monthsNarrow:           []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
    63  		monthsWide:             []string{"", "Januari", "Februari", "Machi", "Aprili", "Mei", "Juni", "Julai", "Agosti", "Septemba", "Oktoba", "Novemba", "Desemba"},
    64  		daysAbbreviated:        []string{"Jumapili", "Jumatatu", "Jumanne", "Jumatano", "Alhamisi", "Ijumaa", "Jumamosi"},
    65  		daysNarrow:             []string{"S", "M", "T", "W", "T", "F", "S"},
    66  		daysShort:              []string{"Jumapili", "Jumatatu", "Jumanne", "Jumatano", "Alhamisi", "Ijumaa", "Jumamosi"},
    67  		daysWide:               []string{"Jumapili", "Jumatatu", "Jumanne", "Jumatano", "Alhamisi", "Ijumaa", "Jumamosi"},
    68  		periodsAbbreviated:     []string{"AM", "PM"},
    69  		periodsNarrow:          []string{"am", "pm"},
    70  		periodsWide:            []string{"AM", "PM"},
    71  		erasAbbreviated:        []string{"KK", "BK"},
    72  		erasNarrow:             []string{"", ""},
    73  		erasWide:               []string{"Kabla ya Kristo", "Baada ya Kristo"},
    74  		timezones:              map[string]string{"ACDT": "Saa za Mchana za Australia ya Kati", "ACST": "Saa za Wastani za Australia ya Kati", "ACWDT": "Saa za Mchana za Magharibi ya Kati ya Australia", "ACWST": "Saa za Wastani za Magharibi ya Kati ya Australia", "ADT": "Saa za Mchana za Atlantiki", "AEDT": "Saa za Mchana za Mashariki mwa Australia", "AEST": "Saa za Wastani za Mashariki mwa Australia", "AKDT": "Saa za Mchana za Alaska", "AKST": "Saa za Wastani za Alaska", "ARST": "Saa za Majira ya joto za Argentina", "ART": "Saa za Wastani za Argentina", "AST": "Saa za Wastani za Atlantiki", "AWDT": "Saa za Mchana za Australia Magharibi", "AWST": "Saa za Wastani za Australia Magharibi", "BOT": "Saa za Bolivia", "BT": "Saa za Bhutan", "CAT": "Saa za Afrika ya Kati", "CDT": "Saa za Mchana za Kati", "CHADT": "Saa za Mchana za Chatham", "CHAST": "Saa za Wastani za Chatham", "CLST": "Saa za Majira ya joto za Chile", "CLT": "Saa za Wastani za Chile", "COST": "Saa za Majira ya joto za Colombia", "COT": "Saa za Wastani za Colombia", "CST": "Saa za Wastani za Kati", "ChST": "Saa za Wastani za Chamorro", "EAT": "Saa za Afrika Mashariki", "ECT": "Saa za Ecuador", "EDT": "Saa za Mchana za Mashariki", "EST": "Saa za Wastani za Mashariki", "GFT": "Saa za Guiana ya Ufaransa", "GMT": "Saa za Greenwich", "GST": "Saa za Wastani za Gulf", "GYT": "Saa za Guyana", "HADT": "Saa za Mchana za Hawaii-Aleutian", "HAST": "Saa za Wastani za Hawaii-Aleutian", "HAT": "Saa za Mchana za Newfoundland", "HECU": "Saa za Mchana za Cuba", "HEEG": "Saa za Majira ya joto za Greenland Mashariki", "HENOMX": "Saa za mchana za Mexico Kaskazini Magharibi", "HEOG": "Saa za Majira ya joto za Greenland Magharibi", "HEPM": "Saa za Mchana za Saint-Pierre na Miquelon", "HEPMX": "Saa za mchana za pasifiki za Mexico", "HKST": "Saa za Majira ya joto za Hong Kong", "HKT": "Saa za Wastani za Hong Kong", "HNCU": "Saa za Wastani ya Cuba", "HNEG": "Saa za Wastani za Greenland Mashariki", "HNNOMX": "Saa za Wastani za Mexico Kaskazini Magharibi", "HNOG": "Saa za Wastani za Greenland Magharibi", "HNPM": "Saa za Wastani ya Saint-Pierre na Miquelon", "HNPMX": "Saa za wastani za pasifiki za Mexico", "HNT": "Saa za Wastani za Newfoundland", "IST": "Saa Wastani za India", "JDT": "Saa za Mchana za Japan", "JST": "Saa Wastani za Japan", "LHDT": "Saa za Mchana za Lord Howe", "LHST": "Saa za Wastani za Lord Howe", "MDT": "Saa za Mchana za Mountain", "MESZ": "Saa za Majira ya joto za Ulaya ya Kati", "MEZ": "Saa za Wastani za Ulaya ya kati", "MST": "Saa za Wastani za Mountain", "MYT": "Saa za Malaysia", "NZDT": "Saa za Mchana za New Zealand", "NZST": "Saa za Wastani za New Zealand", "OESZ": "Saa za Majira ya joto za Mashariki mwa Ulaya", "OEZ": "Saa za Wastani za Mashariki mwa Ulaya", "PDT": "Saa za Mchana za Pasifiki", "PST": "Saa za Wastani za Pasifiki", "SAST": "Saa za Wastani za Afrika Kusini", "SGT": "Saa za Wastani za Singapore", "SRT": "Saa za Suriname", "TMST": "Saa za Majira ya joto za Turkmenistan", "TMT": "Saa za Wastani za Turkmenistan", "UYST": "Saa za Majira ya joto za Uruguay", "UYT": "Saa za Wastani za Uruguay", "VET": "Saa za Venezuela", "WARST": "Saa za Majira ya joto za Magharibi mwa Argentina", "WART": "Saa za Wastani za Magharibi mwa Argentina", "WAST": "Saa za Majira ya joto za Afrika Magharibi", "WAT": "Saa za Wastani za Afrika Magharibi", "WESZ": "Saa za Majira ya joto za Magharibi mwa Ulaya", "WEZ": "Saa za Wastani za Magharibi mwa Ulaya", "WIB": "Saa za Magharibi mwa Indonesia", "WIT": "Saa za Mashariki mwa Indonesia", "WITA": "Saa za Indonesia ya Kati", "∅∅∅": "Saa za Majira ya joto za Azores"},
    75  	}
    76  }
    77  
    78  // Locale returns the current translators string locale
    79  func (sw *sw_CD) Locale() string {
    80  	return sw.locale
    81  }
    82  
    83  // PluralsCardinal returns the list of cardinal plural rules associated with 'sw_CD'
    84  func (sw *sw_CD) PluralsCardinal() []locales.PluralRule {
    85  	return sw.pluralsCardinal
    86  }
    87  
    88  // PluralsOrdinal returns the list of ordinal plural rules associated with 'sw_CD'
    89  func (sw *sw_CD) PluralsOrdinal() []locales.PluralRule {
    90  	return sw.pluralsOrdinal
    91  }
    92  
    93  // PluralsRange returns the list of range plural rules associated with 'sw_CD'
    94  func (sw *sw_CD) PluralsRange() []locales.PluralRule {
    95  	return sw.pluralsRange
    96  }
    97  
    98  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'sw_CD'
    99  func (sw *sw_CD) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
   100  
   101  	n := math.Abs(num)
   102  	i := int64(n)
   103  
   104  	if i == 1 && v == 0 {
   105  		return locales.PluralRuleOne
   106  	}
   107  
   108  	return locales.PluralRuleOther
   109  }
   110  
   111  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'sw_CD'
   112  func (sw *sw_CD) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
   113  	return locales.PluralRuleOther
   114  }
   115  
   116  // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'sw_CD'
   117  func (sw *sw_CD) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   118  
   119  	start := sw.CardinalPluralRule(num1, v1)
   120  	end := sw.CardinalPluralRule(num2, v2)
   121  
   122  	if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
   123  		return locales.PluralRuleOther
   124  	} else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
   125  		return locales.PluralRuleOne
   126  	}
   127  
   128  	return locales.PluralRuleOther
   129  
   130  }
   131  
   132  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   133  func (sw *sw_CD) MonthAbbreviated(month time.Month) string {
   134  	return sw.monthsAbbreviated[month]
   135  }
   136  
   137  // MonthsAbbreviated returns the locales abbreviated months
   138  func (sw *sw_CD) MonthsAbbreviated() []string {
   139  	return sw.monthsAbbreviated[1:]
   140  }
   141  
   142  // MonthNarrow returns the locales narrow month given the 'month' provided
   143  func (sw *sw_CD) MonthNarrow(month time.Month) string {
   144  	return sw.monthsNarrow[month]
   145  }
   146  
   147  // MonthsNarrow returns the locales narrow months
   148  func (sw *sw_CD) MonthsNarrow() []string {
   149  	return sw.monthsNarrow[1:]
   150  }
   151  
   152  // MonthWide returns the locales wide month given the 'month' provided
   153  func (sw *sw_CD) MonthWide(month time.Month) string {
   154  	return sw.monthsWide[month]
   155  }
   156  
   157  // MonthsWide returns the locales wide months
   158  func (sw *sw_CD) MonthsWide() []string {
   159  	return sw.monthsWide[1:]
   160  }
   161  
   162  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   163  func (sw *sw_CD) WeekdayAbbreviated(weekday time.Weekday) string {
   164  	return sw.daysAbbreviated[weekday]
   165  }
   166  
   167  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   168  func (sw *sw_CD) WeekdaysAbbreviated() []string {
   169  	return sw.daysAbbreviated
   170  }
   171  
   172  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   173  func (sw *sw_CD) WeekdayNarrow(weekday time.Weekday) string {
   174  	return sw.daysNarrow[weekday]
   175  }
   176  
   177  // WeekdaysNarrow returns the locales narrow weekdays
   178  func (sw *sw_CD) WeekdaysNarrow() []string {
   179  	return sw.daysNarrow
   180  }
   181  
   182  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   183  func (sw *sw_CD) WeekdayShort(weekday time.Weekday) string {
   184  	return sw.daysShort[weekday]
   185  }
   186  
   187  // WeekdaysShort returns the locales short weekdays
   188  func (sw *sw_CD) WeekdaysShort() []string {
   189  	return sw.daysShort
   190  }
   191  
   192  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   193  func (sw *sw_CD) WeekdayWide(weekday time.Weekday) string {
   194  	return sw.daysWide[weekday]
   195  }
   196  
   197  // WeekdaysWide returns the locales wide weekdays
   198  func (sw *sw_CD) WeekdaysWide() []string {
   199  	return sw.daysWide
   200  }
   201  
   202  // Decimal returns the decimal point of number
   203  func (sw *sw_CD) Decimal() string {
   204  	return sw.decimal
   205  }
   206  
   207  // Group returns the group of number
   208  func (sw *sw_CD) Group() string {
   209  	return sw.group
   210  }
   211  
   212  // Group returns the minus sign of number
   213  func (sw *sw_CD) Minus() string {
   214  	return sw.minus
   215  }
   216  
   217  // FmtNumber returns 'num' with digits/precision of 'v' for 'sw_CD' and handles both Whole and Real numbers based on 'v'
   218  func (sw *sw_CD) FmtNumber(num float64, v uint64) string {
   219  
   220  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   221  	l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
   222  	count := 0
   223  	inWhole := v == 0
   224  	b := make([]byte, 0, l)
   225  
   226  	for i := len(s) - 1; i >= 0; i-- {
   227  
   228  		if s[i] == '.' {
   229  			b = append(b, sw.decimal[0])
   230  			inWhole = true
   231  			continue
   232  		}
   233  
   234  		if inWhole {
   235  			if count == 3 {
   236  				b = append(b, sw.group[0])
   237  				count = 1
   238  			} else {
   239  				count++
   240  			}
   241  		}
   242  
   243  		b = append(b, s[i])
   244  	}
   245  
   246  	if num < 0 {
   247  		b = append(b, sw.minus[0])
   248  	}
   249  
   250  	// reverse
   251  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   252  		b[i], b[j] = b[j], b[i]
   253  	}
   254  
   255  	return string(b)
   256  }
   257  
   258  // FmtPercent returns 'num' with digits/precision of 'v' for 'sw_CD' and handles both Whole and Real numbers based on 'v'
   259  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   260  func (sw *sw_CD) FmtPercent(num float64, v uint64) string {
   261  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   262  	l := len(s) + 3
   263  	b := make([]byte, 0, l)
   264  
   265  	for i := len(s) - 1; i >= 0; i-- {
   266  
   267  		if s[i] == '.' {
   268  			b = append(b, sw.decimal[0])
   269  			continue
   270  		}
   271  
   272  		b = append(b, s[i])
   273  	}
   274  
   275  	if num < 0 {
   276  		b = append(b, sw.minus[0])
   277  	}
   278  
   279  	// reverse
   280  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   281  		b[i], b[j] = b[j], b[i]
   282  	}
   283  
   284  	b = append(b, sw.percent...)
   285  
   286  	return string(b)
   287  }
   288  
   289  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'sw_CD'
   290  func (sw *sw_CD) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   291  
   292  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   293  	symbol := sw.currencies[currency]
   294  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   295  	count := 0
   296  	inWhole := v == 0
   297  	b := make([]byte, 0, l)
   298  
   299  	for i := len(s) - 1; i >= 0; i-- {
   300  
   301  		if s[i] == '.' {
   302  			b = append(b, sw.decimal[0])
   303  			inWhole = true
   304  			continue
   305  		}
   306  
   307  		if inWhole {
   308  			if count == 3 {
   309  				b = append(b, sw.group[0])
   310  				count = 1
   311  			} else {
   312  				count++
   313  			}
   314  		}
   315  
   316  		b = append(b, s[i])
   317  	}
   318  
   319  	for j := len(symbol) - 1; j >= 0; j-- {
   320  		b = append(b, symbol[j])
   321  	}
   322  
   323  	for j := len(sw.currencyPositivePrefix) - 1; j >= 0; j-- {
   324  		b = append(b, sw.currencyPositivePrefix[j])
   325  	}
   326  
   327  	if num < 0 {
   328  		b = append(b, sw.minus[0])
   329  	}
   330  
   331  	// reverse
   332  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   333  		b[i], b[j] = b[j], b[i]
   334  	}
   335  
   336  	if int(v) < 2 {
   337  
   338  		if v == 0 {
   339  			b = append(b, sw.decimal...)
   340  		}
   341  
   342  		for i := 0; i < 2-int(v); i++ {
   343  			b = append(b, '0')
   344  		}
   345  	}
   346  
   347  	return string(b)
   348  }
   349  
   350  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'sw_CD'
   351  // in accounting notation.
   352  func (sw *sw_CD) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   353  
   354  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   355  	symbol := sw.currencies[currency]
   356  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   357  	count := 0
   358  	inWhole := v == 0
   359  	b := make([]byte, 0, l)
   360  
   361  	for i := len(s) - 1; i >= 0; i-- {
   362  
   363  		if s[i] == '.' {
   364  			b = append(b, sw.decimal[0])
   365  			inWhole = true
   366  			continue
   367  		}
   368  
   369  		if inWhole {
   370  			if count == 3 {
   371  				b = append(b, sw.group[0])
   372  				count = 1
   373  			} else {
   374  				count++
   375  			}
   376  		}
   377  
   378  		b = append(b, s[i])
   379  	}
   380  
   381  	if num < 0 {
   382  
   383  		for j := len(symbol) - 1; j >= 0; j-- {
   384  			b = append(b, symbol[j])
   385  		}
   386  
   387  		for j := len(sw.currencyNegativePrefix) - 1; j >= 0; j-- {
   388  			b = append(b, sw.currencyNegativePrefix[j])
   389  		}
   390  
   391  		b = append(b, sw.minus[0])
   392  
   393  	} else {
   394  
   395  		for j := len(symbol) - 1; j >= 0; j-- {
   396  			b = append(b, symbol[j])
   397  		}
   398  
   399  		for j := len(sw.currencyPositivePrefix) - 1; j >= 0; j-- {
   400  			b = append(b, sw.currencyPositivePrefix[j])
   401  		}
   402  
   403  	}
   404  
   405  	// reverse
   406  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   407  		b[i], b[j] = b[j], b[i]
   408  	}
   409  
   410  	if int(v) < 2 {
   411  
   412  		if v == 0 {
   413  			b = append(b, sw.decimal...)
   414  		}
   415  
   416  		for i := 0; i < 2-int(v); i++ {
   417  			b = append(b, '0')
   418  		}
   419  	}
   420  
   421  	return string(b)
   422  }
   423  
   424  // FmtDateShort returns the short date representation of 't' for 'sw_CD'
   425  func (sw *sw_CD) FmtDateShort(t time.Time) string {
   426  
   427  	b := make([]byte, 0, 32)
   428  
   429  	if t.Day() < 10 {
   430  		b = append(b, '0')
   431  	}
   432  
   433  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   434  	b = append(b, []byte{0x2f}...)
   435  
   436  	if t.Month() < 10 {
   437  		b = append(b, '0')
   438  	}
   439  
   440  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   441  
   442  	b = append(b, []byte{0x2f}...)
   443  
   444  	if t.Year() > 0 {
   445  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   446  	} else {
   447  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   448  	}
   449  
   450  	return string(b)
   451  }
   452  
   453  // FmtDateMedium returns the medium date representation of 't' for 'sw_CD'
   454  func (sw *sw_CD) FmtDateMedium(t time.Time) string {
   455  
   456  	b := make([]byte, 0, 32)
   457  
   458  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   459  	b = append(b, []byte{0x20}...)
   460  	b = append(b, sw.monthsAbbreviated[t.Month()]...)
   461  	b = append(b, []byte{0x20}...)
   462  
   463  	if t.Year() > 0 {
   464  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   465  	} else {
   466  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   467  	}
   468  
   469  	return string(b)
   470  }
   471  
   472  // FmtDateLong returns the long date representation of 't' for 'sw_CD'
   473  func (sw *sw_CD) FmtDateLong(t time.Time) string {
   474  
   475  	b := make([]byte, 0, 32)
   476  
   477  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   478  	b = append(b, []byte{0x20}...)
   479  	b = append(b, sw.monthsWide[t.Month()]...)
   480  	b = append(b, []byte{0x20}...)
   481  
   482  	if t.Year() > 0 {
   483  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   484  	} else {
   485  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   486  	}
   487  
   488  	return string(b)
   489  }
   490  
   491  // FmtDateFull returns the full date representation of 't' for 'sw_CD'
   492  func (sw *sw_CD) FmtDateFull(t time.Time) string {
   493  
   494  	b := make([]byte, 0, 32)
   495  
   496  	b = append(b, sw.daysWide[t.Weekday()]...)
   497  	b = append(b, []byte{0x2c, 0x20}...)
   498  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   499  	b = append(b, []byte{0x20}...)
   500  	b = append(b, sw.monthsWide[t.Month()]...)
   501  	b = append(b, []byte{0x20}...)
   502  
   503  	if t.Year() > 0 {
   504  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   505  	} else {
   506  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   507  	}
   508  
   509  	return string(b)
   510  }
   511  
   512  // FmtTimeShort returns the short time representation of 't' for 'sw_CD'
   513  func (sw *sw_CD) FmtTimeShort(t time.Time) string {
   514  
   515  	b := make([]byte, 0, 32)
   516  
   517  	if t.Hour() < 10 {
   518  		b = append(b, '0')
   519  	}
   520  
   521  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   522  	b = append(b, sw.timeSeparator...)
   523  
   524  	if t.Minute() < 10 {
   525  		b = append(b, '0')
   526  	}
   527  
   528  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   529  
   530  	return string(b)
   531  }
   532  
   533  // FmtTimeMedium returns the medium time representation of 't' for 'sw_CD'
   534  func (sw *sw_CD) FmtTimeMedium(t time.Time) string {
   535  
   536  	b := make([]byte, 0, 32)
   537  
   538  	if t.Hour() < 10 {
   539  		b = append(b, '0')
   540  	}
   541  
   542  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   543  	b = append(b, sw.timeSeparator...)
   544  
   545  	if t.Minute() < 10 {
   546  		b = append(b, '0')
   547  	}
   548  
   549  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   550  	b = append(b, sw.timeSeparator...)
   551  
   552  	if t.Second() < 10 {
   553  		b = append(b, '0')
   554  	}
   555  
   556  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   557  
   558  	return string(b)
   559  }
   560  
   561  // FmtTimeLong returns the long time representation of 't' for 'sw_CD'
   562  func (sw *sw_CD) FmtTimeLong(t time.Time) string {
   563  
   564  	b := make([]byte, 0, 32)
   565  
   566  	if t.Hour() < 10 {
   567  		b = append(b, '0')
   568  	}
   569  
   570  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   571  	b = append(b, sw.timeSeparator...)
   572  
   573  	if t.Minute() < 10 {
   574  		b = append(b, '0')
   575  	}
   576  
   577  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   578  	b = append(b, sw.timeSeparator...)
   579  
   580  	if t.Second() < 10 {
   581  		b = append(b, '0')
   582  	}
   583  
   584  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   585  	b = append(b, []byte{0x20}...)
   586  
   587  	tz, _ := t.Zone()
   588  	b = append(b, tz...)
   589  
   590  	return string(b)
   591  }
   592  
   593  // FmtTimeFull returns the full time representation of 't' for 'sw_CD'
   594  func (sw *sw_CD) FmtTimeFull(t time.Time) string {
   595  
   596  	b := make([]byte, 0, 32)
   597  
   598  	if t.Hour() < 10 {
   599  		b = append(b, '0')
   600  	}
   601  
   602  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   603  	b = append(b, sw.timeSeparator...)
   604  
   605  	if t.Minute() < 10 {
   606  		b = append(b, '0')
   607  	}
   608  
   609  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   610  	b = append(b, sw.timeSeparator...)
   611  
   612  	if t.Second() < 10 {
   613  		b = append(b, '0')
   614  	}
   615  
   616  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   617  	b = append(b, []byte{0x20}...)
   618  
   619  	tz, _ := t.Zone()
   620  
   621  	if btz, ok := sw.timezones[tz]; ok {
   622  		b = append(b, btz...)
   623  	} else {
   624  		b = append(b, tz...)
   625  	}
   626  
   627  	return string(b)
   628  }
   629  

View as plain text