...

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

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

     1  package nl
     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 nl 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  	percentSuffix          string
    22  	perMille               string
    23  	timeSeparator          string
    24  	inifinity              string
    25  	currencies             []string // idx = enum of currency code
    26  	currencyPositiveSuffix 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 'nl' locale
    46  func New() locales.Translator {
    47  	return &nl{
    48  		locale:                 "nl",
    49  		pluralsCardinal:        []locales.PluralRule{2, 6},
    50  		pluralsOrdinal:         []locales.PluralRule{6},
    51  		pluralsRange:           []locales.PluralRule{2, 6},
    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  		percentSuffix:          " ",
    61  		currencyPositiveSuffix: " ",
    62  		currencyNegativeSuffix: " ",
    63  		monthsAbbreviated:      []string{"", "jan.", "feb.", "mrt.", "apr.", "mei", "jun.", "jul.", "aug.", "sep.", "okt.", "nov.", "dec."},
    64  		monthsNarrow:           []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
    65  		monthsWide:             []string{"", "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"},
    66  		daysAbbreviated:        []string{"zo", "ma", "di", "wo", "do", "vr", "za"},
    67  		daysNarrow:             []string{"Z", "M", "D", "W", "D", "V", "Z"},
    68  		daysShort:              []string{"zo", "ma", "di", "wo", "do", "vr", "za"},
    69  		daysWide:               []string{"zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"},
    70  		periodsAbbreviated:     []string{"a.m.", "p.m."},
    71  		periodsNarrow:          []string{"a.m.", "p.m."},
    72  		periodsWide:            []string{"a.m.", "p.m."},
    73  		erasAbbreviated:        []string{"v.Chr.", "n.Chr."},
    74  		erasNarrow:             []string{"v.C.", "n.C."},
    75  		erasWide:               []string{"voor Christus", "na Christus"},
    76  		timezones:              map[string]string{"ACDT": "Midden-Australische zomertijd", "ACST": "Midden-Australische standaardtijd", "ACWDT": "Midden-Australische westelijke zomertijd", "ACWST": "Midden-Australische westelijke standaardtijd", "ADT": "Atlantic-zomertijd", "AEDT": "Oost-Australische zomertijd", "AEST": "Oost-Australische standaardtijd", "AKDT": "Alaska-zomertijd", "AKST": "Alaska-standaardtijd", "ARST": "Argentijnse zomertijd", "ART": "Argentijnse standaardtijd", "AST": "Atlantic-standaardtijd", "AWDT": "West-Australische zomertijd", "AWST": "West-Australische standaardtijd", "BOT": "Boliviaanse tijd", "BT": "Bhutaanse tijd", "CAT": "Centraal-Afrikaanse tijd", "CDT": "Central-zomertijd", "CHADT": "Chatham-zomertijd", "CHAST": "Chatham-standaardtijd", "CLST": "Chileense zomertijd", "CLT": "Chileense standaardtijd", "COST": "Colombiaanse zomertijd", "COT": "Colombiaanse standaardtijd", "CST": "Central-standaardtijd", "ChST": "Chamorro-tijd", "EAT": "Oost-Afrikaanse tijd", "ECT": "Ecuadoraanse tijd", "EDT": "Eastern-zomertijd", "EST": "Eastern-standaardtijd", "GFT": "Frans-Guyaanse tijd", "GMT": "Greenwich Mean Time", "GST": "Golf-standaardtijd", "GYT": "Guyaanse tijd", "HADT": "Hawaii-Aleoetische zomertijd", "HAST": "Hawaii-Aleoetische standaardtijd", "HAT": "Newfoundland-zomertijd", "HECU": "Cubaanse zomertijd", "HEEG": "Oost-Groenlandse zomertijd", "HENOMX": "Noordwest-Mexicaanse zomertijd", "HEOG": "West-Groenlandse zomertijd", "HEPM": "Saint Pierre en Miquelon-zomertijd", "HEPMX": "Mexicaanse Pacific-zomertijd", "HKST": "Hongkongse zomertijd", "HKT": "Hongkongse standaardtijd", "HNCU": "Cubaanse standaardtijd", "HNEG": "Oost-Groenlandse standaardtijd", "HNNOMX": "Noordwest-Mexicaanse standaardtijd", "HNOG": "West-Groenlandse standaardtijd", "HNPM": "Saint Pierre en Miquelon-standaardtijd", "HNPMX": "Mexicaanse Pacific-standaardtijd", "HNT": "Newfoundland-standaardtijd", "IST": "Indiase tijd", "JDT": "Japanse zomertijd", "JST": "Japanse standaardtijd", "LHDT": "Lord Howe-eilandse zomertijd", "LHST": "Lord Howe-eilandse standaardtijd", "MDT": "Mountain-zomertijd", "MESZ": "Midden-Europese zomertijd", "MEZ": "Midden-Europese standaardtijd", "MST": "Mountain-standaardtijd", "MYT": "Maleisische tijd", "NZDT": "Nieuw-Zeelandse zomertijd", "NZST": "Nieuw-Zeelandse standaardtijd", "OESZ": "Oost-Europese zomertijd", "OEZ": "Oost-Europese standaardtijd", "PDT": "Pacific-zomertijd", "PST": "Pacific-standaardtijd", "SAST": "Zuid-Afrikaanse tijd", "SGT": "Singaporese standaardtijd", "SRT": "Surinaamse tijd", "TMST": "Turkmeense zomertijd", "TMT": "Turkmeense standaardtijd", "UYST": "Uruguayaanse zomertijd", "UYT": "Uruguayaanse standaardtijd", "VET": "Venezolaanse tijd", "WARST": "West-Argentijnse zomertijd", "WART": "West-Argentijnse standaardtijd", "WAST": "West-Afrikaanse zomertijd", "WAT": "West-Afrikaanse standaardtijd", "WESZ": "West-Europese zomertijd", "WEZ": "West-Europese standaardtijd", "WIB": "West-Indonesische tijd", "WIT": "Oost-Indonesische tijd", "WITA": "Centraal-Indonesische tijd", "∅∅∅": "Braziliaanse zomertijd"},
    77  	}
    78  }
    79  
    80  // Locale returns the current translators string locale
    81  func (nl *nl) Locale() string {
    82  	return nl.locale
    83  }
    84  
    85  // PluralsCardinal returns the list of cardinal plural rules associated with 'nl'
    86  func (nl *nl) PluralsCardinal() []locales.PluralRule {
    87  	return nl.pluralsCardinal
    88  }
    89  
    90  // PluralsOrdinal returns the list of ordinal plural rules associated with 'nl'
    91  func (nl *nl) PluralsOrdinal() []locales.PluralRule {
    92  	return nl.pluralsOrdinal
    93  }
    94  
    95  // PluralsRange returns the list of range plural rules associated with 'nl'
    96  func (nl *nl) PluralsRange() []locales.PluralRule {
    97  	return nl.pluralsRange
    98  }
    99  
   100  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'nl'
   101  func (nl *nl) 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 'nl'
   114  func (nl *nl) 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 'nl'
   119  func (nl *nl) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   120  
   121  	start := nl.CardinalPluralRule(num1, v1)
   122  	end := nl.CardinalPluralRule(num2, v2)
   123  
   124  	if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
   125  		return locales.PluralRuleOther
   126  	} else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
   127  		return locales.PluralRuleOne
   128  	}
   129  
   130  	return locales.PluralRuleOther
   131  
   132  }
   133  
   134  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   135  func (nl *nl) MonthAbbreviated(month time.Month) string {
   136  	return nl.monthsAbbreviated[month]
   137  }
   138  
   139  // MonthsAbbreviated returns the locales abbreviated months
   140  func (nl *nl) MonthsAbbreviated() []string {
   141  	return nl.monthsAbbreviated[1:]
   142  }
   143  
   144  // MonthNarrow returns the locales narrow month given the 'month' provided
   145  func (nl *nl) MonthNarrow(month time.Month) string {
   146  	return nl.monthsNarrow[month]
   147  }
   148  
   149  // MonthsNarrow returns the locales narrow months
   150  func (nl *nl) MonthsNarrow() []string {
   151  	return nl.monthsNarrow[1:]
   152  }
   153  
   154  // MonthWide returns the locales wide month given the 'month' provided
   155  func (nl *nl) MonthWide(month time.Month) string {
   156  	return nl.monthsWide[month]
   157  }
   158  
   159  // MonthsWide returns the locales wide months
   160  func (nl *nl) MonthsWide() []string {
   161  	return nl.monthsWide[1:]
   162  }
   163  
   164  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   165  func (nl *nl) WeekdayAbbreviated(weekday time.Weekday) string {
   166  	return nl.daysAbbreviated[weekday]
   167  }
   168  
   169  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   170  func (nl *nl) WeekdaysAbbreviated() []string {
   171  	return nl.daysAbbreviated
   172  }
   173  
   174  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   175  func (nl *nl) WeekdayNarrow(weekday time.Weekday) string {
   176  	return nl.daysNarrow[weekday]
   177  }
   178  
   179  // WeekdaysNarrow returns the locales narrow weekdays
   180  func (nl *nl) WeekdaysNarrow() []string {
   181  	return nl.daysNarrow
   182  }
   183  
   184  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   185  func (nl *nl) WeekdayShort(weekday time.Weekday) string {
   186  	return nl.daysShort[weekday]
   187  }
   188  
   189  // WeekdaysShort returns the locales short weekdays
   190  func (nl *nl) WeekdaysShort() []string {
   191  	return nl.daysShort
   192  }
   193  
   194  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   195  func (nl *nl) WeekdayWide(weekday time.Weekday) string {
   196  	return nl.daysWide[weekday]
   197  }
   198  
   199  // WeekdaysWide returns the locales wide weekdays
   200  func (nl *nl) WeekdaysWide() []string {
   201  	return nl.daysWide
   202  }
   203  
   204  // Decimal returns the decimal point of number
   205  func (nl *nl) Decimal() string {
   206  	return nl.decimal
   207  }
   208  
   209  // Group returns the group of number
   210  func (nl *nl) Group() string {
   211  	return nl.group
   212  }
   213  
   214  // Group returns the minus sign of number
   215  func (nl *nl) Minus() string {
   216  	return nl.minus
   217  }
   218  
   219  // FmtNumber returns 'num' with digits/precision of 'v' for 'nl' and handles both Whole and Real numbers based on 'v'
   220  func (nl *nl) FmtNumber(num float64, v uint64) string {
   221  
   222  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   223  	l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
   224  	count := 0
   225  	inWhole := v == 0
   226  	b := make([]byte, 0, l)
   227  
   228  	for i := len(s) - 1; i >= 0; i-- {
   229  
   230  		if s[i] == '.' {
   231  			b = append(b, nl.decimal[0])
   232  			inWhole = true
   233  			continue
   234  		}
   235  
   236  		if inWhole {
   237  			if count == 3 {
   238  				b = append(b, nl.group[0])
   239  				count = 1
   240  			} else {
   241  				count++
   242  			}
   243  		}
   244  
   245  		b = append(b, s[i])
   246  	}
   247  
   248  	if num < 0 {
   249  		b = append(b, nl.minus[0])
   250  	}
   251  
   252  	// reverse
   253  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   254  		b[i], b[j] = b[j], b[i]
   255  	}
   256  
   257  	return string(b)
   258  }
   259  
   260  // FmtPercent returns 'num' with digits/precision of 'v' for 'nl' and handles both Whole and Real numbers based on 'v'
   261  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   262  func (nl *nl) FmtPercent(num float64, v uint64) string {
   263  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   264  	l := len(s) + 5
   265  	b := make([]byte, 0, l)
   266  
   267  	for i := len(s) - 1; i >= 0; i-- {
   268  
   269  		if s[i] == '.' {
   270  			b = append(b, nl.decimal[0])
   271  			continue
   272  		}
   273  
   274  		b = append(b, s[i])
   275  	}
   276  
   277  	if num < 0 {
   278  		b = append(b, nl.minus[0])
   279  	}
   280  
   281  	// reverse
   282  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   283  		b[i], b[j] = b[j], b[i]
   284  	}
   285  
   286  	b = append(b, nl.percentSuffix...)
   287  
   288  	b = append(b, nl.percent...)
   289  
   290  	return string(b)
   291  }
   292  
   293  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'nl'
   294  func (nl *nl) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   295  
   296  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   297  	symbol := nl.currencies[currency]
   298  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   299  	count := 0
   300  	inWhole := v == 0
   301  	b := make([]byte, 0, l)
   302  
   303  	for i := len(s) - 1; i >= 0; i-- {
   304  
   305  		if s[i] == '.' {
   306  			b = append(b, nl.decimal[0])
   307  			inWhole = true
   308  			continue
   309  		}
   310  
   311  		if inWhole {
   312  			if count == 3 {
   313  				b = append(b, nl.group[0])
   314  				count = 1
   315  			} else {
   316  				count++
   317  			}
   318  		}
   319  
   320  		b = append(b, s[i])
   321  	}
   322  
   323  	if num < 0 {
   324  		b = append(b, nl.minus[0])
   325  	}
   326  
   327  	// reverse
   328  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   329  		b[i], b[j] = b[j], b[i]
   330  	}
   331  
   332  	if int(v) < 2 {
   333  
   334  		if v == 0 {
   335  			b = append(b, nl.decimal...)
   336  		}
   337  
   338  		for i := 0; i < 2-int(v); i++ {
   339  			b = append(b, '0')
   340  		}
   341  	}
   342  
   343  	b = append(b, nl.currencyPositiveSuffix...)
   344  
   345  	b = append(b, symbol...)
   346  
   347  	return string(b)
   348  }
   349  
   350  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'nl'
   351  // in accounting notation.
   352  func (nl *nl) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   353  
   354  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   355  	symbol := nl.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, nl.decimal[0])
   365  			inWhole = true
   366  			continue
   367  		}
   368  
   369  		if inWhole {
   370  			if count == 3 {
   371  				b = append(b, nl.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  		b = append(b, nl.minus[0])
   384  
   385  	}
   386  
   387  	// reverse
   388  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   389  		b[i], b[j] = b[j], b[i]
   390  	}
   391  
   392  	if int(v) < 2 {
   393  
   394  		if v == 0 {
   395  			b = append(b, nl.decimal...)
   396  		}
   397  
   398  		for i := 0; i < 2-int(v); i++ {
   399  			b = append(b, '0')
   400  		}
   401  	}
   402  
   403  	if num < 0 {
   404  		b = append(b, nl.currencyNegativeSuffix...)
   405  		b = append(b, symbol...)
   406  	} else {
   407  
   408  		b = append(b, nl.currencyPositiveSuffix...)
   409  		b = append(b, symbol...)
   410  	}
   411  
   412  	return string(b)
   413  }
   414  
   415  // FmtDateShort returns the short date representation of 't' for 'nl'
   416  func (nl *nl) FmtDateShort(t time.Time) string {
   417  
   418  	b := make([]byte, 0, 32)
   419  
   420  	if t.Day() < 10 {
   421  		b = append(b, '0')
   422  	}
   423  
   424  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   425  	b = append(b, []byte{0x2d}...)
   426  
   427  	if t.Month() < 10 {
   428  		b = append(b, '0')
   429  	}
   430  
   431  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   432  
   433  	b = append(b, []byte{0x2d}...)
   434  
   435  	if t.Year() > 0 {
   436  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   437  	} else {
   438  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   439  	}
   440  
   441  	return string(b)
   442  }
   443  
   444  // FmtDateMedium returns the medium date representation of 't' for 'nl'
   445  func (nl *nl) FmtDateMedium(t time.Time) string {
   446  
   447  	b := make([]byte, 0, 32)
   448  
   449  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   450  	b = append(b, []byte{0x20}...)
   451  	b = append(b, nl.monthsAbbreviated[t.Month()]...)
   452  	b = append(b, []byte{0x20}...)
   453  
   454  	if t.Year() > 0 {
   455  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   456  	} else {
   457  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   458  	}
   459  
   460  	return string(b)
   461  }
   462  
   463  // FmtDateLong returns the long date representation of 't' for 'nl'
   464  func (nl *nl) FmtDateLong(t time.Time) string {
   465  
   466  	b := make([]byte, 0, 32)
   467  
   468  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   469  	b = append(b, []byte{0x20}...)
   470  	b = append(b, nl.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  // FmtDateFull returns the full date representation of 't' for 'nl'
   483  func (nl *nl) FmtDateFull(t time.Time) string {
   484  
   485  	b := make([]byte, 0, 32)
   486  
   487  	b = append(b, nl.daysWide[t.Weekday()]...)
   488  	b = append(b, []byte{0x20}...)
   489  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   490  	b = append(b, []byte{0x20}...)
   491  	b = append(b, nl.monthsWide[t.Month()]...)
   492  	b = append(b, []byte{0x20}...)
   493  
   494  	if t.Year() > 0 {
   495  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   496  	} else {
   497  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   498  	}
   499  
   500  	return string(b)
   501  }
   502  
   503  // FmtTimeShort returns the short time representation of 't' for 'nl'
   504  func (nl *nl) FmtTimeShort(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, nl.timeSeparator...)
   514  
   515  	if t.Minute() < 10 {
   516  		b = append(b, '0')
   517  	}
   518  
   519  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   520  
   521  	return string(b)
   522  }
   523  
   524  // FmtTimeMedium returns the medium time representation of 't' for 'nl'
   525  func (nl *nl) FmtTimeMedium(t time.Time) string {
   526  
   527  	b := make([]byte, 0, 32)
   528  
   529  	if t.Hour() < 10 {
   530  		b = append(b, '0')
   531  	}
   532  
   533  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   534  	b = append(b, nl.timeSeparator...)
   535  
   536  	if t.Minute() < 10 {
   537  		b = append(b, '0')
   538  	}
   539  
   540  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   541  	b = append(b, nl.timeSeparator...)
   542  
   543  	if t.Second() < 10 {
   544  		b = append(b, '0')
   545  	}
   546  
   547  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   548  
   549  	return string(b)
   550  }
   551  
   552  // FmtTimeLong returns the long time representation of 't' for 'nl'
   553  func (nl *nl) FmtTimeLong(t time.Time) string {
   554  
   555  	b := make([]byte, 0, 32)
   556  
   557  	if t.Hour() < 10 {
   558  		b = append(b, '0')
   559  	}
   560  
   561  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   562  	b = append(b, nl.timeSeparator...)
   563  
   564  	if t.Minute() < 10 {
   565  		b = append(b, '0')
   566  	}
   567  
   568  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   569  	b = append(b, nl.timeSeparator...)
   570  
   571  	if t.Second() < 10 {
   572  		b = append(b, '0')
   573  	}
   574  
   575  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   576  	b = append(b, []byte{0x20}...)
   577  
   578  	tz, _ := t.Zone()
   579  	b = append(b, tz...)
   580  
   581  	return string(b)
   582  }
   583  
   584  // FmtTimeFull returns the full time representation of 't' for 'nl'
   585  func (nl *nl) FmtTimeFull(t time.Time) string {
   586  
   587  	b := make([]byte, 0, 32)
   588  
   589  	if t.Hour() < 10 {
   590  		b = append(b, '0')
   591  	}
   592  
   593  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   594  	b = append(b, nl.timeSeparator...)
   595  
   596  	if t.Minute() < 10 {
   597  		b = append(b, '0')
   598  	}
   599  
   600  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   601  	b = append(b, nl.timeSeparator...)
   602  
   603  	if t.Second() < 10 {
   604  		b = append(b, '0')
   605  	}
   606  
   607  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   608  	b = append(b, []byte{0x20}...)
   609  
   610  	tz, _ := t.Zone()
   611  
   612  	if btz, ok := nl.timezones[tz]; ok {
   613  		b = append(b, btz...)
   614  	} else {
   615  		b = append(b, tz...)
   616  	}
   617  
   618  	return string(b)
   619  }
   620  

View as plain text