nus.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package nus
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type nus 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. currencyNegativePrefix string
  23. currencyNegativeSuffix string
  24. monthsAbbreviated []string
  25. monthsNarrow []string
  26. monthsWide []string
  27. daysAbbreviated []string
  28. daysNarrow []string
  29. daysShort []string
  30. daysWide []string
  31. periodsAbbreviated []string
  32. periodsNarrow []string
  33. periodsShort []string
  34. periodsWide []string
  35. erasAbbreviated []string
  36. erasNarrow []string
  37. erasWide []string
  38. timezones map[string]string
  39. }
  40. // New returns a new instance of translator for the 'nus' locale
  41. func New() locales.Translator {
  42. return &nus{
  43. locale: "nus",
  44. pluralsCardinal: nil,
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  47. decimal: ".",
  48. group: ",",
  49. timeSeparator: ":",
  50. 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 ", "GB£", "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 ", "NOK ", "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 ", "£", "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 "},
  51. currencyNegativePrefix: "(",
  52. currencyNegativeSuffix: ")",
  53. monthsAbbreviated: []string{"", "Tiop", "Pɛt", "Duɔ̱ɔ̱", "Guak", "Duä", "Kor", "Pay", "Thoo", "Tɛɛ", "Laa", "Kur", "Tid"},
  54. monthsNarrow: []string{"", "T", "P", "D", "G", "D", "K", "P", "T", "T", "L", "K", "T"},
  55. monthsWide: []string{"", "Tiop thar pɛt", "Pɛt", "Duɔ̱ɔ̱ŋ", "Guak", "Duät", "Kornyoot", "Pay yie̱tni", "Tho̱o̱r", "Tɛɛr", "Laath", "Kur", "Tio̱p in di̱i̱t"},
  56. daysAbbreviated: []string{"Cäŋ", "Jiec", "Rɛw", "Diɔ̱k", "Ŋuaan", "Dhieec", "Bäkɛl"},
  57. daysNarrow: []string{"C", "J", "R", "D", "Ŋ", "D", "B"},
  58. daysWide: []string{"Cäŋ kuɔth", "Jiec la̱t", "Rɛw lätni", "Diɔ̱k lätni", "Ŋuaan lätni", "Dhieec lätni", "Bäkɛl lätni"},
  59. periodsAbbreviated: []string{"RW", "TŊ"},
  60. periodsWide: []string{"RW", "TŊ"},
  61. erasAbbreviated: []string{"AY", "ƐY"},
  62. erasNarrow: []string{"", ""},
  63. erasWide: []string{"A ka̱n Yecu ni dap", "Ɛ ca Yecu dap"},
  64. timezones: map[string]string{"JST": "JST", "ACWST": "ACWST", "AST": "AST", "WITA": "WITA", "MYT": "MYT", "CDT": "CDT", "UYT": "UYT", "HKST": "HKST", "JDT": "JDT", "LHST": "LHST", "PDT": "PDT", "LHDT": "LHDT", "MESZ": "MESZ", "NZST": "NZST", "WART": "WART", "SRT": "SRT", "AKST": "AKST", "ChST": "ChST", "EST": "EST", "WAT": "WAT", "ACWDT": "ACWDT", "ARST": "ARST", "CST": "CST", "UYST": "UYST", "CLT": "CLT", "WESZ": "WESZ", "WARST": "WARST", "WIB": "WIB", "OEZ": "OEZ", "AEST": "AEST", "TMST": "TMST", "NZDT": "NZDT", "CHAST": "CHAST", "OESZ": "OESZ", "HNT": "HNT", "MEZ": "MEZ", "HAST": "HAST", "HKT": "HKT", "WIT": "WIT", "AKDT": "AKDT", "AWST": "AWST", "GYT": "GYT", "COT": "COT", "IST": "IST", "ACST": "ACST", "HAT": "HAT", "CLST": "CLST", "AWDT": "AWDT", "SAST": "SAST", "EAT": "EAT", "PST": "PST", "ACDT": "ACDT", "ART": "ART", "BOT": "BOT", "CAT": "CAT", "COST": "COST", "BT": "BT", "WAST": "WAST", "CHADT": "CHADT", "HADT": "HADT", "SGT": "SGT", "AEDT": "AEDT", "ADT": "ADT", "MST": "MST", "WEZ": "WEZ", "VET": "VET", "∅∅∅": "∅∅∅", "GFT": "GFT", "MDT": "MDT", "TMT": "TMT", "EDT": "EDT", "ECT": "ECT", "GMT": "GMT"},
  65. }
  66. }
  67. // Locale returns the current translators string locale
  68. func (nus *nus) Locale() string {
  69. return nus.locale
  70. }
  71. // PluralsCardinal returns the list of cardinal plural rules associated with 'nus'
  72. func (nus *nus) PluralsCardinal() []locales.PluralRule {
  73. return nus.pluralsCardinal
  74. }
  75. // PluralsOrdinal returns the list of ordinal plural rules associated with 'nus'
  76. func (nus *nus) PluralsOrdinal() []locales.PluralRule {
  77. return nus.pluralsOrdinal
  78. }
  79. // PluralsRange returns the list of range plural rules associated with 'nus'
  80. func (nus *nus) PluralsRange() []locales.PluralRule {
  81. return nus.pluralsRange
  82. }
  83. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'nus'
  84. func (nus *nus) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  85. return locales.PluralRuleUnknown
  86. }
  87. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'nus'
  88. func (nus *nus) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  89. return locales.PluralRuleUnknown
  90. }
  91. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'nus'
  92. func (nus *nus) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  93. return locales.PluralRuleUnknown
  94. }
  95. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  96. func (nus *nus) MonthAbbreviated(month time.Month) string {
  97. return nus.monthsAbbreviated[month]
  98. }
  99. // MonthsAbbreviated returns the locales abbreviated months
  100. func (nus *nus) MonthsAbbreviated() []string {
  101. return nus.monthsAbbreviated[1:]
  102. }
  103. // MonthNarrow returns the locales narrow month given the 'month' provided
  104. func (nus *nus) MonthNarrow(month time.Month) string {
  105. return nus.monthsNarrow[month]
  106. }
  107. // MonthsNarrow returns the locales narrow months
  108. func (nus *nus) MonthsNarrow() []string {
  109. return nus.monthsNarrow[1:]
  110. }
  111. // MonthWide returns the locales wide month given the 'month' provided
  112. func (nus *nus) MonthWide(month time.Month) string {
  113. return nus.monthsWide[month]
  114. }
  115. // MonthsWide returns the locales wide months
  116. func (nus *nus) MonthsWide() []string {
  117. return nus.monthsWide[1:]
  118. }
  119. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  120. func (nus *nus) WeekdayAbbreviated(weekday time.Weekday) string {
  121. return nus.daysAbbreviated[weekday]
  122. }
  123. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  124. func (nus *nus) WeekdaysAbbreviated() []string {
  125. return nus.daysAbbreviated
  126. }
  127. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  128. func (nus *nus) WeekdayNarrow(weekday time.Weekday) string {
  129. return nus.daysNarrow[weekday]
  130. }
  131. // WeekdaysNarrow returns the locales narrow weekdays
  132. func (nus *nus) WeekdaysNarrow() []string {
  133. return nus.daysNarrow
  134. }
  135. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  136. func (nus *nus) WeekdayShort(weekday time.Weekday) string {
  137. return nus.daysShort[weekday]
  138. }
  139. // WeekdaysShort returns the locales short weekdays
  140. func (nus *nus) WeekdaysShort() []string {
  141. return nus.daysShort
  142. }
  143. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  144. func (nus *nus) WeekdayWide(weekday time.Weekday) string {
  145. return nus.daysWide[weekday]
  146. }
  147. // WeekdaysWide returns the locales wide weekdays
  148. func (nus *nus) WeekdaysWide() []string {
  149. return nus.daysWide
  150. }
  151. // FmtNumber returns 'num' with digits/precision of 'v' for 'nus' and handles both Whole and Real numbers based on 'v'
  152. func (nus *nus) FmtNumber(num float64, v uint64) string {
  153. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  154. l := len(s) + 1 + 1*len(s[:len(s)-int(v)-1])/3
  155. count := 0
  156. inWhole := v == 0
  157. b := make([]byte, 0, l)
  158. for i := len(s) - 1; i >= 0; i-- {
  159. if s[i] == '.' {
  160. b = append(b, nus.decimal[0])
  161. inWhole = true
  162. continue
  163. }
  164. if inWhole {
  165. if count == 3 {
  166. b = append(b, nus.group[0])
  167. count = 1
  168. } else {
  169. count++
  170. }
  171. }
  172. b = append(b, s[i])
  173. }
  174. if num < 0 {
  175. b = append(b, nus.minus[0])
  176. }
  177. // reverse
  178. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  179. b[i], b[j] = b[j], b[i]
  180. }
  181. return string(b)
  182. }
  183. // FmtPercent returns 'num' with digits/precision of 'v' for 'nus' and handles both Whole and Real numbers based on 'v'
  184. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  185. func (nus *nus) FmtPercent(num float64, v uint64) string {
  186. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  187. l := len(s) + 1
  188. b := make([]byte, 0, l)
  189. for i := len(s) - 1; i >= 0; i-- {
  190. if s[i] == '.' {
  191. b = append(b, nus.decimal[0])
  192. continue
  193. }
  194. b = append(b, s[i])
  195. }
  196. if num < 0 {
  197. b = append(b, nus.minus[0])
  198. }
  199. // reverse
  200. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  201. b[i], b[j] = b[j], b[i]
  202. }
  203. b = append(b, nus.percent...)
  204. return string(b)
  205. }
  206. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'nus'
  207. func (nus *nus) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  208. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  209. symbol := nus.currencies[currency]
  210. l := len(s) + len(symbol) + 1 + 1*len(s[:len(s)-int(v)-1])/3
  211. count := 0
  212. inWhole := v == 0
  213. b := make([]byte, 0, l)
  214. for i := len(s) - 1; i >= 0; i-- {
  215. if s[i] == '.' {
  216. b = append(b, nus.decimal[0])
  217. inWhole = true
  218. continue
  219. }
  220. if inWhole {
  221. if count == 3 {
  222. b = append(b, nus.group[0])
  223. count = 1
  224. } else {
  225. count++
  226. }
  227. }
  228. b = append(b, s[i])
  229. }
  230. for j := len(symbol) - 1; j >= 0; j-- {
  231. b = append(b, symbol[j])
  232. }
  233. if num < 0 {
  234. b = append(b, nus.minus[0])
  235. }
  236. // reverse
  237. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  238. b[i], b[j] = b[j], b[i]
  239. }
  240. if int(v) < 2 {
  241. if v == 0 {
  242. b = append(b, nus.decimal...)
  243. }
  244. for i := 0; i < 2-int(v); i++ {
  245. b = append(b, '0')
  246. }
  247. }
  248. return string(b)
  249. }
  250. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'nus'
  251. // in accounting notation.
  252. func (nus *nus) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  253. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  254. symbol := nus.currencies[currency]
  255. l := len(s) + len(symbol) + 3 + 1*len(s[:len(s)-int(v)-1])/3
  256. count := 0
  257. inWhole := v == 0
  258. b := make([]byte, 0, l)
  259. for i := len(s) - 1; i >= 0; i-- {
  260. if s[i] == '.' {
  261. b = append(b, nus.decimal[0])
  262. inWhole = true
  263. continue
  264. }
  265. if inWhole {
  266. if count == 3 {
  267. b = append(b, nus.group[0])
  268. count = 1
  269. } else {
  270. count++
  271. }
  272. }
  273. b = append(b, s[i])
  274. }
  275. if num < 0 {
  276. for j := len(symbol) - 1; j >= 0; j-- {
  277. b = append(b, symbol[j])
  278. }
  279. b = append(b, nus.currencyNegativePrefix[0])
  280. } else {
  281. for j := len(symbol) - 1; j >= 0; j-- {
  282. b = append(b, symbol[j])
  283. }
  284. }
  285. // reverse
  286. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  287. b[i], b[j] = b[j], b[i]
  288. }
  289. if int(v) < 2 {
  290. if v == 0 {
  291. b = append(b, nus.decimal...)
  292. }
  293. for i := 0; i < 2-int(v); i++ {
  294. b = append(b, '0')
  295. }
  296. }
  297. if num < 0 {
  298. b = append(b, nus.currencyNegativeSuffix...)
  299. }
  300. return string(b)
  301. }
  302. // FmtDateShort returns the short date representation of 't' for 'nus'
  303. func (nus *nus) FmtDateShort(t time.Time) string {
  304. b := make([]byte, 0, 32)
  305. b = strconv.AppendInt(b, int64(t.Day()), 10)
  306. b = append(b, []byte{0x2f}...)
  307. if t.Month() < 10 {
  308. b = append(b, '0')
  309. }
  310. b = strconv.AppendInt(b, int64(t.Month()), 10)
  311. b = append(b, []byte{0x2f}...)
  312. b = strconv.AppendInt(b, int64(t.Year()), 10)
  313. return string(b)
  314. }
  315. // FmtDateMedium returns the medium date representation of 't' for 'nus'
  316. func (nus *nus) FmtDateMedium(t time.Time) string {
  317. b := make([]byte, 0, 32)
  318. b = strconv.AppendInt(b, int64(t.Day()), 10)
  319. b = append(b, []byte{0x20}...)
  320. b = append(b, nus.monthsAbbreviated[t.Month()]...)
  321. b = append(b, []byte{0x20}...)
  322. b = strconv.AppendInt(b, int64(t.Year()), 10)
  323. return string(b)
  324. }
  325. // FmtDateLong returns the long date representation of 't' for 'nus'
  326. func (nus *nus) FmtDateLong(t time.Time) string {
  327. b := make([]byte, 0, 32)
  328. b = strconv.AppendInt(b, int64(t.Day()), 10)
  329. b = append(b, []byte{0x20}...)
  330. b = append(b, nus.monthsWide[t.Month()]...)
  331. b = append(b, []byte{0x20}...)
  332. b = strconv.AppendInt(b, int64(t.Year()), 10)
  333. return string(b)
  334. }
  335. // FmtDateFull returns the full date representation of 't' for 'nus'
  336. func (nus *nus) FmtDateFull(t time.Time) string {
  337. b := make([]byte, 0, 32)
  338. b = append(b, nus.daysWide[t.Weekday()]...)
  339. b = append(b, []byte{0x20}...)
  340. b = strconv.AppendInt(b, int64(t.Day()), 10)
  341. b = append(b, []byte{0x20}...)
  342. b = append(b, nus.monthsWide[t.Month()]...)
  343. b = append(b, []byte{0x20}...)
  344. b = strconv.AppendInt(b, int64(t.Year()), 10)
  345. return string(b)
  346. }
  347. // FmtTimeShort returns the short time representation of 't' for 'nus'
  348. func (nus *nus) FmtTimeShort(t time.Time) string {
  349. b := make([]byte, 0, 32)
  350. h := t.Hour()
  351. if h > 12 {
  352. h -= 12
  353. }
  354. b = strconv.AppendInt(b, int64(h), 10)
  355. b = append(b, nus.timeSeparator...)
  356. if t.Minute() < 10 {
  357. b = append(b, '0')
  358. }
  359. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  360. b = append(b, []byte{0x20}...)
  361. if t.Hour() < 12 {
  362. b = append(b, nus.periodsAbbreviated[0]...)
  363. } else {
  364. b = append(b, nus.periodsAbbreviated[1]...)
  365. }
  366. return string(b)
  367. }
  368. // FmtTimeMedium returns the medium time representation of 't' for 'nus'
  369. func (nus *nus) FmtTimeMedium(t time.Time) string {
  370. b := make([]byte, 0, 32)
  371. h := t.Hour()
  372. if h > 12 {
  373. h -= 12
  374. }
  375. b = strconv.AppendInt(b, int64(h), 10)
  376. b = append(b, nus.timeSeparator...)
  377. if t.Minute() < 10 {
  378. b = append(b, '0')
  379. }
  380. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  381. b = append(b, nus.timeSeparator...)
  382. if t.Second() < 10 {
  383. b = append(b, '0')
  384. }
  385. b = strconv.AppendInt(b, int64(t.Second()), 10)
  386. b = append(b, []byte{0x20}...)
  387. if t.Hour() < 12 {
  388. b = append(b, nus.periodsAbbreviated[0]...)
  389. } else {
  390. b = append(b, nus.periodsAbbreviated[1]...)
  391. }
  392. return string(b)
  393. }
  394. // FmtTimeLong returns the long time representation of 't' for 'nus'
  395. func (nus *nus) FmtTimeLong(t time.Time) string {
  396. b := make([]byte, 0, 32)
  397. tz, _ := t.Zone()
  398. b = append(b, tz...)
  399. b = append(b, []byte{0x20}...)
  400. h := t.Hour()
  401. if h > 12 {
  402. h -= 12
  403. }
  404. b = strconv.AppendInt(b, int64(h), 10)
  405. b = append(b, nus.timeSeparator...)
  406. if t.Minute() < 10 {
  407. b = append(b, '0')
  408. }
  409. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  410. b = append(b, nus.timeSeparator...)
  411. if t.Second() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Second()), 10)
  415. b = append(b, []byte{0x20}...)
  416. if t.Hour() < 12 {
  417. b = append(b, nus.periodsAbbreviated[0]...)
  418. } else {
  419. b = append(b, nus.periodsAbbreviated[1]...)
  420. }
  421. return string(b)
  422. }
  423. // FmtTimeFull returns the full time representation of 't' for 'nus'
  424. func (nus *nus) FmtTimeFull(t time.Time) string {
  425. b := make([]byte, 0, 32)
  426. tz, _ := t.Zone()
  427. if btz, ok := nus.timezones[tz]; ok {
  428. b = append(b, btz...)
  429. } else {
  430. b = append(b, tz...)
  431. }
  432. b = append(b, []byte{0x20}...)
  433. h := t.Hour()
  434. if h > 12 {
  435. h -= 12
  436. }
  437. b = strconv.AppendInt(b, int64(h), 10)
  438. b = append(b, nus.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, nus.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. if t.Hour() < 12 {
  450. b = append(b, nus.periodsAbbreviated[0]...)
  451. } else {
  452. b = append(b, nus.periodsAbbreviated[1]...)
  453. }
  454. return string(b)
  455. }