nb.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CNY", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "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", "STN", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "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{"HNT": "normaltid for Newfoundland", "HEPM": "sommertid for Saint-Pierre-et-Miquelon", "WEZ": "vesteuropeisk normaltid", "WESZ": "vesteuropeisk sommertid", "MYT": "malaysisk tid", "SGT": "singaporsk tid", "HKT": "normaltid for Hongkong", "HNEG": "østgrønlandsk normaltid", "CLST": "chilensk sommertid", "HAST": "normaltid for Hawaii og Aleutene", "AWDT": "vestaustralsk sommertid", "NZDT": "newzealandsk sommertid", "HNPM": "normaltid for Saint-Pierre-et-Miquelon", "OESZ": "østeuropeisk sommertid", "HECU": "cubansk sommertid", "AEDT": "østaustralsk sommertid", "MDT": "sommertid for Rocky Mountains (USA)", "ACWST": "vest-sentralaustralsk normaltid", "VET": "venezuelansk tid", "ChST": "tidssone for Chamorro", "PST": "normaltid for den nordamerikanske Stillehavskysten", "HEPMX": "sommertid for den meksikanske Stillehavskysten", "SAST": "sørafrikansk tid", "EST": "normaltid for den nordamerikanske østkysten", "ACST": "sentralaustralsk normaltid", "ACWDT": "vest-sentralaustralsk sommertid", "CHADT": "sommertid for Chatham", "HAT": "sommertid for Newfoundland", "HNCU": "cubansk normaltid", "CDT": "sommertid for det sentrale Nord-Amerika", "WAST": "vestafrikansk sommertid", "∅∅∅": "Acre sommertid", "EDT": "sommertid for den nordamerikanske østkysten", "HEEG": "østgrønlandsk sommertid", "HEOG": "vestgrønlandsk sommertid", "AEST": "østaustralsk normaltid", "WITA": "sentralindonesisk tid", "HENOMX": "sommertid for nordvestlige Mexico", "MESZ": "sentraleuropeisk sommertid", "IST": "indisk tid", "LHST": "normaltid for Lord Howe-øya", "HADT": "sommertid for Hawaii og Aleutene", "HNNOMX": "normaltid for nordvestlige Mexico", "WIT": "østindonesisk tid", "TMT": "turkmensk normaltid", "BT": "bhutansk tid", "NZST": "newzealandsk normaltid", "BOT": "boliviansk tid", "AKST": "alaskisk normaltid", "WART": "vestargentinsk normaltid", "TMST": "turkmensk sommertid", "OEZ": "østeuropeisk normaltid", "GYT": "guyansk tid", "CHAST": "normaltid for Chatham", "HNPMX": "normaltid for den meksikanske Stillehavskysten", "ADT": "sommertid for den nordamerikanske atlanterhavskysten", "WAT": "vestafrikansk normaltid", "MEZ": "sentraleuropeisk normaltid", "ACDT": "sentralaustralsk sommertid", "WARST": "vestargentinsk sommertid", "SRT": "surinamsk tid", "ART": "argentinsk normaltid", "CST": "normaltid for det sentrale Nord-Amerika", "AWST": "vestaustralsk normaltid", "MST": "normaltid for Rocky Mountains (USA)", "GFT": "tidssone for Fransk Guyana", "JST": "japansk normaltid", "GMT": "Greenwich middeltid", "UYST": "uruguayansk sommertid", "AKDT": "alaskisk sommertid", "HNOG": "vestgrønlandsk normaltid", "HKST": "sommertid for Hongkong", "ARST": "argentinsk sommertid", "UYT": "uruguayansk normaltid", "CAT": "sentralafrikansk tid", "PDT": "sommertid for den nordamerikanske Stillehavskysten", "JDT": "japansk sommertid", "EAT": "østafrikansk tid", "COT": "colombiansk normaltid", "COST": "colombiansk sommertid", "AST": "normaltid for den nordamerikanske atlanterhavskysten", "WIB": "vestindonesisk tid", "ECT": "ecuadoriansk tid", "LHDT": "sommertid for Lord Howe-øya", "CLT": "chilensk 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. // Decimal returns the decimal point of number
  164. func (nb *nb) Decimal() string {
  165. return nb.decimal
  166. }
  167. // Group returns the group of number
  168. func (nb *nb) Group() string {
  169. return nb.group
  170. }
  171. // Group returns the minus sign of number
  172. func (nb *nb) Minus() string {
  173. return nb.minus
  174. }
  175. // FmtNumber returns 'num' with digits/precision of 'v' for 'nb' and handles both Whole and Real numbers based on 'v'
  176. func (nb *nb) FmtNumber(num float64, v uint64) string {
  177. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  178. l := len(s) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  179. count := 0
  180. inWhole := v == 0
  181. b := make([]byte, 0, l)
  182. for i := len(s) - 1; i >= 0; i-- {
  183. if s[i] == '.' {
  184. b = append(b, nb.decimal[0])
  185. inWhole = true
  186. continue
  187. }
  188. if inWhole {
  189. if count == 3 {
  190. for j := len(nb.group) - 1; j >= 0; j-- {
  191. b = append(b, nb.group[j])
  192. }
  193. count = 1
  194. } else {
  195. count++
  196. }
  197. }
  198. b = append(b, s[i])
  199. }
  200. if num < 0 {
  201. for j := len(nb.minus) - 1; j >= 0; j-- {
  202. b = append(b, nb.minus[j])
  203. }
  204. }
  205. // reverse
  206. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  207. b[i], b[j] = b[j], b[i]
  208. }
  209. return string(b)
  210. }
  211. // FmtPercent returns 'num' with digits/precision of 'v' for 'nb' and handles both Whole and Real numbers based on 'v'
  212. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  213. func (nb *nb) FmtPercent(num float64, v uint64) string {
  214. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  215. l := len(s) + 7
  216. b := make([]byte, 0, l)
  217. for i := len(s) - 1; i >= 0; i-- {
  218. if s[i] == '.' {
  219. b = append(b, nb.decimal[0])
  220. continue
  221. }
  222. b = append(b, s[i])
  223. }
  224. if num < 0 {
  225. for j := len(nb.minus) - 1; j >= 0; j-- {
  226. b = append(b, nb.minus[j])
  227. }
  228. }
  229. // reverse
  230. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  231. b[i], b[j] = b[j], b[i]
  232. }
  233. b = append(b, nb.percentSuffix...)
  234. b = append(b, nb.percent...)
  235. return string(b)
  236. }
  237. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'nb'
  238. func (nb *nb) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  239. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  240. symbol := nb.currencies[currency]
  241. l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  242. count := 0
  243. inWhole := v == 0
  244. b := make([]byte, 0, l)
  245. for i := len(s) - 1; i >= 0; i-- {
  246. if s[i] == '.' {
  247. b = append(b, nb.decimal[0])
  248. inWhole = true
  249. continue
  250. }
  251. if inWhole {
  252. if count == 3 {
  253. for j := len(nb.group) - 1; j >= 0; j-- {
  254. b = append(b, nb.group[j])
  255. }
  256. count = 1
  257. } else {
  258. count++
  259. }
  260. }
  261. b = append(b, s[i])
  262. }
  263. for j := len(symbol) - 1; j >= 0; j-- {
  264. b = append(b, symbol[j])
  265. }
  266. for j := len(nb.currencyPositivePrefix) - 1; j >= 0; j-- {
  267. b = append(b, nb.currencyPositivePrefix[j])
  268. }
  269. if num < 0 {
  270. for j := len(nb.minus) - 1; j >= 0; j-- {
  271. b = append(b, nb.minus[j])
  272. }
  273. }
  274. // reverse
  275. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  276. b[i], b[j] = b[j], b[i]
  277. }
  278. if int(v) < 2 {
  279. if v == 0 {
  280. b = append(b, nb.decimal...)
  281. }
  282. for i := 0; i < 2-int(v); i++ {
  283. b = append(b, '0')
  284. }
  285. }
  286. return string(b)
  287. }
  288. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'nb'
  289. // in accounting notation.
  290. func (nb *nb) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  291. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  292. symbol := nb.currencies[currency]
  293. l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  294. count := 0
  295. inWhole := v == 0
  296. b := make([]byte, 0, l)
  297. for i := len(s) - 1; i >= 0; i-- {
  298. if s[i] == '.' {
  299. b = append(b, nb.decimal[0])
  300. inWhole = true
  301. continue
  302. }
  303. if inWhole {
  304. if count == 3 {
  305. for j := len(nb.group) - 1; j >= 0; j-- {
  306. b = append(b, nb.group[j])
  307. }
  308. count = 1
  309. } else {
  310. count++
  311. }
  312. }
  313. b = append(b, s[i])
  314. }
  315. if num < 0 {
  316. for j := len(symbol) - 1; j >= 0; j-- {
  317. b = append(b, symbol[j])
  318. }
  319. for j := len(nb.currencyNegativePrefix) - 1; j >= 0; j-- {
  320. b = append(b, nb.currencyNegativePrefix[j])
  321. }
  322. for j := len(nb.minus) - 1; j >= 0; j-- {
  323. b = append(b, nb.minus[j])
  324. }
  325. } else {
  326. for j := len(symbol) - 1; j >= 0; j-- {
  327. b = append(b, symbol[j])
  328. }
  329. for j := len(nb.currencyPositivePrefix) - 1; j >= 0; j-- {
  330. b = append(b, nb.currencyPositivePrefix[j])
  331. }
  332. }
  333. // reverse
  334. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  335. b[i], b[j] = b[j], b[i]
  336. }
  337. if int(v) < 2 {
  338. if v == 0 {
  339. b = append(b, nb.decimal...)
  340. }
  341. for i := 0; i < 2-int(v); i++ {
  342. b = append(b, '0')
  343. }
  344. }
  345. return string(b)
  346. }
  347. // FmtDateShort returns the short date representation of 't' for 'nb'
  348. func (nb *nb) FmtDateShort(t time.Time) string {
  349. b := make([]byte, 0, 32)
  350. if t.Day() < 10 {
  351. b = append(b, '0')
  352. }
  353. b = strconv.AppendInt(b, int64(t.Day()), 10)
  354. b = append(b, []byte{0x2e}...)
  355. if t.Month() < 10 {
  356. b = append(b, '0')
  357. }
  358. b = strconv.AppendInt(b, int64(t.Month()), 10)
  359. b = append(b, []byte{0x2e}...)
  360. if t.Year() > 0 {
  361. b = strconv.AppendInt(b, int64(t.Year()), 10)
  362. } else {
  363. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  364. }
  365. return string(b)
  366. }
  367. // FmtDateMedium returns the medium date representation of 't' for 'nb'
  368. func (nb *nb) FmtDateMedium(t time.Time) string {
  369. b := make([]byte, 0, 32)
  370. b = strconv.AppendInt(b, int64(t.Day()), 10)
  371. b = append(b, []byte{0x2e, 0x20}...)
  372. b = append(b, nb.monthsAbbreviated[t.Month()]...)
  373. b = append(b, []byte{0x20}...)
  374. if t.Year() > 0 {
  375. b = strconv.AppendInt(b, int64(t.Year()), 10)
  376. } else {
  377. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  378. }
  379. return string(b)
  380. }
  381. // FmtDateLong returns the long date representation of 't' for 'nb'
  382. func (nb *nb) FmtDateLong(t time.Time) string {
  383. b := make([]byte, 0, 32)
  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. if t.Year() > 0 {
  389. b = strconv.AppendInt(b, int64(t.Year()), 10)
  390. } else {
  391. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  392. }
  393. return string(b)
  394. }
  395. // FmtDateFull returns the full date representation of 't' for 'nb'
  396. func (nb *nb) FmtDateFull(t time.Time) string {
  397. b := make([]byte, 0, 32)
  398. b = append(b, nb.daysWide[t.Weekday()]...)
  399. b = append(b, []byte{0x20}...)
  400. b = strconv.AppendInt(b, int64(t.Day()), 10)
  401. b = append(b, []byte{0x2e, 0x20}...)
  402. b = append(b, nb.monthsWide[t.Month()]...)
  403. b = append(b, []byte{0x20}...)
  404. if t.Year() > 0 {
  405. b = strconv.AppendInt(b, int64(t.Year()), 10)
  406. } else {
  407. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  408. }
  409. return string(b)
  410. }
  411. // FmtTimeShort returns the short time representation of 't' for 'nb'
  412. func (nb *nb) FmtTimeShort(t time.Time) string {
  413. b := make([]byte, 0, 32)
  414. if t.Hour() < 10 {
  415. b = append(b, '0')
  416. }
  417. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  418. b = append(b, nb.timeSeparator...)
  419. if t.Minute() < 10 {
  420. b = append(b, '0')
  421. }
  422. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  423. return string(b)
  424. }
  425. // FmtTimeMedium returns the medium time representation of 't' for 'nb'
  426. func (nb *nb) FmtTimeMedium(t time.Time) string {
  427. b := make([]byte, 0, 32)
  428. if t.Hour() < 10 {
  429. b = append(b, '0')
  430. }
  431. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  432. b = append(b, nb.timeSeparator...)
  433. if t.Minute() < 10 {
  434. b = append(b, '0')
  435. }
  436. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  437. b = append(b, nb.timeSeparator...)
  438. if t.Second() < 10 {
  439. b = append(b, '0')
  440. }
  441. b = strconv.AppendInt(b, int64(t.Second()), 10)
  442. return string(b)
  443. }
  444. // FmtTimeLong returns the long time representation of 't' for 'nb'
  445. func (nb *nb) FmtTimeLong(t time.Time) string {
  446. b := make([]byte, 0, 32)
  447. if t.Hour() < 10 {
  448. b = append(b, '0')
  449. }
  450. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  451. b = append(b, nb.timeSeparator...)
  452. if t.Minute() < 10 {
  453. b = append(b, '0')
  454. }
  455. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  456. b = append(b, nb.timeSeparator...)
  457. if t.Second() < 10 {
  458. b = append(b, '0')
  459. }
  460. b = strconv.AppendInt(b, int64(t.Second()), 10)
  461. b = append(b, []byte{0x20}...)
  462. tz, _ := t.Zone()
  463. b = append(b, tz...)
  464. return string(b)
  465. }
  466. // FmtTimeFull returns the full time representation of 't' for 'nb'
  467. func (nb *nb) FmtTimeFull(t time.Time) string {
  468. b := make([]byte, 0, 32)
  469. if t.Hour() < 10 {
  470. b = append(b, '0')
  471. }
  472. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  473. b = append(b, nb.timeSeparator...)
  474. if t.Minute() < 10 {
  475. b = append(b, '0')
  476. }
  477. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  478. b = append(b, nb.timeSeparator...)
  479. if t.Second() < 10 {
  480. b = append(b, '0')
  481. }
  482. b = strconv.AppendInt(b, int64(t.Second()), 10)
  483. b = append(b, []byte{0x20}...)
  484. tz, _ := t.Zone()
  485. if btz, ok := nb.timezones[tz]; ok {
  486. b = append(b, btz...)
  487. } else {
  488. b = append(b, tz...)
  489. }
  490. return string(b)
  491. }