nb.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. package nb
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type nb 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. percentSuffix string
  19. perMille string
  20. timeSeparator string
  21. inifinity string
  22. currencies []string // idx = enum of currency code
  23. currencyPositivePrefix string
  24. currencyNegativePrefix 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 'nb' locale
  42. func New() locales.Translator {
  43. return &nb{
  44. locale: "nb",
  45. pluralsCardinal: []locales.PluralRule{2, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: []locales.PluralRule{6},
  48. decimal: "٫",
  49. group: " ",
  50. minus: "−",
  51. percent: "٪",
  52. perMille: "؉",
  53. timeSeparator: ".",
  54. inifinity: "∞",
  55. currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "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", "€", "FIM", "FJD", "FKP", "FRF", "£", "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", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "kr", "NPR", "NZD", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "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", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "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 "},
  56. percentSuffix: " ",
  57. currencyPositivePrefix: " ",
  58. currencyNegativePrefix: " ",
  59. monthsAbbreviated: []string{"", "jan.", "feb.", "mar.", "apr.", "mai", "jun.", "jul.", "aug.", "sep.", "okt.", "nov.", "des."},
  60. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  61. monthsWide: []string{"", "januar", "februar", "mars", "april", "mai", "juni", "juli", "august", "september", "oktober", "november", "desember"},
  62. daysAbbreviated: []string{"søn.", "man.", "tir.", "ons.", "tor.", "fre.", "lør."},
  63. daysNarrow: []string{"S", "M", "T", "O", "T", "F", "L"},
  64. daysShort: []string{"sø.", "ma.", "ti.", "on.", "to.", "fr.", "lø."},
  65. daysWide: []string{"søndag", "mandag", "tirsdag", "onsdag", "torsdag", "fredag", "lørdag"},
  66. periodsAbbreviated: []string{"a.m.", "p.m."},
  67. periodsNarrow: []string{"a", "p"},
  68. periodsWide: []string{"a.m.", "p.m."},
  69. erasAbbreviated: []string{"f.Kr.", "e.Kr."},
  70. erasNarrow: []string{"f.Kr.", "e.Kr."},
  71. erasWide: []string{"før Kristus", "etter Kristus"},
  72. timezones: map[string]string{"CHADT": "sommertid for Chatham", "∅∅∅": "sommertid for Brasilia", "ARST": "argentinsk sommertid", "WITA": "sentralindonesisk tid", "CDT": "sommertid for det sentrale Nord-Amerika", "MESZ": "sentraleuropeisk sommertid", "MDT": "sommertid for Rocky Mountains (USA)", "EDT": "sommertid for den nordamerikanske østkysten", "COT": "colombiansk normaltid", "BOT": "boliviansk tid", "WARST": "vestargentinsk sommertid", "OESZ": "østeuropeisk sommertid", "SRT": "surinamsk tid", "UYST": "uruguayansk sommertid", "MST": "normaltid for Rocky Mountains (USA)", "VET": "venezuelansk tid", "CAT": "sentralafrikansk tid", "HKT": "normaltid for Hongkong", "IST": "indisk tid", "GMT": "Greenwich middeltid", "GYT": "guyansk tid", "UYT": "uruguayansk normaltid", "ACWDT": "vest-sentralaustralsk sommertid", "COST": "colombiansk sommertid", "SGT": "singaporsk tid", "WIB": "vestindonesisk tid", "PST": "normaltid for den nordamerikanske Stillehavskysten", "AEST": "østaustralsk normaltid", "GFT": "tidssone for Fransk Guyana", "ChST": "tidssone for Chamorro", "HAT": "sommertid for Newfoundland", "AST": "atlanterhavskystlig standardtid", "OEZ": "østeuropeisk normaltid", "ACDT": "sentralaustralsk sommertid", "AKST": "alaskisk normaltid", "JDT": "japansk sommertid", "MEZ": "sentraleuropeisk normaltid", "BT": "bhutansk tid", "TMST": "turkmensk sommertid", "EAT": "østafrikansk tid", "LHST": "normaltid for Lord Howe-øya", "PDT": "sommertid for den nordamerikanske Stillehavskysten", "NZDT": "newzealandsk sommertid", "CHAST": "normaltid for Chatham", "WART": "vestargentinsk normaltid", "SAST": "sørafrikansk tid", "MYT": "malaysisk tid", "WAST": "vestafrikansk sommertid", "WIT": "østindonesisk tid", "AWST": "vestaustralsk normaltid", "AWDT": "vestaustralsk sommertid", "JST": "japansk normaltid", "NZST": "newzealandsk normaltid", "ECT": "ecuadoriansk tid", "ADT": "atlanterhavskystlig sommertid", "HADT": "sommertid for Hawaii og Aleutene", "TMT": "turkmensk normaltid", "WEZ": "vesteuropeisk normaltid", "EST": "normaltid for den nordamerikanske østkysten", "HAST": "normaltid for Hawaii og Aleutene", "CST": "normaltid for det sentrale Nord-Amerika", "CLT": "chilensk normaltid", "HKST": "sommertid for Hongkong", "LHDT": "sommertid for Lord Howe-øya", "ACWST": "vest-sentralaustralsk normaltid", "WAT": "vestafrikansk normaltid", "HNT": "normaltid for Newfoundland", "AKDT": "alaskisk sommertid", "CLST": "chilensk sommertid", "WESZ": "vesteuropeisk sommertid", "AEDT": "østaustralsk sommertid", "ART": "argentinsk normaltid", "ACST": "sentralaustralsk normaltid"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (nb *nb) Locale() string {
  77. return nb.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'nb'
  80. func (nb *nb) PluralsCardinal() []locales.PluralRule {
  81. return nb.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'nb'
  84. func (nb *nb) PluralsOrdinal() []locales.PluralRule {
  85. return nb.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'nb'
  88. func (nb *nb) PluralsRange() []locales.PluralRule {
  89. return nb.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'nb'
  92. func (nb *nb) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. if n == 1 {
  95. return locales.PluralRuleOne
  96. }
  97. return locales.PluralRuleOther
  98. }
  99. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'nb'
  100. func (nb *nb) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  101. return locales.PluralRuleOther
  102. }
  103. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'nb'
  104. func (nb *nb) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  105. return locales.PluralRuleOther
  106. }
  107. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  108. func (nb *nb) MonthAbbreviated(month time.Month) string {
  109. return nb.monthsAbbreviated[month]
  110. }
  111. // MonthsAbbreviated returns the locales abbreviated months
  112. func (nb *nb) MonthsAbbreviated() []string {
  113. return nb.monthsAbbreviated[1:]
  114. }
  115. // MonthNarrow returns the locales narrow month given the 'month' provided
  116. func (nb *nb) MonthNarrow(month time.Month) string {
  117. return nb.monthsNarrow[month]
  118. }
  119. // MonthsNarrow returns the locales narrow months
  120. func (nb *nb) MonthsNarrow() []string {
  121. return nb.monthsNarrow[1:]
  122. }
  123. // MonthWide returns the locales wide month given the 'month' provided
  124. func (nb *nb) MonthWide(month time.Month) string {
  125. return nb.monthsWide[month]
  126. }
  127. // MonthsWide returns the locales wide months
  128. func (nb *nb) MonthsWide() []string {
  129. return nb.monthsWide[1:]
  130. }
  131. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  132. func (nb *nb) WeekdayAbbreviated(weekday time.Weekday) string {
  133. return nb.daysAbbreviated[weekday]
  134. }
  135. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  136. func (nb *nb) WeekdaysAbbreviated() []string {
  137. return nb.daysAbbreviated
  138. }
  139. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  140. func (nb *nb) WeekdayNarrow(weekday time.Weekday) string {
  141. return nb.daysNarrow[weekday]
  142. }
  143. // WeekdaysNarrow returns the locales narrow weekdays
  144. func (nb *nb) WeekdaysNarrow() []string {
  145. return nb.daysNarrow
  146. }
  147. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  148. func (nb *nb) WeekdayShort(weekday time.Weekday) string {
  149. return nb.daysShort[weekday]
  150. }
  151. // WeekdaysShort returns the locales short weekdays
  152. func (nb *nb) WeekdaysShort() []string {
  153. return nb.daysShort
  154. }
  155. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  156. func (nb *nb) WeekdayWide(weekday time.Weekday) string {
  157. return nb.daysWide[weekday]
  158. }
  159. // WeekdaysWide returns the locales wide weekdays
  160. func (nb *nb) WeekdaysWide() []string {
  161. return nb.daysWide
  162. }
  163. // FmtNumber returns 'num' with digits/precision of 'v' for 'nb' and handles both Whole and Real numbers based on 'v'
  164. func (nb *nb) FmtNumber(num float64, v uint64) string {
  165. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  166. l := len(s) + 5 + 2*len(s[:len(s)-int(v)-1])/3
  167. count := 0
  168. inWhole := v == 0
  169. b := make([]byte, 0, l)
  170. for i := len(s) - 1; i >= 0; i-- {
  171. if s[i] == '.' {
  172. for j := len(nb.decimal) - 1; j >= 0; j-- {
  173. b = append(b, nb.decimal[j])
  174. }
  175. inWhole = true
  176. continue
  177. }
  178. if inWhole {
  179. if count == 3 {
  180. for j := len(nb.group) - 1; j >= 0; j-- {
  181. b = append(b, nb.group[j])
  182. }
  183. count = 1
  184. } else {
  185. count++
  186. }
  187. }
  188. b = append(b, s[i])
  189. }
  190. if num < 0 {
  191. for j := len(nb.minus) - 1; j >= 0; j-- {
  192. b = append(b, nb.minus[j])
  193. }
  194. }
  195. // reverse
  196. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  197. b[i], b[j] = b[j], b[i]
  198. }
  199. return string(b)
  200. }
  201. // FmtPercent returns 'num' with digits/precision of 'v' for 'nb' and handles both Whole and Real numbers based on 'v'
  202. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  203. func (nb *nb) FmtPercent(num float64, v uint64) string {
  204. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  205. l := len(s) + 9
  206. b := make([]byte, 0, l)
  207. for i := len(s) - 1; i >= 0; i-- {
  208. if s[i] == '.' {
  209. for j := len(nb.decimal) - 1; j >= 0; j-- {
  210. b = append(b, nb.decimal[j])
  211. }
  212. continue
  213. }
  214. b = append(b, s[i])
  215. }
  216. if num < 0 {
  217. for j := len(nb.minus) - 1; j >= 0; j-- {
  218. b = append(b, nb.minus[j])
  219. }
  220. }
  221. // reverse
  222. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  223. b[i], b[j] = b[j], b[i]
  224. }
  225. b = append(b, nb.percentSuffix...)
  226. b = append(b, nb.percent...)
  227. return string(b)
  228. }
  229. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'nb'
  230. func (nb *nb) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  231. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  232. symbol := nb.currencies[currency]
  233. l := len(s) + len(symbol) + 7 + 2*len(s[:len(s)-int(v)-1])/3
  234. count := 0
  235. inWhole := v == 0
  236. b := make([]byte, 0, l)
  237. for i := len(s) - 1; i >= 0; i-- {
  238. if s[i] == '.' {
  239. for j := len(nb.decimal) - 1; j >= 0; j-- {
  240. b = append(b, nb.decimal[j])
  241. }
  242. inWhole = true
  243. continue
  244. }
  245. if inWhole {
  246. if count == 3 {
  247. for j := len(nb.group) - 1; j >= 0; j-- {
  248. b = append(b, nb.group[j])
  249. }
  250. count = 1
  251. } else {
  252. count++
  253. }
  254. }
  255. b = append(b, s[i])
  256. }
  257. for j := len(symbol) - 1; j >= 0; j-- {
  258. b = append(b, symbol[j])
  259. }
  260. for j := len(nb.currencyPositivePrefix) - 1; j >= 0; j-- {
  261. b = append(b, nb.currencyPositivePrefix[j])
  262. }
  263. if num < 0 {
  264. for j := len(nb.minus) - 1; j >= 0; j-- {
  265. b = append(b, nb.minus[j])
  266. }
  267. }
  268. // reverse
  269. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  270. b[i], b[j] = b[j], b[i]
  271. }
  272. if int(v) < 2 {
  273. if v == 0 {
  274. b = append(b, nb.decimal...)
  275. }
  276. for i := 0; i < 2-int(v); i++ {
  277. b = append(b, '0')
  278. }
  279. }
  280. return string(b)
  281. }
  282. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'nb'
  283. // in accounting notation.
  284. func (nb *nb) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  285. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  286. symbol := nb.currencies[currency]
  287. l := len(s) + len(symbol) + 7 + 2*len(s[:len(s)-int(v)-1])/3
  288. count := 0
  289. inWhole := v == 0
  290. b := make([]byte, 0, l)
  291. for i := len(s) - 1; i >= 0; i-- {
  292. if s[i] == '.' {
  293. for j := len(nb.decimal) - 1; j >= 0; j-- {
  294. b = append(b, nb.decimal[j])
  295. }
  296. inWhole = true
  297. continue
  298. }
  299. if inWhole {
  300. if count == 3 {
  301. for j := len(nb.group) - 1; j >= 0; j-- {
  302. b = append(b, nb.group[j])
  303. }
  304. count = 1
  305. } else {
  306. count++
  307. }
  308. }
  309. b = append(b, s[i])
  310. }
  311. if num < 0 {
  312. for j := len(symbol) - 1; j >= 0; j-- {
  313. b = append(b, symbol[j])
  314. }
  315. for j := len(nb.currencyNegativePrefix) - 1; j >= 0; j-- {
  316. b = append(b, nb.currencyNegativePrefix[j])
  317. }
  318. for j := len(nb.minus) - 1; j >= 0; j-- {
  319. b = append(b, nb.minus[j])
  320. }
  321. } else {
  322. for j := len(symbol) - 1; j >= 0; j-- {
  323. b = append(b, symbol[j])
  324. }
  325. for j := len(nb.currencyPositivePrefix) - 1; j >= 0; j-- {
  326. b = append(b, nb.currencyPositivePrefix[j])
  327. }
  328. }
  329. // reverse
  330. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  331. b[i], b[j] = b[j], b[i]
  332. }
  333. if int(v) < 2 {
  334. if v == 0 {
  335. b = append(b, nb.decimal...)
  336. }
  337. for i := 0; i < 2-int(v); i++ {
  338. b = append(b, '0')
  339. }
  340. }
  341. return string(b)
  342. }
  343. // FmtDateShort returns the short date representation of 't' for 'nb'
  344. func (nb *nb) FmtDateShort(t time.Time) string {
  345. b := make([]byte, 0, 32)
  346. if t.Day() < 10 {
  347. b = append(b, '0')
  348. }
  349. b = strconv.AppendInt(b, int64(t.Day()), 10)
  350. b = append(b, []byte{0x2e}...)
  351. if t.Month() < 10 {
  352. b = append(b, '0')
  353. }
  354. b = strconv.AppendInt(b, int64(t.Month()), 10)
  355. b = append(b, []byte{0x2e}...)
  356. b = strconv.AppendInt(b, int64(t.Year()), 10)
  357. return string(b)
  358. }
  359. // FmtDateMedium returns the medium date representation of 't' for 'nb'
  360. func (nb *nb) FmtDateMedium(t time.Time) string {
  361. b := make([]byte, 0, 32)
  362. b = strconv.AppendInt(b, int64(t.Day()), 10)
  363. b = append(b, []byte{0x2e, 0x20}...)
  364. b = append(b, nb.monthsAbbreviated[t.Month()]...)
  365. b = append(b, []byte{0x20}...)
  366. b = strconv.AppendInt(b, int64(t.Year()), 10)
  367. return string(b)
  368. }
  369. // FmtDateLong returns the long date representation of 't' for 'nb'
  370. func (nb *nb) FmtDateLong(t time.Time) string {
  371. b := make([]byte, 0, 32)
  372. b = strconv.AppendInt(b, int64(t.Day()), 10)
  373. b = append(b, []byte{0x2e, 0x20}...)
  374. b = append(b, nb.monthsWide[t.Month()]...)
  375. b = append(b, []byte{0x20}...)
  376. b = strconv.AppendInt(b, int64(t.Year()), 10)
  377. return string(b)
  378. }
  379. // FmtDateFull returns the full date representation of 't' for 'nb'
  380. func (nb *nb) FmtDateFull(t time.Time) string {
  381. b := make([]byte, 0, 32)
  382. b = append(b, nb.daysWide[t.Weekday()]...)
  383. b = append(b, []byte{0x20}...)
  384. b = strconv.AppendInt(b, int64(t.Day()), 10)
  385. b = append(b, []byte{0x2e, 0x20}...)
  386. b = append(b, nb.monthsWide[t.Month()]...)
  387. b = append(b, []byte{0x20}...)
  388. b = strconv.AppendInt(b, int64(t.Year()), 10)
  389. return string(b)
  390. }
  391. // FmtTimeShort returns the short time representation of 't' for 'nb'
  392. func (nb *nb) FmtTimeShort(t time.Time) string {
  393. b := make([]byte, 0, 32)
  394. if t.Hour() < 10 {
  395. b = append(b, '0')
  396. }
  397. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  398. b = append(b, []byte{0x2e}...)
  399. if t.Minute() < 10 {
  400. b = append(b, '0')
  401. }
  402. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  403. return string(b)
  404. }
  405. // FmtTimeMedium returns the medium time representation of 't' for 'nb'
  406. func (nb *nb) FmtTimeMedium(t time.Time) string {
  407. b := make([]byte, 0, 32)
  408. if t.Hour() < 10 {
  409. b = append(b, '0')
  410. }
  411. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  412. b = append(b, []byte{0x2e}...)
  413. if t.Minute() < 10 {
  414. b = append(b, '0')
  415. }
  416. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  417. b = append(b, []byte{0x2e}...)
  418. if t.Second() < 10 {
  419. b = append(b, '0')
  420. }
  421. b = strconv.AppendInt(b, int64(t.Second()), 10)
  422. return string(b)
  423. }
  424. // FmtTimeLong returns the long time representation of 't' for 'nb'
  425. func (nb *nb) FmtTimeLong(t time.Time) string {
  426. b := make([]byte, 0, 32)
  427. if t.Hour() < 10 {
  428. b = append(b, '0')
  429. }
  430. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  431. b = append(b, []byte{0x2e}...)
  432. if t.Minute() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  436. b = append(b, []byte{0x2e}...)
  437. if t.Second() < 10 {
  438. b = append(b, '0')
  439. }
  440. b = strconv.AppendInt(b, int64(t.Second()), 10)
  441. b = append(b, []byte{0x20}...)
  442. tz, _ := t.Zone()
  443. b = append(b, tz...)
  444. return string(b)
  445. }
  446. // FmtTimeFull returns the full time representation of 't' for 'nb'
  447. func (nb *nb) FmtTimeFull(t time.Time) string {
  448. b := make([]byte, 0, 32)
  449. if t.Hour() < 10 {
  450. b = append(b, '0')
  451. }
  452. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  453. b = append(b, []byte{0x2e}...)
  454. if t.Minute() < 10 {
  455. b = append(b, '0')
  456. }
  457. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  458. b = append(b, []byte{0x2e}...)
  459. if t.Second() < 10 {
  460. b = append(b, '0')
  461. }
  462. b = strconv.AppendInt(b, int64(t.Second()), 10)
  463. b = append(b, []byte{0x20}...)
  464. tz, _ := t.Zone()
  465. if btz, ok := nb.timezones[tz]; ok {
  466. b = append(b, btz...)
  467. } else {
  468. b = append(b, tz...)
  469. }
  470. return string(b)
  471. }