nl.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. package nl
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type nl struct {
  10. locale string
  11. pluralsCardinal []locales.PluralRule
  12. pluralsOrdinal []locales.PluralRule
  13. pluralsRange []locales.PluralRule
  14. decimal string
  15. group string
  16. minus string
  17. percent string
  18. perMille string
  19. timeSeparator string
  20. inifinity string
  21. currencies []string // idx = enum of currency code
  22. currencyPositivePrefix string
  23. currencyNegativePrefix string
  24. currencyNegativeSuffix string
  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. // New returns a new instance of translator for the 'nl' locale
  42. func New() locales.Translator {
  43. return &nl{
  44. locale: "nl",
  45. pluralsCardinal: []locales.PluralRule{2, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: []locales.PluralRule{6, 2},
  48. timeSeparator: ":",
  49. 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", "BYR", "BZD", "C$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "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", "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", "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", "UZS", "VEB", "VEF", "₫", "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"},
  50. currencyPositivePrefix: " ",
  51. currencyNegativePrefix: "( ",
  52. currencyNegativeSuffix: ")",
  53. monthsAbbreviated: []string{"", "jan.", "feb.", "mrt.", "apr.", "mei", "jun.", "jul.", "aug.", "sep.", "okt.", "nov.", "dec."},
  54. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  55. monthsWide: []string{"", "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"},
  56. daysAbbreviated: []string{"zo", "ma", "di", "wo", "do", "vr", "za"},
  57. daysNarrow: []string{"Z", "M", "D", "W", "D", "V", "Z"},
  58. daysShort: []string{"zo", "ma", "di", "wo", "do", "vr", "za"},
  59. daysWide: []string{"zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"},
  60. periodsAbbreviated: []string{"a.m.", "p.m."},
  61. periodsNarrow: []string{"a.m.", "p.m."},
  62. periodsWide: []string{"a.m.", "p.m."},
  63. erasAbbreviated: []string{"v.Chr.", "n.Chr."},
  64. erasNarrow: []string{"v.C.", "n.C."},
  65. erasWide: []string{"voor Christus", "na Christus"},
  66. timezones: map[string]string{"ACWDT": "Midden-Australische westelijke zomertijd", "ACST": "Midden-Australische standaardtijd", "CST": "Central-standaardtijd", "ChST": "Chamorro-tijd", "AKST": "Alaska-standaardtijd", "UYT": "Uruguayaanse standaardtijd", "EST": "Eastern-standaardtijd", "AST": "Atlantic-standaardtijd", "WIB": "West-Indonesische tijd", "OESZ": "Oost-Europese zomertijd", "TMST": "Turkmeense zomertijd", "JST": "Japanse standaardtijd", "CLT": "Chileense standaardtijd", "MST": "Mountain-standaardtijd", "IST": "Indiase tijd", "ECT": "Ecuadoraanse tijd", "BT": "Bhutaanse tijd", "JDT": "Japanse zomertijd", "LHST": "Lord Howe-eilandse standaardtijd", "MEZ": "Midden-Europese standaardtijd", "CHAST": "Chatham-standaardtijd", "CHADT": "Chatham-zomertijd", "WAT": "West-Afrikaanse standaardtijd", "HKST": "Hongkongse zomertijd", "WARST": "West-Argentijnse zomertijd", "NZDT": "Nieuw-Zeelandse zomertijd", "VET": "Venezolaanse tijd", "ACWST": "Midden-Australische westelijke standaardtijd", "COT": "Colombiaanse standaardtijd", "ARST": "Argentijnse zomertijd", "MYT": "Maleisische tijd", "BOT": "Boliviaanse tijd", "SAST": "Zuid-Afrikaanse tijd", "LHDT": "Lord Howe-eilandse zomertijd", "MESZ": "Midden-Europese zomertijd", "UYST": "Uruguayaanse zomertijd", "CLST": "Chileense zomertijd", "WIT": "Oost-Indonesische tijd", "SRT": "Surinaamse tijd", "AWDT": "West-Australische zomertijd", "HAST": "Hawaii-Aleoetische standaardtijd", "NZST": "Nieuw-Zeelandse standaardtijd", "AEST": "Oost-Australische standaardtijd", "HADT": "Hawaii-Aleoetische zomertijd", "SGT": "Singaporese standaardtijd", "GMT": "Greenwich Mean Time", "ART": "Argentijnse standaardtijd", "AKDT": "Alaska-zomertijd", "PDT": "Pacific-zomertijd", "CAT": "Centraal-Afrikaanse tijd", "EDT": "Eastern-zomertijd", "OEZ": "Oost-Europese standaardtijd", "HNT": "Newfoundland-standaardtijd", "CDT": "Central-zomertijd", "ADT": "Atlantic-zomertijd", "HKT": "Hongkongse standaardtijd", "ACDT": "Midden-Australische zomertijd", "PST": "Pacific-standaardtijd", "WEZ": "West-Europese standaardtijd", "AEDT": "Oost-Australische zomertijd", "∅∅∅": "Braziliaanse zomertijd", "HAT": "Newfoundland-zomertijd", "WITA": "Centraal-Indonesische tijd", "AWST": "West-Australische standaardtijd", "MDT": "Mountain-zomertijd", "WAST": "West-Afrikaanse zomertijd", "GFT": "Frans-Guyaanse tijd", "WESZ": "West-Europese zomertijd", "COST": "Colombiaanse zomertijd", "WART": "West-Argentijnse standaardtijd", "EAT": "Oost-Afrikaanse tijd", "TMT": "Turkmeense standaardtijd", "GYT": "Guyaanse tijd"},
  67. }
  68. }
  69. // Locale returns the current translators string locale
  70. func (nl *nl) Locale() string {
  71. return nl.locale
  72. }
  73. // PluralsCardinal returns the list of cardinal plural rules associated with 'nl'
  74. func (nl *nl) PluralsCardinal() []locales.PluralRule {
  75. return nl.pluralsCardinal
  76. }
  77. // PluralsOrdinal returns the list of ordinal plural rules associated with 'nl'
  78. func (nl *nl) PluralsOrdinal() []locales.PluralRule {
  79. return nl.pluralsOrdinal
  80. }
  81. // PluralsRange returns the list of range plural rules associated with 'nl'
  82. func (nl *nl) PluralsRange() []locales.PluralRule {
  83. return nl.pluralsRange
  84. }
  85. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'nl'
  86. func (nl *nl) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  87. n := math.Abs(num)
  88. i := int64(n)
  89. if i == 1 && v == 0 {
  90. return locales.PluralRuleOne
  91. }
  92. return locales.PluralRuleOther
  93. }
  94. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'nl'
  95. func (nl *nl) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  96. return locales.PluralRuleOther
  97. }
  98. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'nl'
  99. func (nl *nl) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  100. start := nl.CardinalPluralRule(num1, v1)
  101. end := nl.CardinalPluralRule(num2, v2)
  102. if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  103. return locales.PluralRuleOther
  104. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  105. return locales.PluralRuleOne
  106. }
  107. return locales.PluralRuleOther
  108. }
  109. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  110. func (nl *nl) MonthAbbreviated(month time.Month) string {
  111. return nl.monthsAbbreviated[month]
  112. }
  113. // MonthsAbbreviated returns the locales abbreviated months
  114. func (nl *nl) MonthsAbbreviated() []string {
  115. return nl.monthsAbbreviated[1:]
  116. }
  117. // MonthNarrow returns the locales narrow month given the 'month' provided
  118. func (nl *nl) MonthNarrow(month time.Month) string {
  119. return nl.monthsNarrow[month]
  120. }
  121. // MonthsNarrow returns the locales narrow months
  122. func (nl *nl) MonthsNarrow() []string {
  123. return nl.monthsNarrow[1:]
  124. }
  125. // MonthWide returns the locales wide month given the 'month' provided
  126. func (nl *nl) MonthWide(month time.Month) string {
  127. return nl.monthsWide[month]
  128. }
  129. // MonthsWide returns the locales wide months
  130. func (nl *nl) MonthsWide() []string {
  131. return nl.monthsWide[1:]
  132. }
  133. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  134. func (nl *nl) WeekdayAbbreviated(weekday time.Weekday) string {
  135. return nl.daysAbbreviated[weekday]
  136. }
  137. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  138. func (nl *nl) WeekdaysAbbreviated() []string {
  139. return nl.daysAbbreviated
  140. }
  141. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  142. func (nl *nl) WeekdayNarrow(weekday time.Weekday) string {
  143. return nl.daysNarrow[weekday]
  144. }
  145. // WeekdaysNarrow returns the locales narrow weekdays
  146. func (nl *nl) WeekdaysNarrow() []string {
  147. return nl.daysNarrow
  148. }
  149. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  150. func (nl *nl) WeekdayShort(weekday time.Weekday) string {
  151. return nl.daysShort[weekday]
  152. }
  153. // WeekdaysShort returns the locales short weekdays
  154. func (nl *nl) WeekdaysShort() []string {
  155. return nl.daysShort
  156. }
  157. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  158. func (nl *nl) WeekdayWide(weekday time.Weekday) string {
  159. return nl.daysWide[weekday]
  160. }
  161. // WeekdaysWide returns the locales wide weekdays
  162. func (nl *nl) WeekdaysWide() []string {
  163. return nl.daysWide
  164. }
  165. // FmtNumber returns 'num' with digits/precision of 'v' for 'nl' and handles both Whole and Real numbers based on 'v'
  166. func (nl *nl) FmtNumber(num float64, v uint64) string {
  167. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  168. l := len(s) + 0 + 0*len(s[:len(s)-int(v)-1])/3
  169. count := 0
  170. inWhole := v == 0
  171. b := make([]byte, 0, l)
  172. for i := len(s) - 1; i >= 0; i-- {
  173. if s[i] == '.' {
  174. b = append(b, nl.decimal[0])
  175. inWhole = true
  176. continue
  177. }
  178. if inWhole {
  179. if count == 3 {
  180. b = append(b, nl.group[0])
  181. count = 1
  182. } else {
  183. count++
  184. }
  185. }
  186. b = append(b, s[i])
  187. }
  188. if num < 0 {
  189. b = append(b, nl.minus[0])
  190. }
  191. // reverse
  192. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  193. b[i], b[j] = b[j], b[i]
  194. }
  195. return string(b)
  196. }
  197. // FmtPercent returns 'num' with digits/precision of 'v' for 'nl' and handles both Whole and Real numbers based on 'v'
  198. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  199. func (nl *nl) FmtPercent(num float64, v uint64) string {
  200. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  201. l := len(s) + 0
  202. b := make([]byte, 0, l)
  203. for i := len(s) - 1; i >= 0; i-- {
  204. if s[i] == '.' {
  205. b = append(b, nl.decimal[0])
  206. continue
  207. }
  208. b = append(b, s[i])
  209. }
  210. if num < 0 {
  211. b = append(b, nl.minus[0])
  212. }
  213. // reverse
  214. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  215. b[i], b[j] = b[j], b[i]
  216. }
  217. b = append(b, nl.percent...)
  218. return string(b)
  219. }
  220. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'nl'
  221. func (nl *nl) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  222. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  223. symbol := nl.currencies[currency]
  224. l := len(s) + len(symbol) + 2 + 0*len(s[:len(s)-int(v)-1])/3
  225. count := 0
  226. inWhole := v == 0
  227. b := make([]byte, 0, l)
  228. for i := len(s) - 1; i >= 0; i-- {
  229. if s[i] == '.' {
  230. b = append(b, nl.decimal[0])
  231. inWhole = true
  232. continue
  233. }
  234. if inWhole {
  235. if count == 3 {
  236. b = append(b, nl.group[0])
  237. count = 1
  238. } else {
  239. count++
  240. }
  241. }
  242. b = append(b, s[i])
  243. }
  244. for j := len(symbol) - 1; j >= 0; j-- {
  245. b = append(b, symbol[j])
  246. }
  247. for j := len(nl.currencyPositivePrefix) - 1; j >= 0; j-- {
  248. b = append(b, nl.currencyPositivePrefix[j])
  249. }
  250. if num < 0 {
  251. b = append(b, nl.minus[0])
  252. }
  253. // reverse
  254. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  255. b[i], b[j] = b[j], b[i]
  256. }
  257. if int(v) < 2 {
  258. if v == 0 {
  259. b = append(b, nl.decimal...)
  260. }
  261. for i := 0; i < 2-int(v); i++ {
  262. b = append(b, '0')
  263. }
  264. }
  265. return string(b)
  266. }
  267. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'nl'
  268. // in accounting notation.
  269. func (nl *nl) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  270. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  271. symbol := nl.currencies[currency]
  272. l := len(s) + len(symbol) + 4 + 0*len(s[:len(s)-int(v)-1])/3
  273. count := 0
  274. inWhole := v == 0
  275. b := make([]byte, 0, l)
  276. for i := len(s) - 1; i >= 0; i-- {
  277. if s[i] == '.' {
  278. b = append(b, nl.decimal[0])
  279. inWhole = true
  280. continue
  281. }
  282. if inWhole {
  283. if count == 3 {
  284. b = append(b, nl.group[0])
  285. count = 1
  286. } else {
  287. count++
  288. }
  289. }
  290. b = append(b, s[i])
  291. }
  292. if num < 0 {
  293. for j := len(symbol) - 1; j >= 0; j-- {
  294. b = append(b, symbol[j])
  295. }
  296. for j := len(nl.currencyNegativePrefix) - 1; j >= 0; j-- {
  297. b = append(b, nl.currencyNegativePrefix[j])
  298. }
  299. } else {
  300. for j := len(symbol) - 1; j >= 0; j-- {
  301. b = append(b, symbol[j])
  302. }
  303. for j := len(nl.currencyPositivePrefix) - 1; j >= 0; j-- {
  304. b = append(b, nl.currencyPositivePrefix[j])
  305. }
  306. }
  307. // reverse
  308. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  309. b[i], b[j] = b[j], b[i]
  310. }
  311. if int(v) < 2 {
  312. if v == 0 {
  313. b = append(b, nl.decimal...)
  314. }
  315. for i := 0; i < 2-int(v); i++ {
  316. b = append(b, '0')
  317. }
  318. }
  319. if num < 0 {
  320. b = append(b, nl.currencyNegativeSuffix...)
  321. }
  322. return string(b)
  323. }
  324. // FmtDateShort returns the short date representation of 't' for 'nl'
  325. func (nl *nl) FmtDateShort(t time.Time) string {
  326. b := make([]byte, 0, 32)
  327. if t.Day() < 10 {
  328. b = append(b, '0')
  329. }
  330. b = strconv.AppendInt(b, int64(t.Day()), 10)
  331. b = append(b, []byte{0x2d}...)
  332. if t.Month() < 10 {
  333. b = append(b, '0')
  334. }
  335. b = strconv.AppendInt(b, int64(t.Month()), 10)
  336. b = append(b, []byte{0x2d}...)
  337. if t.Year() > 9 {
  338. b = append(b, strconv.Itoa(t.Year())[2:]...)
  339. } else {
  340. b = append(b, strconv.Itoa(t.Year())[1:]...)
  341. }
  342. return string(b)
  343. }
  344. // FmtDateMedium returns the medium date representation of 't' for 'nl'
  345. func (nl *nl) FmtDateMedium(t time.Time) string {
  346. b := make([]byte, 0, 32)
  347. b = strconv.AppendInt(b, int64(t.Day()), 10)
  348. b = append(b, []byte{0x20}...)
  349. b = append(b, nl.monthsAbbreviated[t.Month()]...)
  350. b = append(b, []byte{0x20}...)
  351. b = strconv.AppendInt(b, int64(t.Year()), 10)
  352. return string(b)
  353. }
  354. // FmtDateLong returns the long date representation of 't' for 'nl'
  355. func (nl *nl) FmtDateLong(t time.Time) string {
  356. b := make([]byte, 0, 32)
  357. b = strconv.AppendInt(b, int64(t.Day()), 10)
  358. b = append(b, []byte{0x20}...)
  359. b = append(b, nl.monthsWide[t.Month()]...)
  360. b = append(b, []byte{0x20}...)
  361. b = strconv.AppendInt(b, int64(t.Year()), 10)
  362. return string(b)
  363. }
  364. // FmtDateFull returns the full date representation of 't' for 'nl'
  365. func (nl *nl) FmtDateFull(t time.Time) string {
  366. b := make([]byte, 0, 32)
  367. b = append(b, nl.daysWide[t.Weekday()]...)
  368. b = append(b, []byte{0x20}...)
  369. b = strconv.AppendInt(b, int64(t.Day()), 10)
  370. b = append(b, []byte{0x20}...)
  371. b = append(b, nl.monthsWide[t.Month()]...)
  372. b = append(b, []byte{0x20}...)
  373. b = strconv.AppendInt(b, int64(t.Year()), 10)
  374. return string(b)
  375. }
  376. // FmtTimeShort returns the short time representation of 't' for 'nl'
  377. func (nl *nl) FmtTimeShort(t time.Time) string {
  378. b := make([]byte, 0, 32)
  379. if t.Hour() < 10 {
  380. b = append(b, '0')
  381. }
  382. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  383. b = append(b, nl.timeSeparator...)
  384. if t.Minute() < 10 {
  385. b = append(b, '0')
  386. }
  387. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  388. return string(b)
  389. }
  390. // FmtTimeMedium returns the medium time representation of 't' for 'nl'
  391. func (nl *nl) FmtTimeMedium(t time.Time) string {
  392. b := make([]byte, 0, 32)
  393. if t.Hour() < 10 {
  394. b = append(b, '0')
  395. }
  396. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  397. b = append(b, nl.timeSeparator...)
  398. if t.Minute() < 10 {
  399. b = append(b, '0')
  400. }
  401. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  402. b = append(b, nl.timeSeparator...)
  403. if t.Second() < 10 {
  404. b = append(b, '0')
  405. }
  406. b = strconv.AppendInt(b, int64(t.Second()), 10)
  407. return string(b)
  408. }
  409. // FmtTimeLong returns the long time representation of 't' for 'nl'
  410. func (nl *nl) FmtTimeLong(t time.Time) string {
  411. b := make([]byte, 0, 32)
  412. if t.Hour() < 10 {
  413. b = append(b, '0')
  414. }
  415. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  416. b = append(b, nl.timeSeparator...)
  417. if t.Minute() < 10 {
  418. b = append(b, '0')
  419. }
  420. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  421. b = append(b, nl.timeSeparator...)
  422. if t.Second() < 10 {
  423. b = append(b, '0')
  424. }
  425. b = strconv.AppendInt(b, int64(t.Second()), 10)
  426. b = append(b, []byte{0x20}...)
  427. tz, _ := t.Zone()
  428. b = append(b, tz...)
  429. return string(b)
  430. }
  431. // FmtTimeFull returns the full time representation of 't' for 'nl'
  432. func (nl *nl) FmtTimeFull(t time.Time) string {
  433. b := make([]byte, 0, 32)
  434. if t.Hour() < 10 {
  435. b = append(b, '0')
  436. }
  437. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  438. b = append(b, nl.timeSeparator...)
  439. if t.Minute() < 10 {
  440. b = append(b, '0')
  441. }
  442. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  443. b = append(b, nl.timeSeparator...)
  444. if t.Second() < 10 {
  445. b = append(b, '0')
  446. }
  447. b = strconv.AppendInt(b, int64(t.Second()), 10)
  448. b = append(b, []byte{0x20}...)
  449. tz, _ := t.Zone()
  450. if btz, ok := nl.timezones[tz]; ok {
  451. b = append(b, btz...)
  452. } else {
  453. b = append(b, tz...)
  454. }
  455. return string(b)
  456. }