nn.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. package nn
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type nn 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. currencyPositiveSuffix 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 'nn' locale
  42. func New() locales.Translator {
  43. return &nn{
  44. locale: "nn",
  45. pluralsCardinal: []locales.PluralRule{2, 6},
  46. pluralsOrdinal: nil,
  47. pluralsRange: nil,
  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 ", "EUR ", "FIM ", "FJD ", "FKP ", "FRF ", "GBP ", "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 ", "XOF ", "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. currencyPositiveSuffix: " ",
  58. currencyNegativeSuffix: " ",
  59. monthsAbbreviated: []string{"", "jan.", "feb.", "mars", "apr.", "mai", "juni", "juli", "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ø.", "må.", "ty.", "on.", "to.", "fr.", "la."},
  63. daysNarrow: []string{"S", "M", "T", "O", "T", "F", "L"},
  64. daysWide: []string{"søndag", "måndag", "tysdag", "onsdag", "torsdag", "fredag", "laurdag"},
  65. periodsAbbreviated: []string{"f.m.", "e.m."},
  66. periodsNarrow: []string{"f.m.", "e.m."},
  67. periodsWide: []string{"formiddag", "ettermiddag"},
  68. erasAbbreviated: []string{"f.Kr.", "e.Kr."},
  69. erasNarrow: []string{"f.Kr.", "e.Kr."},
  70. erasWide: []string{"f.Kr.", "e.Kr."},
  71. timezones: map[string]string{"UYST": "UYST", "EDT": "EDT", "ECT": "ECT", "WART": "WART", "MDT": "MDT", "LHST": "LHST", "NZDT": "NZDT", "OESZ": "austeuropeisk sommartid", "MST": "MST", "ART": "ART", "PDT": "PDT", "GYT": "GYT", "CDT": "CDT", "WAST": "vestafrikansk sommartid", "AWDT": "vestaustralsk sommartid", "MESZ": "sentraleuropeisk sommartid", "CLT": "CLT", "CHADT": "CHADT", "HKT": "HKT", "SRT": "SRT", "CLST": "CLST", "TMST": "TMST", "UYT": "UYT", "EST": "EST", "WAT": "vestafrikansk standardtid", "BT": "BT", "WIB": "WIB", "GFT": "GFT", "ACST": "sentralaustralsk standardtid", "ACWDT": "vest-sentralaustralsk sommartid", "JDT": "JDT", "AWST": "vestaustralsk standardtid", "HKST": "HKST", "WARST": "WARST", "IST": "IST", "WITA": "WITA", "COST": "COST", "WIT": "WIT", "PST": "PST", "ACWST": "vest-sentralaustralsk standardtid", "ChST": "ChST", "CHAST": "CHAST", "HNT": "HNT", "HAT": "HAT", "EAT": "austafrikansk tid", "MYT": "MYT", "WESZ": "vesteuropeisk sommartid", "CAT": "sentralafrikansk tid", "∅∅∅": "∅∅∅", "WEZ": "vesteuropeisk standardtid", "AEST": "austaustralsk standardtid", "AEDT": "austaustralsk sommartid", "OEZ": "austeuropeisk standardtid", "AKST": "AKST", "CST": "CST", "MEZ": "sentraleuropeisk standardtid", "BOT": "BOT", "VET": "VET", "TMT": "TMT", "JST": "JST", "COT": "COT", "AST": "AST", "HAST": "HAST", "SAST": "sørafrikansk tid", "ACDT": "sentralaustralsk sommartid", "ARST": "ARST", "HADT": "HADT", "SGT": "SGT", "AKDT": "AKDT", "LHDT": "LHDT", "NZST": "NZST", "ADT": "ADT", "GMT": "greenwich middeltid"},
  72. }
  73. }
  74. // Locale returns the current translators string locale
  75. func (nn *nn) Locale() string {
  76. return nn.locale
  77. }
  78. // PluralsCardinal returns the list of cardinal plural rules associated with 'nn'
  79. func (nn *nn) PluralsCardinal() []locales.PluralRule {
  80. return nn.pluralsCardinal
  81. }
  82. // PluralsOrdinal returns the list of ordinal plural rules associated with 'nn'
  83. func (nn *nn) PluralsOrdinal() []locales.PluralRule {
  84. return nn.pluralsOrdinal
  85. }
  86. // PluralsRange returns the list of range plural rules associated with 'nn'
  87. func (nn *nn) PluralsRange() []locales.PluralRule {
  88. return nn.pluralsRange
  89. }
  90. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'nn'
  91. func (nn *nn) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  92. n := math.Abs(num)
  93. if n == 1 {
  94. return locales.PluralRuleOne
  95. }
  96. return locales.PluralRuleOther
  97. }
  98. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'nn'
  99. func (nn *nn) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  100. return locales.PluralRuleUnknown
  101. }
  102. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'nn'
  103. func (nn *nn) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  104. return locales.PluralRuleUnknown
  105. }
  106. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  107. func (nn *nn) MonthAbbreviated(month time.Month) string {
  108. return nn.monthsAbbreviated[month]
  109. }
  110. // MonthsAbbreviated returns the locales abbreviated months
  111. func (nn *nn) MonthsAbbreviated() []string {
  112. return nn.monthsAbbreviated[1:]
  113. }
  114. // MonthNarrow returns the locales narrow month given the 'month' provided
  115. func (nn *nn) MonthNarrow(month time.Month) string {
  116. return nn.monthsNarrow[month]
  117. }
  118. // MonthsNarrow returns the locales narrow months
  119. func (nn *nn) MonthsNarrow() []string {
  120. return nn.monthsNarrow[1:]
  121. }
  122. // MonthWide returns the locales wide month given the 'month' provided
  123. func (nn *nn) MonthWide(month time.Month) string {
  124. return nn.monthsWide[month]
  125. }
  126. // MonthsWide returns the locales wide months
  127. func (nn *nn) MonthsWide() []string {
  128. return nn.monthsWide[1:]
  129. }
  130. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  131. func (nn *nn) WeekdayAbbreviated(weekday time.Weekday) string {
  132. return nn.daysAbbreviated[weekday]
  133. }
  134. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  135. func (nn *nn) WeekdaysAbbreviated() []string {
  136. return nn.daysAbbreviated
  137. }
  138. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  139. func (nn *nn) WeekdayNarrow(weekday time.Weekday) string {
  140. return nn.daysNarrow[weekday]
  141. }
  142. // WeekdaysNarrow returns the locales narrow weekdays
  143. func (nn *nn) WeekdaysNarrow() []string {
  144. return nn.daysNarrow
  145. }
  146. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  147. func (nn *nn) WeekdayShort(weekday time.Weekday) string {
  148. return nn.daysShort[weekday]
  149. }
  150. // WeekdaysShort returns the locales short weekdays
  151. func (nn *nn) WeekdaysShort() []string {
  152. return nn.daysShort
  153. }
  154. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  155. func (nn *nn) WeekdayWide(weekday time.Weekday) string {
  156. return nn.daysWide[weekday]
  157. }
  158. // WeekdaysWide returns the locales wide weekdays
  159. func (nn *nn) WeekdaysWide() []string {
  160. return nn.daysWide
  161. }
  162. // FmtNumber returns 'num' with digits/precision of 'v' for 'nn' and handles both Whole and Real numbers based on 'v'
  163. func (nn *nn) FmtNumber(num float64, v uint64) string {
  164. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  165. l := len(s) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  166. count := 0
  167. inWhole := v == 0
  168. b := make([]byte, 0, l)
  169. for i := len(s) - 1; i >= 0; i-- {
  170. if s[i] == '.' {
  171. b = append(b, nn.decimal[0])
  172. inWhole = true
  173. continue
  174. }
  175. if inWhole {
  176. if count == 3 {
  177. for j := len(nn.group) - 1; j >= 0; j-- {
  178. b = append(b, nn.group[j])
  179. }
  180. count = 1
  181. } else {
  182. count++
  183. }
  184. }
  185. b = append(b, s[i])
  186. }
  187. if num < 0 {
  188. for j := len(nn.minus) - 1; j >= 0; j-- {
  189. b = append(b, nn.minus[j])
  190. }
  191. }
  192. // reverse
  193. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  194. b[i], b[j] = b[j], b[i]
  195. }
  196. return string(b)
  197. }
  198. // FmtPercent returns 'num' with digits/precision of 'v' for 'nn' and handles both Whole and Real numbers based on 'v'
  199. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  200. func (nn *nn) FmtPercent(num float64, v uint64) string {
  201. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  202. l := len(s) + 7
  203. b := make([]byte, 0, l)
  204. for i := len(s) - 1; i >= 0; i-- {
  205. if s[i] == '.' {
  206. b = append(b, nn.decimal[0])
  207. continue
  208. }
  209. b = append(b, s[i])
  210. }
  211. if num < 0 {
  212. for j := len(nn.minus) - 1; j >= 0; j-- {
  213. b = append(b, nn.minus[j])
  214. }
  215. }
  216. // reverse
  217. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  218. b[i], b[j] = b[j], b[i]
  219. }
  220. b = append(b, nn.percentSuffix...)
  221. b = append(b, nn.percent...)
  222. return string(b)
  223. }
  224. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'nn'
  225. func (nn *nn) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  226. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  227. symbol := nn.currencies[currency]
  228. l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  229. count := 0
  230. inWhole := v == 0
  231. b := make([]byte, 0, l)
  232. for i := len(s) - 1; i >= 0; i-- {
  233. if s[i] == '.' {
  234. b = append(b, nn.decimal[0])
  235. inWhole = true
  236. continue
  237. }
  238. if inWhole {
  239. if count == 3 {
  240. for j := len(nn.group) - 1; j >= 0; j-- {
  241. b = append(b, nn.group[j])
  242. }
  243. count = 1
  244. } else {
  245. count++
  246. }
  247. }
  248. b = append(b, s[i])
  249. }
  250. if num < 0 {
  251. for j := len(nn.minus) - 1; j >= 0; j-- {
  252. b = append(b, nn.minus[j])
  253. }
  254. }
  255. // reverse
  256. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  257. b[i], b[j] = b[j], b[i]
  258. }
  259. if int(v) < 2 {
  260. if v == 0 {
  261. b = append(b, nn.decimal...)
  262. }
  263. for i := 0; i < 2-int(v); i++ {
  264. b = append(b, '0')
  265. }
  266. }
  267. b = append(b, nn.currencyPositiveSuffix...)
  268. b = append(b, symbol...)
  269. return string(b)
  270. }
  271. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'nn'
  272. // in accounting notation.
  273. func (nn *nn) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  274. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  275. symbol := nn.currencies[currency]
  276. l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  277. count := 0
  278. inWhole := v == 0
  279. b := make([]byte, 0, l)
  280. for i := len(s) - 1; i >= 0; i-- {
  281. if s[i] == '.' {
  282. b = append(b, nn.decimal[0])
  283. inWhole = true
  284. continue
  285. }
  286. if inWhole {
  287. if count == 3 {
  288. for j := len(nn.group) - 1; j >= 0; j-- {
  289. b = append(b, nn.group[j])
  290. }
  291. count = 1
  292. } else {
  293. count++
  294. }
  295. }
  296. b = append(b, s[i])
  297. }
  298. if num < 0 {
  299. for j := len(nn.minus) - 1; j >= 0; j-- {
  300. b = append(b, nn.minus[j])
  301. }
  302. }
  303. // reverse
  304. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  305. b[i], b[j] = b[j], b[i]
  306. }
  307. if int(v) < 2 {
  308. if v == 0 {
  309. b = append(b, nn.decimal...)
  310. }
  311. for i := 0; i < 2-int(v); i++ {
  312. b = append(b, '0')
  313. }
  314. }
  315. if num < 0 {
  316. b = append(b, nn.currencyNegativeSuffix...)
  317. b = append(b, symbol...)
  318. } else {
  319. b = append(b, nn.currencyPositiveSuffix...)
  320. b = append(b, symbol...)
  321. }
  322. return string(b)
  323. }
  324. // FmtDateShort returns the short date representation of 't' for 'nn'
  325. func (nn *nn) 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{0x2e}...)
  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{0x2e}...)
  337. b = strconv.AppendInt(b, int64(t.Year()), 10)
  338. return string(b)
  339. }
  340. // FmtDateMedium returns the medium date representation of 't' for 'nn'
  341. func (nn *nn) FmtDateMedium(t time.Time) string {
  342. b := make([]byte, 0, 32)
  343. b = strconv.AppendInt(b, int64(t.Day()), 10)
  344. b = append(b, []byte{0x2e, 0x20}...)
  345. b = append(b, nn.monthsAbbreviated[t.Month()]...)
  346. b = append(b, []byte{0x20}...)
  347. b = strconv.AppendInt(b, int64(t.Year()), 10)
  348. return string(b)
  349. }
  350. // FmtDateLong returns the long date representation of 't' for 'nn'
  351. func (nn *nn) FmtDateLong(t time.Time) string {
  352. b := make([]byte, 0, 32)
  353. b = strconv.AppendInt(b, int64(t.Day()), 10)
  354. b = append(b, []byte{0x2e, 0x20}...)
  355. b = append(b, nn.monthsWide[t.Month()]...)
  356. b = append(b, []byte{0x20}...)
  357. b = strconv.AppendInt(b, int64(t.Year()), 10)
  358. return string(b)
  359. }
  360. // FmtDateFull returns the full date representation of 't' for 'nn'
  361. func (nn *nn) FmtDateFull(t time.Time) string {
  362. b := make([]byte, 0, 32)
  363. b = append(b, nn.daysWide[t.Weekday()]...)
  364. b = append(b, []byte{0x20}...)
  365. b = strconv.AppendInt(b, int64(t.Day()), 10)
  366. b = append(b, []byte{0x2e, 0x20}...)
  367. b = append(b, nn.monthsWide[t.Month()]...)
  368. b = append(b, []byte{0x20}...)
  369. b = strconv.AppendInt(b, int64(t.Year()), 10)
  370. return string(b)
  371. }
  372. // FmtTimeShort returns the short time representation of 't' for 'nn'
  373. func (nn *nn) FmtTimeShort(t time.Time) string {
  374. b := make([]byte, 0, 32)
  375. if t.Hour() < 10 {
  376. b = append(b, '0')
  377. }
  378. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  379. b = append(b, []byte{0x2e}...)
  380. if t.Minute() < 10 {
  381. b = append(b, '0')
  382. }
  383. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  384. return string(b)
  385. }
  386. // FmtTimeMedium returns the medium time representation of 't' for 'nn'
  387. func (nn *nn) FmtTimeMedium(t time.Time) string {
  388. b := make([]byte, 0, 32)
  389. if t.Hour() < 10 {
  390. b = append(b, '0')
  391. }
  392. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  393. b = append(b, []byte{0x2e}...)
  394. if t.Minute() < 10 {
  395. b = append(b, '0')
  396. }
  397. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  398. b = append(b, []byte{0x2e}...)
  399. if t.Second() < 10 {
  400. b = append(b, '0')
  401. }
  402. b = strconv.AppendInt(b, int64(t.Second()), 10)
  403. return string(b)
  404. }
  405. // FmtTimeLong returns the long time representation of 't' for 'nn'
  406. func (nn *nn) FmtTimeLong(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. b = append(b, []byte{0x20}...)
  423. tz, _ := t.Zone()
  424. b = append(b, tz...)
  425. return string(b)
  426. }
  427. // FmtTimeFull returns the full time representation of 't' for 'nn'
  428. func (nn *nn) FmtTimeFull(t time.Time) string {
  429. b := make([]byte, 0, 32)
  430. b = append(b, []byte{0x27, 0x6b, 0x6c, 0x27, 0x2e, 0x20}...)
  431. if t.Hour() < 10 {
  432. b = append(b, '0')
  433. }
  434. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  435. b = append(b, []byte{0x2e}...)
  436. if t.Minute() < 10 {
  437. b = append(b, '0')
  438. }
  439. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  440. b = append(b, []byte{0x2e}...)
  441. if t.Second() < 10 {
  442. b = append(b, '0')
  443. }
  444. b = strconv.AppendInt(b, int64(t.Second()), 10)
  445. b = append(b, []byte{0x20}...)
  446. tz, _ := t.Zone()
  447. if btz, ok := nn.timezones[tz]; ok {
  448. b = append(b, btz...)
  449. } else {
  450. b = append(b, tz...)
  451. }
  452. return string(b)
  453. }