...

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

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

     1  package id
     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 id 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  	monthsAbbreviated  []string
    26  	monthsNarrow       []string
    27  	monthsWide         []string
    28  	daysAbbreviated    []string
    29  	daysNarrow         []string
    30  	daysShort          []string
    31  	daysWide           []string
    32  	periodsAbbreviated []string
    33  	periodsNarrow      []string
    34  	periodsShort       []string
    35  	periodsWide        []string
    36  	erasAbbreviated    []string
    37  	erasNarrow         []string
    38  	erasWide           []string
    39  	timezones          map[string]string
    40  }
    41  
    42  // New returns a new instance of translator for the 'id' locale
    43  func New() locales.Translator {
    44  	return &id{
    45  		locale:             "id",
    46  		pluralsCardinal:    []locales.PluralRule{6},
    47  		pluralsOrdinal:     []locales.PluralRule{6},
    48  		pluralsRange:       []locales.PluralRule{6},
    49  		decimal:            ",",
    50  		group:              ".",
    51  		minus:              "-",
    52  		percent:            "%",
    53  		perMille:           "‰",
    54  		timeSeparator:      ".",
    55  		inifinity:          "∞",
    56  		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", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "FJD", "FKP", "FRF", "£", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "Rp", "IEP", "ILP", "ILR", "₪", "Rs", "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", "SBD", "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", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
    57  		monthsAbbreviated:  []string{"", "Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des"},
    58  		monthsNarrow:       []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
    59  		monthsWide:         []string{"", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"},
    60  		daysAbbreviated:    []string{"Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"},
    61  		daysNarrow:         []string{"M", "S", "S", "R", "K", "J", "S"},
    62  		daysShort:          []string{"Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"},
    63  		daysWide:           []string{"Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"},
    64  		periodsAbbreviated: []string{"AM", "PM"},
    65  		periodsNarrow:      []string{"AM", "PM"},
    66  		periodsWide:        []string{"AM", "PM"},
    67  		erasAbbreviated:    []string{"SM", "M"},
    68  		erasNarrow:         []string{"SM", "M"},
    69  		erasWide:           []string{"Sebelum Masehi", "Masehi"},
    70  		timezones:          map[string]string{"ACDT": "Waktu Musim Panas Tengah Australia", "ACST": "Waktu Standar Tengah Australia", "ACWDT": "Waktu Musim Panas Barat Tengah Australia", "ACWST": "Waktu Standar Barat Tengah Australia", "ADT": "Waktu Musim Panas Atlantik", "AEDT": "Waktu Musim Panas Timur Australia", "AEST": "Waktu Standar Timur Australia", "AKDT": "Waktu Musim Panas Alaska", "AKST": "Waktu Standar Alaska", "ARST": "Waktu Musim Panas Argentina", "ART": "Waktu Standar Argentina", "AST": "Waktu Standar Atlantik", "AWDT": "Waktu Musim Panas Barat Australia", "AWST": "Waktu Standar Barat Australia", "BOT": "Waktu Bolivia", "BT": "Waktu Bhutan", "CAT": "Waktu Afrika Tengah", "CDT": "Waktu Musim Panas Tengah", "CHADT": "Waktu Musim Panas Chatham", "CHAST": "Waktu Standar Chatham", "CLST": "Waktu Musim Panas Cile", "CLT": "Waktu Standar Cile", "COST": "Waktu Musim Panas Kolombia", "COT": "Waktu Standar Kolombia", "CST": "Waktu Standar Tengah", "ChST": "Waktu Standar Chamorro", "EAT": "Waktu Afrika Timur", "ECT": "Waktu Ekuador", "EDT": "Waktu Musim Panas Timur", "EST": "Waktu Standar Timur", "GFT": "Waktu Guyana Prancis", "GMT": "Greenwich Mean Time", "GST": "Waktu Standar Teluk", "GYT": "Waktu Guyana", "HADT": "Waktu Musim Panas Hawaii-Aleutian", "HAST": "Waktu Standar Hawaii-Aleutian", "HAT": "Waktu Musim Panas Newfoundland", "HECU": "Waktu Musim Panas Kuba", "HEEG": "Waktu Musim Panas Greenland Timur", "HENOMX": "Waktu Musim Panas Meksiko Barat Laut", "HEOG": "Waktu Musim Panas Greenland Barat", "HEPM": "Waktu Musim Panas Saint Pierre dan Miquelon", "HEPMX": "Waktu Musim Panas Pasifik Meksiko", "HKST": "Waktu Musim Panas Hong Kong", "HKT": "Waktu Standar Hong Kong", "HNCU": "Waktu Standar Kuba", "HNEG": "Waktu Standar Greenland Timur", "HNNOMX": "Waktu Standar Meksiko Barat Laut", "HNOG": "Waktu Standar Greenland Barat", "HNPM": "Waktu Standar Saint Pierre dan Miquelon", "HNPMX": "Waktu Standar Pasifik Meksiko", "HNT": "Waktu Standar Newfoundland", "IST": "Waktu India", "JDT": "Waktu Musim Panas Jepang", "JST": "Waktu Standar Jepang", "LHDT": "Waktu Musim Panas Lord Howe", "LHST": "Waktu Standar Lord Howe", "MDT": "Waktu Musim Panas Pegunungan", "MESZ": "Waktu Musim Panas Eropa Tengah", "MEZ": "Waktu Standar Eropa Tengah", "MST": "Waktu Standar Pegunungan", "MYT": "Waktu Malaysia", "NZDT": "Waktu Musim Panas Selandia Baru", "NZST": "Waktu Standar Selandia Baru", "OESZ": "Waktu Musim Panas Eropa Timur", "OEZ": "Waktu Standar Eropa Timur", "PDT": "Waktu Musim Panas Pasifik", "PST": "Waktu Standar Pasifik", "SAST": "Waktu Standar Afrika Selatan", "SGT": "Waktu Standar Singapura", "SRT": "Waktu Suriname", "TMST": "Waktu Musim Panas Turkmenistan", "TMT": "Waktu Standar Turkmenistan", "UYST": "Waktu Musim Panas Uruguay", "UYT": "Waktu Standar Uruguay", "VET": "Waktu Venezuela", "WARST": "Waktu Musim Panas Argentina Bagian Barat", "WART": "Waktu Standar Argentina Bagian Barat", "WAST": "Waktu Musim Panas Afrika Barat", "WAT": "Waktu Standar Afrika Barat", "WESZ": "Waktu Musim Panas Eropa Barat", "WEZ": "Waktu Standar Eropa Barat", "WIB": "Waktu Indonesia Barat", "WIT": "Waktu Indonesia Timur", "WITA": "Waktu Indonesia Tengah", "∅∅∅": "Waktu Musim Panas Brasil"},
    71  	}
    72  }
    73  
    74  // Locale returns the current translators string locale
    75  func (id *id) Locale() string {
    76  	return id.locale
    77  }
    78  
    79  // PluralsCardinal returns the list of cardinal plural rules associated with 'id'
    80  func (id *id) PluralsCardinal() []locales.PluralRule {
    81  	return id.pluralsCardinal
    82  }
    83  
    84  // PluralsOrdinal returns the list of ordinal plural rules associated with 'id'
    85  func (id *id) PluralsOrdinal() []locales.PluralRule {
    86  	return id.pluralsOrdinal
    87  }
    88  
    89  // PluralsRange returns the list of range plural rules associated with 'id'
    90  func (id *id) PluralsRange() []locales.PluralRule {
    91  	return id.pluralsRange
    92  }
    93  
    94  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'id'
    95  func (id *id) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
    96  	return locales.PluralRuleOther
    97  }
    98  
    99  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'id'
   100  func (id *id) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
   101  	return locales.PluralRuleOther
   102  }
   103  
   104  // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'id'
   105  func (id *id) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   106  	return locales.PluralRuleOther
   107  }
   108  
   109  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   110  func (id *id) MonthAbbreviated(month time.Month) string {
   111  	return id.monthsAbbreviated[month]
   112  }
   113  
   114  // MonthsAbbreviated returns the locales abbreviated months
   115  func (id *id) MonthsAbbreviated() []string {
   116  	return id.monthsAbbreviated[1:]
   117  }
   118  
   119  // MonthNarrow returns the locales narrow month given the 'month' provided
   120  func (id *id) MonthNarrow(month time.Month) string {
   121  	return id.monthsNarrow[month]
   122  }
   123  
   124  // MonthsNarrow returns the locales narrow months
   125  func (id *id) MonthsNarrow() []string {
   126  	return id.monthsNarrow[1:]
   127  }
   128  
   129  // MonthWide returns the locales wide month given the 'month' provided
   130  func (id *id) MonthWide(month time.Month) string {
   131  	return id.monthsWide[month]
   132  }
   133  
   134  // MonthsWide returns the locales wide months
   135  func (id *id) MonthsWide() []string {
   136  	return id.monthsWide[1:]
   137  }
   138  
   139  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   140  func (id *id) WeekdayAbbreviated(weekday time.Weekday) string {
   141  	return id.daysAbbreviated[weekday]
   142  }
   143  
   144  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   145  func (id *id) WeekdaysAbbreviated() []string {
   146  	return id.daysAbbreviated
   147  }
   148  
   149  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   150  func (id *id) WeekdayNarrow(weekday time.Weekday) string {
   151  	return id.daysNarrow[weekday]
   152  }
   153  
   154  // WeekdaysNarrow returns the locales narrow weekdays
   155  func (id *id) WeekdaysNarrow() []string {
   156  	return id.daysNarrow
   157  }
   158  
   159  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   160  func (id *id) WeekdayShort(weekday time.Weekday) string {
   161  	return id.daysShort[weekday]
   162  }
   163  
   164  // WeekdaysShort returns the locales short weekdays
   165  func (id *id) WeekdaysShort() []string {
   166  	return id.daysShort
   167  }
   168  
   169  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   170  func (id *id) WeekdayWide(weekday time.Weekday) string {
   171  	return id.daysWide[weekday]
   172  }
   173  
   174  // WeekdaysWide returns the locales wide weekdays
   175  func (id *id) WeekdaysWide() []string {
   176  	return id.daysWide
   177  }
   178  
   179  // Decimal returns the decimal point of number
   180  func (id *id) Decimal() string {
   181  	return id.decimal
   182  }
   183  
   184  // Group returns the group of number
   185  func (id *id) Group() string {
   186  	return id.group
   187  }
   188  
   189  // Group returns the minus sign of number
   190  func (id *id) Minus() string {
   191  	return id.minus
   192  }
   193  
   194  // FmtNumber returns 'num' with digits/precision of 'v' for 'id' and handles both Whole and Real numbers based on 'v'
   195  func (id *id) FmtNumber(num float64, v uint64) string {
   196  
   197  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   198  	l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
   199  	count := 0
   200  	inWhole := v == 0
   201  	b := make([]byte, 0, l)
   202  
   203  	for i := len(s) - 1; i >= 0; i-- {
   204  
   205  		if s[i] == '.' {
   206  			b = append(b, id.decimal[0])
   207  			inWhole = true
   208  			continue
   209  		}
   210  
   211  		if inWhole {
   212  			if count == 3 {
   213  				b = append(b, id.group[0])
   214  				count = 1
   215  			} else {
   216  				count++
   217  			}
   218  		}
   219  
   220  		b = append(b, s[i])
   221  	}
   222  
   223  	if num < 0 {
   224  		b = append(b, id.minus[0])
   225  	}
   226  
   227  	// reverse
   228  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   229  		b[i], b[j] = b[j], b[i]
   230  	}
   231  
   232  	return string(b)
   233  }
   234  
   235  // FmtPercent returns 'num' with digits/precision of 'v' for 'id' and handles both Whole and Real numbers based on 'v'
   236  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   237  func (id *id) FmtPercent(num float64, v uint64) string {
   238  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   239  	l := len(s) + 3
   240  	b := make([]byte, 0, l)
   241  
   242  	for i := len(s) - 1; i >= 0; i-- {
   243  
   244  		if s[i] == '.' {
   245  			b = append(b, id.decimal[0])
   246  			continue
   247  		}
   248  
   249  		b = append(b, s[i])
   250  	}
   251  
   252  	if num < 0 {
   253  		b = append(b, id.minus[0])
   254  	}
   255  
   256  	// reverse
   257  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   258  		b[i], b[j] = b[j], b[i]
   259  	}
   260  
   261  	b = append(b, id.percent...)
   262  
   263  	return string(b)
   264  }
   265  
   266  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'id'
   267  func (id *id) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   268  
   269  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   270  	symbol := id.currencies[currency]
   271  	l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
   272  	count := 0
   273  	inWhole := v == 0
   274  	b := make([]byte, 0, l)
   275  
   276  	for i := len(s) - 1; i >= 0; i-- {
   277  
   278  		if s[i] == '.' {
   279  			b = append(b, id.decimal[0])
   280  			inWhole = true
   281  			continue
   282  		}
   283  
   284  		if inWhole {
   285  			if count == 3 {
   286  				b = append(b, id.group[0])
   287  				count = 1
   288  			} else {
   289  				count++
   290  			}
   291  		}
   292  
   293  		b = append(b, s[i])
   294  	}
   295  
   296  	for j := len(symbol) - 1; j >= 0; j-- {
   297  		b = append(b, symbol[j])
   298  	}
   299  
   300  	if num < 0 {
   301  		b = append(b, id.minus[0])
   302  	}
   303  
   304  	// reverse
   305  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   306  		b[i], b[j] = b[j], b[i]
   307  	}
   308  
   309  	if int(v) < 2 {
   310  
   311  		if v == 0 {
   312  			b = append(b, id.decimal...)
   313  		}
   314  
   315  		for i := 0; i < 2-int(v); i++ {
   316  			b = append(b, '0')
   317  		}
   318  	}
   319  
   320  	return string(b)
   321  }
   322  
   323  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'id'
   324  // in accounting notation.
   325  func (id *id) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   326  
   327  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   328  	symbol := id.currencies[currency]
   329  	l := len(s) + len(symbol) + 2 + 1*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, id.decimal[0])
   338  			inWhole = true
   339  			continue
   340  		}
   341  
   342  		if inWhole {
   343  			if count == 3 {
   344  				b = append(b, id.group[0])
   345  				count = 1
   346  			} else {
   347  				count++
   348  			}
   349  		}
   350  
   351  		b = append(b, s[i])
   352  	}
   353  
   354  	if num < 0 {
   355  
   356  		for j := len(symbol) - 1; j >= 0; j-- {
   357  			b = append(b, symbol[j])
   358  		}
   359  
   360  		b = append(b, id.minus[0])
   361  
   362  	} else {
   363  
   364  		for j := len(symbol) - 1; j >= 0; j-- {
   365  			b = append(b, symbol[j])
   366  		}
   367  
   368  	}
   369  
   370  	// reverse
   371  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   372  		b[i], b[j] = b[j], b[i]
   373  	}
   374  
   375  	if int(v) < 2 {
   376  
   377  		if v == 0 {
   378  			b = append(b, id.decimal...)
   379  		}
   380  
   381  		for i := 0; i < 2-int(v); i++ {
   382  			b = append(b, '0')
   383  		}
   384  	}
   385  
   386  	return string(b)
   387  }
   388  
   389  // FmtDateShort returns the short date representation of 't' for 'id'
   390  func (id *id) FmtDateShort(t time.Time) string {
   391  
   392  	b := make([]byte, 0, 32)
   393  
   394  	if t.Day() < 10 {
   395  		b = append(b, '0')
   396  	}
   397  
   398  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   399  	b = append(b, []byte{0x2f}...)
   400  
   401  	if t.Month() < 10 {
   402  		b = append(b, '0')
   403  	}
   404  
   405  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   406  
   407  	b = append(b, []byte{0x2f}...)
   408  
   409  	if t.Year() > 9 {
   410  		b = append(b, strconv.Itoa(t.Year())[2:]...)
   411  	} else {
   412  		b = append(b, strconv.Itoa(t.Year())[1:]...)
   413  	}
   414  
   415  	return string(b)
   416  }
   417  
   418  // FmtDateMedium returns the medium date representation of 't' for 'id'
   419  func (id *id) FmtDateMedium(t time.Time) string {
   420  
   421  	b := make([]byte, 0, 32)
   422  
   423  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   424  	b = append(b, []byte{0x20}...)
   425  	b = append(b, id.monthsAbbreviated[t.Month()]...)
   426  	b = append(b, []byte{0x20}...)
   427  
   428  	if t.Year() > 0 {
   429  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   430  	} else {
   431  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   432  	}
   433  
   434  	return string(b)
   435  }
   436  
   437  // FmtDateLong returns the long date representation of 't' for 'id'
   438  func (id *id) FmtDateLong(t time.Time) string {
   439  
   440  	b := make([]byte, 0, 32)
   441  
   442  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   443  	b = append(b, []byte{0x20}...)
   444  	b = append(b, id.monthsWide[t.Month()]...)
   445  	b = append(b, []byte{0x20}...)
   446  
   447  	if t.Year() > 0 {
   448  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   449  	} else {
   450  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   451  	}
   452  
   453  	return string(b)
   454  }
   455  
   456  // FmtDateFull returns the full date representation of 't' for 'id'
   457  func (id *id) FmtDateFull(t time.Time) string {
   458  
   459  	b := make([]byte, 0, 32)
   460  
   461  	b = append(b, id.daysWide[t.Weekday()]...)
   462  	b = append(b, []byte{0x2c, 0x20}...)
   463  
   464  	if t.Day() < 10 {
   465  		b = append(b, '0')
   466  	}
   467  
   468  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   469  	b = append(b, []byte{0x20}...)
   470  	b = append(b, id.monthsWide[t.Month()]...)
   471  	b = append(b, []byte{0x20}...)
   472  
   473  	if t.Year() > 0 {
   474  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   475  	} else {
   476  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   477  	}
   478  
   479  	return string(b)
   480  }
   481  
   482  // FmtTimeShort returns the short time representation of 't' for 'id'
   483  func (id *id) FmtTimeShort(t time.Time) string {
   484  
   485  	b := make([]byte, 0, 32)
   486  
   487  	if t.Hour() < 10 {
   488  		b = append(b, '0')
   489  	}
   490  
   491  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   492  	b = append(b, []byte{0x2e}...)
   493  
   494  	if t.Minute() < 10 {
   495  		b = append(b, '0')
   496  	}
   497  
   498  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   499  
   500  	return string(b)
   501  }
   502  
   503  // FmtTimeMedium returns the medium time representation of 't' for 'id'
   504  func (id *id) FmtTimeMedium(t time.Time) string {
   505  
   506  	b := make([]byte, 0, 32)
   507  
   508  	if t.Hour() < 10 {
   509  		b = append(b, '0')
   510  	}
   511  
   512  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   513  	b = append(b, []byte{0x2e}...)
   514  
   515  	if t.Minute() < 10 {
   516  		b = append(b, '0')
   517  	}
   518  
   519  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   520  	b = append(b, []byte{0x2e}...)
   521  
   522  	if t.Second() < 10 {
   523  		b = append(b, '0')
   524  	}
   525  
   526  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   527  
   528  	return string(b)
   529  }
   530  
   531  // FmtTimeLong returns the long time representation of 't' for 'id'
   532  func (id *id) FmtTimeLong(t time.Time) string {
   533  
   534  	b := make([]byte, 0, 32)
   535  
   536  	if t.Hour() < 10 {
   537  		b = append(b, '0')
   538  	}
   539  
   540  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   541  	b = append(b, []byte{0x2e}...)
   542  
   543  	if t.Minute() < 10 {
   544  		b = append(b, '0')
   545  	}
   546  
   547  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   548  	b = append(b, []byte{0x2e}...)
   549  
   550  	if t.Second() < 10 {
   551  		b = append(b, '0')
   552  	}
   553  
   554  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   555  	b = append(b, []byte{0x20}...)
   556  
   557  	tz, _ := t.Zone()
   558  	b = append(b, tz...)
   559  
   560  	return string(b)
   561  }
   562  
   563  // FmtTimeFull returns the full time representation of 't' for 'id'
   564  func (id *id) FmtTimeFull(t time.Time) string {
   565  
   566  	b := make([]byte, 0, 32)
   567  
   568  	if t.Hour() < 10 {
   569  		b = append(b, '0')
   570  	}
   571  
   572  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   573  	b = append(b, []byte{0x2e}...)
   574  
   575  	if t.Minute() < 10 {
   576  		b = append(b, '0')
   577  	}
   578  
   579  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   580  	b = append(b, []byte{0x2e}...)
   581  
   582  	if t.Second() < 10 {
   583  		b = append(b, '0')
   584  	}
   585  
   586  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   587  	b = append(b, []byte{0x20}...)
   588  
   589  	tz, _ := t.Zone()
   590  
   591  	if btz, ok := id.timezones[tz]; ok {
   592  		b = append(b, btz...)
   593  	} else {
   594  		b = append(b, tz...)
   595  	}
   596  
   597  	return string(b)
   598  }
   599  

View as plain text