...

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

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

     1  package so
     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 so 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  	currencyNegativePrefix 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 'so' locale
    45  func New() locales.Translator {
    46  	return &so{
    47  		locale:                 "so",
    48  		pluralsCardinal:        []locales.PluralRule{2, 6},
    49  		pluralsOrdinal:         nil,
    50  		pluralsRange:           nil,
    51  		timeSeparator:          ":",
    52  		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", "DBB", "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", "S", "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"},
    53  		currencyNegativePrefix: "(",
    54  		currencyNegativeSuffix: ")",
    55  		monthsAbbreviated:      []string{"", "Jan", "Feb", "Mar", "Abr", "May", "Jun", "Lul", "Ogs", "Seb", "Okt", "Nof", "Dis"},
    56  		monthsNarrow:           []string{"", "J", "F", "M", "A", "M", "J", "L", "O", "S", "O", "N", "D"},
    57  		monthsWide:             []string{"", "Bisha Koobaad", "Bisha Labaad", "Bisha Saddexaad", "Bisha Afraad", "Bisha Shanaad", "Bisha Lixaad", "Bisha Todobaad", "Bisha Sideedaad", "Bisha Sagaalaad", "Bisha Tobnaad", "Bisha Kow iyo Tobnaad", "Bisha Laba iyo Tobnaad"},
    58  		daysAbbreviated:        []string{"Axd", "Isn", "Tldo", "Arbc", "Khms", "Jmc", "Sbti"},
    59  		daysNarrow:             []string{"A", "I", "T", "A", "Kh", "J", "S"},
    60  		daysShort:              []string{"Axd", "Isn", "Tldo", "Arbc", "Khms", "Jmc", "Sbti"},
    61  		daysWide:               []string{"Axad", "Isniin", "Talaado", "Arbaco", "Khamiis", "Jimco", "Sabti"},
    62  		periodsAbbreviated:     []string{"GH", "GD"},
    63  		periodsNarrow:          []string{"h", "d"},
    64  		periodsWide:            []string{"GH", "GD"},
    65  		erasAbbreviated:        []string{"CH", "CD"},
    66  		erasNarrow:             []string{"", ""},
    67  		erasWide:               []string{"Ciise Hortii", "Ciise Dabadii"},
    68  		timezones:              map[string]string{"ACDT": "Waqtiga Dharaarta ee Bartamaha Astaraaliya", "ACST": "Waqtiga Caadiga Ah ee Bartamaha Astaraaliya", "ACWDT": "Waqtiga Dharaarta Bartamaha Galbeedka Australiya", "ACWST": "Waqtiga Caadiga Ah ee Bartamaha Galbeedka Astaraaliya", "ADT": "Waqtiga Dharaarta ee Atlantika Waqooyiga Ameerika", "AEDT": "Waqtiga Dharaarta ee Bariga Astaraaliya", "AEST": "Waqtiyada Caadiga ah ee Bariga Astaraaliya", "AKDT": "Waqtiga Dharaarta ee Alaska", "AKST": "Waqtiga Caadiga Ah ee Alaska", "ARST": "Waqtiga Xagaaga ee Arjentiina", "ART": "Waqtiga Caadiga Ah ee Arjentiina", "AST": "Waqtiga Caadiga Ah ee Atlantika Waqooyiga Ameerika", "AWDT": "Waqtiga Dharaarta ee Galbeedka Astaraaliya", "AWST": "Waqtiga Caadiga Ah ee Galbeedka Astaraaliya", "BOT": "Waqtiga Boliifiya", "BT": "Waqtiga Butaan", "CAT": "Waqtiga Bartamaha Afrika", "CDT": "Waqtiga Dharaarta ee Bartamaha Waqooyiga Ameerika", "CHADT": "Waqtiga Dharaarta ee Jaatam", "CHAST": "Waqtiga Caadiga Ah ee Jaatam", "CLST": "Waqtiga Xagaaga ee Jili", "CLT": "Waqtiga Caadiga Ah ee Jili", "COST": "Waqtiga Xagaaga ee Kolambiya", "COT": "Waqtiga Caadiga Ah ee Kolambiya", "CST": "Waqtiga Caadiga Ah ee Bartamaha Waqooyiga Ameerika", "ChST": "Waqtiga Jamoro", "EAT": "Waqtiga Bariga Afrika", "ECT": "Waqtiga Ekuwadoor", "EDT": "Waqtiga Dharaarta ee Bariga Waqooyiga Ameerika", "EST": "Waqtiga Caadiga Ah ee Bariga Waqooyiga Ameerika", "GFT": "Waqtiga Ferenj Guyana", "GMT": "Waqtiga Celceliska Giriinwij", "GST": "Waqtiga Gacanka", "GYT": "Waqtiga Guyaana", "HADT": "Waqtiga Dharaarta ee Hawaay-Alutiyaan", "HAST": "Waqtiga Caadiga Ah ee Hawaay-Alutiyaan", "HAT": "Waqtiga Dharaarta ee Niyuufoonlaan", "HECU": "Waqtiga Dharaarta ee Kuuba", "HEEG": "Waqtiga Xagaaga ee Bariga Giriinlaan", "HENOMX": "Waqtiga Dharaarta ee Waqooyi-Galbeed Meksiko", "HEOG": "Waqtiga Xagaaga ee Galbeedka Giriinlaan", "HEPM": "Waqtiga Dharaarta ee St. Beere & Mikiwelon", "HEPMX": "Waqtiga Dharaarta ee Baasifikada Meksiko", "HKST": "Waqtiga Xagaaga ee Hoong Koong", "HKT": "Waqtiga Caadiga Ah ee Hoong Koong", "HNCU": "Waqtiga Caadiga Ah ee Kuuba", "HNEG": "Waqtiga Caadiga ah ee Bariga Giriinlaan", "HNNOMX": "Waqtiga Caadiga Ah ee Waqooyi-Galbeed Meksiko", "HNOG": "Waqtiga Caadiga Ah ee Galbeedka Giriinlaan", "HNPM": "Waqtiga Caadiga Ah St. Beere & Mikiwelon", "HNPMX": "Waqtiga Caadiga Ah ee Baasifikada Meksiko", "HNT": "Waqtiga Caadiga Ah ee Niyuufoonlaan", "IST": "Waqtiga Caadiga Ah ee Hindiya", "JDT": "Waqtiga Dharaarta ee Jabaan", "JST": "Waqtiga Caadiga Ah ee Jabaan", "LHDT": "Waqtiga Dharaarta ee Lod How", "LHST": "Waqtiga Caadiga Ah ee Lod How", "MDT": "Waqtiga Dharaarta ee Buurleyda Waqooyiga Ameerika", "MESZ": "Waqtiga Xagaaga ee Bartamaha Yurub", "MEZ": "Waqtiga Caadiga Ah ee Bartamaha Yurub", "MST": "Waqtiga Caadiga ah ee Buuraleyda Waqooyiga Ameerika", "MYT": "Waqtiga Maleyshiya", "NZDT": "Waqtiga Dharaarta ee Niyuu Si’laan", "NZST": "Waqtiga Caadiga Ah ee Niyuu Si’laan", "OESZ": "Waqtiga Xagaaga ee Bariga Yurub", "OEZ": "Waqtiga Caadiga Ah ee Bariga Yurub", "PDT": "Waqtiga Dharaarta ee Basifika Waqooyiga Ameerika", "PST": "Waqtiga Caadiga ah ee Basifika Waqooyiga Ameerika", "SAST": "Waqtiyada Caadiga Ah ee Koonfur Afrika", "SGT": "Waqtiga Singabuur", "SRT": "Waqtiga Surineym", "TMST": "Waqtiga Xagaaga ee Turkmenistan", "TMT": "Waqtiga Caadiga Ah ee Turkmenistan", "UYST": "Waqtiga Xagaaga ee Urugwaay", "UYT": "Waqtiga Caadiga Ah ee Urugwaay", "VET": "Waqtiga Fenezuweela", "WARST": "Waqtiga Xagaaga ee Galbeedka Arjentiina", "WART": "Waqtiga Caadiga Ah ee Galbeedka Arjentiina", "WAST": "Waqtiga Xagaaga ee Galbeedka Afrika", "WAT": "Waqtiga Caadiga Ah ee Galbeedka Afrika", "WESZ": "Waqtiga Xagaaga ee Galbeedka Yurub", "WEZ": "Waqtiga Caadiga Ah ee Galbeedka Yurub", "WIB": "Waqtiga Galbeedka Indoneeysiya", "WIT": "Waqtiga Indoneeysiya", "WITA": "Waqtiga Bartamaha Indoneeysiya", "∅∅∅": "Waqtiga Xagaaga ee Asores"},
    69  	}
    70  }
    71  
    72  // Locale returns the current translators string locale
    73  func (so *so) Locale() string {
    74  	return so.locale
    75  }
    76  
    77  // PluralsCardinal returns the list of cardinal plural rules associated with 'so'
    78  func (so *so) PluralsCardinal() []locales.PluralRule {
    79  	return so.pluralsCardinal
    80  }
    81  
    82  // PluralsOrdinal returns the list of ordinal plural rules associated with 'so'
    83  func (so *so) PluralsOrdinal() []locales.PluralRule {
    84  	return so.pluralsOrdinal
    85  }
    86  
    87  // PluralsRange returns the list of range plural rules associated with 'so'
    88  func (so *so) PluralsRange() []locales.PluralRule {
    89  	return so.pluralsRange
    90  }
    91  
    92  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'so'
    93  func (so *so) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
    94  
    95  	n := math.Abs(num)
    96  
    97  	if n == 1 {
    98  		return locales.PluralRuleOne
    99  	}
   100  
   101  	return locales.PluralRuleOther
   102  }
   103  
   104  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'so'
   105  func (so *so) 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 'so'
   110  func (so *so) 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 (so *so) MonthAbbreviated(month time.Month) string {
   116  	return so.monthsAbbreviated[month]
   117  }
   118  
   119  // MonthsAbbreviated returns the locales abbreviated months
   120  func (so *so) MonthsAbbreviated() []string {
   121  	return so.monthsAbbreviated[1:]
   122  }
   123  
   124  // MonthNarrow returns the locales narrow month given the 'month' provided
   125  func (so *so) MonthNarrow(month time.Month) string {
   126  	return so.monthsNarrow[month]
   127  }
   128  
   129  // MonthsNarrow returns the locales narrow months
   130  func (so *so) MonthsNarrow() []string {
   131  	return so.monthsNarrow[1:]
   132  }
   133  
   134  // MonthWide returns the locales wide month given the 'month' provided
   135  func (so *so) MonthWide(month time.Month) string {
   136  	return so.monthsWide[month]
   137  }
   138  
   139  // MonthsWide returns the locales wide months
   140  func (so *so) MonthsWide() []string {
   141  	return so.monthsWide[1:]
   142  }
   143  
   144  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   145  func (so *so) WeekdayAbbreviated(weekday time.Weekday) string {
   146  	return so.daysAbbreviated[weekday]
   147  }
   148  
   149  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   150  func (so *so) WeekdaysAbbreviated() []string {
   151  	return so.daysAbbreviated
   152  }
   153  
   154  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   155  func (so *so) WeekdayNarrow(weekday time.Weekday) string {
   156  	return so.daysNarrow[weekday]
   157  }
   158  
   159  // WeekdaysNarrow returns the locales narrow weekdays
   160  func (so *so) WeekdaysNarrow() []string {
   161  	return so.daysNarrow
   162  }
   163  
   164  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   165  func (so *so) WeekdayShort(weekday time.Weekday) string {
   166  	return so.daysShort[weekday]
   167  }
   168  
   169  // WeekdaysShort returns the locales short weekdays
   170  func (so *so) WeekdaysShort() []string {
   171  	return so.daysShort
   172  }
   173  
   174  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   175  func (so *so) WeekdayWide(weekday time.Weekday) string {
   176  	return so.daysWide[weekday]
   177  }
   178  
   179  // WeekdaysWide returns the locales wide weekdays
   180  func (so *so) WeekdaysWide() []string {
   181  	return so.daysWide
   182  }
   183  
   184  // Decimal returns the decimal point of number
   185  func (so *so) Decimal() string {
   186  	return so.decimal
   187  }
   188  
   189  // Group returns the group of number
   190  func (so *so) Group() string {
   191  	return so.group
   192  }
   193  
   194  // Group returns the minus sign of number
   195  func (so *so) Minus() string {
   196  	return so.minus
   197  }
   198  
   199  // FmtNumber returns 'num' with digits/precision of 'v' for 'so' and handles both Whole and Real numbers based on 'v'
   200  func (so *so) FmtNumber(num float64, v uint64) string {
   201  
   202  	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   203  }
   204  
   205  // FmtPercent returns 'num' with digits/precision of 'v' for 'so' and handles both Whole and Real numbers based on 'v'
   206  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   207  func (so *so) FmtPercent(num float64, v uint64) string {
   208  	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   209  }
   210  
   211  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'so'
   212  func (so *so) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   213  
   214  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   215  	symbol := so.currencies[currency]
   216  	l := len(s) + len(symbol) + 0
   217  	count := 0
   218  	inWhole := v == 0
   219  	b := make([]byte, 0, l)
   220  
   221  	for i := len(s) - 1; i >= 0; i-- {
   222  
   223  		if s[i] == '.' {
   224  			b = append(b, so.decimal[0])
   225  			inWhole = true
   226  			continue
   227  		}
   228  
   229  		if inWhole {
   230  			if count == 3 {
   231  				b = append(b, so.group[0])
   232  				count = 1
   233  			} else {
   234  				count++
   235  			}
   236  		}
   237  
   238  		b = append(b, s[i])
   239  	}
   240  
   241  	for j := len(symbol) - 1; j >= 0; j-- {
   242  		b = append(b, symbol[j])
   243  	}
   244  
   245  	if num < 0 {
   246  		b = append(b, so.minus[0])
   247  	}
   248  
   249  	// reverse
   250  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   251  		b[i], b[j] = b[j], b[i]
   252  	}
   253  
   254  	if int(v) < 2 {
   255  
   256  		if v == 0 {
   257  			b = append(b, so.decimal...)
   258  		}
   259  
   260  		for i := 0; i < 2-int(v); i++ {
   261  			b = append(b, '0')
   262  		}
   263  	}
   264  
   265  	return string(b)
   266  }
   267  
   268  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'so'
   269  // in accounting notation.
   270  func (so *so) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   271  
   272  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   273  	symbol := so.currencies[currency]
   274  	l := len(s) + len(symbol) + 2
   275  	count := 0
   276  	inWhole := v == 0
   277  	b := make([]byte, 0, l)
   278  
   279  	for i := len(s) - 1; i >= 0; i-- {
   280  
   281  		if s[i] == '.' {
   282  			b = append(b, so.decimal[0])
   283  			inWhole = true
   284  			continue
   285  		}
   286  
   287  		if inWhole {
   288  			if count == 3 {
   289  				b = append(b, so.group[0])
   290  				count = 1
   291  			} else {
   292  				count++
   293  			}
   294  		}
   295  
   296  		b = append(b, s[i])
   297  	}
   298  
   299  	if num < 0 {
   300  
   301  		for j := len(symbol) - 1; j >= 0; j-- {
   302  			b = append(b, symbol[j])
   303  		}
   304  
   305  		b = append(b, so.currencyNegativePrefix[0])
   306  
   307  	} else {
   308  
   309  		for j := len(symbol) - 1; j >= 0; j-- {
   310  			b = append(b, symbol[j])
   311  		}
   312  
   313  	}
   314  
   315  	// reverse
   316  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   317  		b[i], b[j] = b[j], b[i]
   318  	}
   319  
   320  	if int(v) < 2 {
   321  
   322  		if v == 0 {
   323  			b = append(b, so.decimal...)
   324  		}
   325  
   326  		for i := 0; i < 2-int(v); i++ {
   327  			b = append(b, '0')
   328  		}
   329  	}
   330  
   331  	if num < 0 {
   332  		b = append(b, so.currencyNegativeSuffix...)
   333  	}
   334  
   335  	return string(b)
   336  }
   337  
   338  // FmtDateShort returns the short date representation of 't' for 'so'
   339  func (so *so) FmtDateShort(t time.Time) string {
   340  
   341  	b := make([]byte, 0, 32)
   342  
   343  	if t.Day() < 10 {
   344  		b = append(b, '0')
   345  	}
   346  
   347  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   348  	b = append(b, []byte{0x2f}...)
   349  
   350  	if t.Month() < 10 {
   351  		b = append(b, '0')
   352  	}
   353  
   354  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   355  
   356  	b = append(b, []byte{0x2f}...)
   357  
   358  	if t.Year() > 9 {
   359  		b = append(b, strconv.Itoa(t.Year())[2:]...)
   360  	} else {
   361  		b = append(b, strconv.Itoa(t.Year())[1:]...)
   362  	}
   363  
   364  	return string(b)
   365  }
   366  
   367  // FmtDateMedium returns the medium date representation of 't' for 'so'
   368  func (so *so) FmtDateMedium(t time.Time) string {
   369  
   370  	b := make([]byte, 0, 32)
   371  
   372  	if t.Day() < 10 {
   373  		b = append(b, '0')
   374  	}
   375  
   376  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   377  	b = append(b, []byte{0x2d}...)
   378  	b = append(b, so.monthsAbbreviated[t.Month()]...)
   379  	b = append(b, []byte{0x2d}...)
   380  
   381  	if t.Year() > 0 {
   382  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   383  	} else {
   384  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   385  	}
   386  
   387  	return string(b)
   388  }
   389  
   390  // FmtDateLong returns the long date representation of 't' for 'so'
   391  func (so *so) FmtDateLong(t time.Time) string {
   392  
   393  	b := make([]byte, 0, 32)
   394  
   395  	if t.Day() < 10 {
   396  		b = append(b, '0')
   397  	}
   398  
   399  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   400  	b = append(b, []byte{0x20}...)
   401  	b = append(b, so.monthsWide[t.Month()]...)
   402  	b = append(b, []byte{0x20}...)
   403  
   404  	if t.Year() > 0 {
   405  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   406  	} else {
   407  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   408  	}
   409  
   410  	return string(b)
   411  }
   412  
   413  // FmtDateFull returns the full date representation of 't' for 'so'
   414  func (so *so) FmtDateFull(t time.Time) string {
   415  
   416  	b := make([]byte, 0, 32)
   417  
   418  	b = append(b, so.daysWide[t.Weekday()]...)
   419  	b = append(b, []byte{0x2c, 0x20}...)
   420  	b = append(b, so.monthsWide[t.Month()]...)
   421  	b = append(b, []byte{0x20}...)
   422  
   423  	if t.Day() < 10 {
   424  		b = append(b, '0')
   425  	}
   426  
   427  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   428  	b = append(b, []byte{0x2c, 0x20}...)
   429  
   430  	if t.Year() > 0 {
   431  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   432  	} else {
   433  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   434  	}
   435  
   436  	return string(b)
   437  }
   438  
   439  // FmtTimeShort returns the short time representation of 't' for 'so'
   440  func (so *so) FmtTimeShort(t time.Time) string {
   441  
   442  	b := make([]byte, 0, 32)
   443  
   444  	h := t.Hour()
   445  
   446  	if h > 12 {
   447  		h -= 12
   448  	}
   449  
   450  	b = strconv.AppendInt(b, int64(h), 10)
   451  	b = append(b, so.timeSeparator...)
   452  
   453  	if t.Minute() < 10 {
   454  		b = append(b, '0')
   455  	}
   456  
   457  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   458  	b = append(b, []byte{0x20}...)
   459  
   460  	if t.Hour() < 12 {
   461  		b = append(b, so.periodsAbbreviated[0]...)
   462  	} else {
   463  		b = append(b, so.periodsAbbreviated[1]...)
   464  	}
   465  
   466  	return string(b)
   467  }
   468  
   469  // FmtTimeMedium returns the medium time representation of 't' for 'so'
   470  func (so *so) FmtTimeMedium(t time.Time) string {
   471  
   472  	b := make([]byte, 0, 32)
   473  
   474  	h := t.Hour()
   475  
   476  	if h > 12 {
   477  		h -= 12
   478  	}
   479  
   480  	b = strconv.AppendInt(b, int64(h), 10)
   481  	b = append(b, so.timeSeparator...)
   482  
   483  	if t.Minute() < 10 {
   484  		b = append(b, '0')
   485  	}
   486  
   487  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   488  	b = append(b, so.timeSeparator...)
   489  
   490  	if t.Second() < 10 {
   491  		b = append(b, '0')
   492  	}
   493  
   494  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   495  	b = append(b, []byte{0x20}...)
   496  
   497  	if t.Hour() < 12 {
   498  		b = append(b, so.periodsAbbreviated[0]...)
   499  	} else {
   500  		b = append(b, so.periodsAbbreviated[1]...)
   501  	}
   502  
   503  	return string(b)
   504  }
   505  
   506  // FmtTimeLong returns the long time representation of 't' for 'so'
   507  func (so *so) FmtTimeLong(t time.Time) string {
   508  
   509  	b := make([]byte, 0, 32)
   510  
   511  	h := t.Hour()
   512  
   513  	if h > 12 {
   514  		h -= 12
   515  	}
   516  
   517  	b = strconv.AppendInt(b, int64(h), 10)
   518  	b = append(b, so.timeSeparator...)
   519  
   520  	if t.Minute() < 10 {
   521  		b = append(b, '0')
   522  	}
   523  
   524  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   525  	b = append(b, so.timeSeparator...)
   526  
   527  	if t.Second() < 10 {
   528  		b = append(b, '0')
   529  	}
   530  
   531  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   532  	b = append(b, []byte{0x20}...)
   533  
   534  	if t.Hour() < 12 {
   535  		b = append(b, so.periodsAbbreviated[0]...)
   536  	} else {
   537  		b = append(b, so.periodsAbbreviated[1]...)
   538  	}
   539  
   540  	b = append(b, []byte{0x20}...)
   541  
   542  	tz, _ := t.Zone()
   543  	b = append(b, tz...)
   544  
   545  	return string(b)
   546  }
   547  
   548  // FmtTimeFull returns the full time representation of 't' for 'so'
   549  func (so *so) FmtTimeFull(t time.Time) string {
   550  
   551  	b := make([]byte, 0, 32)
   552  
   553  	h := t.Hour()
   554  
   555  	if h > 12 {
   556  		h -= 12
   557  	}
   558  
   559  	b = strconv.AppendInt(b, int64(h), 10)
   560  	b = append(b, so.timeSeparator...)
   561  
   562  	if t.Minute() < 10 {
   563  		b = append(b, '0')
   564  	}
   565  
   566  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   567  	b = append(b, so.timeSeparator...)
   568  
   569  	if t.Second() < 10 {
   570  		b = append(b, '0')
   571  	}
   572  
   573  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   574  	b = append(b, []byte{0x20}...)
   575  
   576  	if t.Hour() < 12 {
   577  		b = append(b, so.periodsAbbreviated[0]...)
   578  	} else {
   579  		b = append(b, so.periodsAbbreviated[1]...)
   580  	}
   581  
   582  	b = append(b, []byte{0x20}...)
   583  
   584  	tz, _ := t.Zone()
   585  
   586  	if btz, ok := so.timezones[tz]; ok {
   587  		b = append(b, btz...)
   588  	} else {
   589  		b = append(b, tz...)
   590  	}
   591  
   592  	return string(b)
   593  }
   594  

View as plain text