rm.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. package rm
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type rm 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 'rm' locale
  42. func New() locales.Translator {
  43. return &rm{
  44. locale: "rm",
  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", "A$", "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", "CA$", "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", "MX$", "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", "SSP", "STD", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "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{"", "schan.", "favr.", "mars", "avr.", "matg", "zercl.", "fan.", "avust", "sett.", "oct.", "nov.", "dec."},
  60. monthsNarrow: []string{"", "S", "F", "M", "A", "M", "Z", "F", "A", "S", "O", "N", "D"},
  61. monthsWide: []string{"", "schaner", "favrer", "mars", "avrigl", "matg", "zercladur", "fanadur", "avust", "settember", "october", "november", "december"},
  62. daysAbbreviated: []string{"du", "gli", "ma", "me", "gie", "ve", "so"},
  63. daysNarrow: []string{"D", "G", "M", "M", "G", "V", "S"},
  64. daysWide: []string{"dumengia", "glindesdi", "mardi", "mesemna", "gievgia", "venderdi", "sonda"},
  65. periodsAbbreviated: []string{"am", "sm"},
  66. periodsWide: []string{"am", "sm"},
  67. erasAbbreviated: []string{"av. Cr.", "s. Cr."},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"avant Cristus", "suenter Cristus"},
  70. timezones: map[string]string{"EST": "EST", "∅∅∅": "∅∅∅", "VET": "VET", "JDT": "JDT", "EAT": "EAT", "AWST": "AWST", "ChST": "ChST", "WART": "WART", "COST": "COST", "HNT": "HNT", "CST": "CST", "CAT": "CAT", "PST": "PST", "ART": "ART", "MEZ": "MEZ", "TMT": "TMT", "BT": "BT", "MYT": "MYT", "UYT": "UYT", "ADT": "ADT", "OESZ": "OESZ", "HADT": "HADT", "EDT": "EDT", "LHST": "LHST", "NZDT": "NZDT", "HAST": "HAST", "HAT": "HAT", "GYT": "GYT", "WEZ": "WEZ", "WIB": "WIB", "MDT": "MDT", "COT": "COT", "GFT": "GFT", "ECT": "ECT", "AKST": "AKST", "AST": "AST", "MESZ": "MESZ", "CHADT": "CHADT", "WITA": "WITA", "SAST": "SAST", "LHDT": "LHDT", "MST": "MST", "CHAST": "CHAST", "CLST": "CLST", "AWDT": "AWDT", "ACST": "ACST", "JST": "JST", "HKST": "HKST", "AEST": "AEST", "ACWST": "ACWST", "UYST": "UYST", "ACDT": "ACDT", "TMST": "TMST", "AEDT": "AEDT", "WIT": "WIT", "HKT": "HKT", "WAT": "WAT", "SGT": "SGT", "ARST": "ARST", "CDT": "CDT", "WESZ": "WESZ", "SRT": "SRT", "AKDT": "AKDT", "IST": "IST", "OEZ": "OEZ", "PDT": "PDT", "WARST": "WARST", "GMT": "GMT", "ACWDT": "ACWDT", "BOT": "BOT", "WAST": "WAST", "NZST": "NZST", "CLT": "CLT"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (rm *rm) Locale() string {
  75. return rm.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'rm'
  78. func (rm *rm) PluralsCardinal() []locales.PluralRule {
  79. return rm.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'rm'
  82. func (rm *rm) PluralsOrdinal() []locales.PluralRule {
  83. return rm.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'rm'
  86. func (rm *rm) PluralsRange() []locales.PluralRule {
  87. return rm.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'rm'
  90. func (rm *rm) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. if n == 1 {
  93. return locales.PluralRuleOne
  94. }
  95. return locales.PluralRuleOther
  96. }
  97. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'rm'
  98. func (rm *rm) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  99. return locales.PluralRuleUnknown
  100. }
  101. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'rm'
  102. func (rm *rm) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  103. return locales.PluralRuleUnknown
  104. }
  105. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  106. func (rm *rm) MonthAbbreviated(month time.Month) string {
  107. return rm.monthsAbbreviated[month]
  108. }
  109. // MonthsAbbreviated returns the locales abbreviated months
  110. func (rm *rm) MonthsAbbreviated() []string {
  111. return rm.monthsAbbreviated[1:]
  112. }
  113. // MonthNarrow returns the locales narrow month given the 'month' provided
  114. func (rm *rm) MonthNarrow(month time.Month) string {
  115. return rm.monthsNarrow[month]
  116. }
  117. // MonthsNarrow returns the locales narrow months
  118. func (rm *rm) MonthsNarrow() []string {
  119. return rm.monthsNarrow[1:]
  120. }
  121. // MonthWide returns the locales wide month given the 'month' provided
  122. func (rm *rm) MonthWide(month time.Month) string {
  123. return rm.monthsWide[month]
  124. }
  125. // MonthsWide returns the locales wide months
  126. func (rm *rm) MonthsWide() []string {
  127. return rm.monthsWide[1:]
  128. }
  129. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  130. func (rm *rm) WeekdayAbbreviated(weekday time.Weekday) string {
  131. return rm.daysAbbreviated[weekday]
  132. }
  133. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  134. func (rm *rm) WeekdaysAbbreviated() []string {
  135. return rm.daysAbbreviated
  136. }
  137. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  138. func (rm *rm) WeekdayNarrow(weekday time.Weekday) string {
  139. return rm.daysNarrow[weekday]
  140. }
  141. // WeekdaysNarrow returns the locales narrow weekdays
  142. func (rm *rm) WeekdaysNarrow() []string {
  143. return rm.daysNarrow
  144. }
  145. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  146. func (rm *rm) WeekdayShort(weekday time.Weekday) string {
  147. return rm.daysShort[weekday]
  148. }
  149. // WeekdaysShort returns the locales short weekdays
  150. func (rm *rm) WeekdaysShort() []string {
  151. return rm.daysShort
  152. }
  153. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  154. func (rm *rm) WeekdayWide(weekday time.Weekday) string {
  155. return rm.daysWide[weekday]
  156. }
  157. // WeekdaysWide returns the locales wide weekdays
  158. func (rm *rm) WeekdaysWide() []string {
  159. return rm.daysWide
  160. }
  161. // FmtNumber returns 'num' with digits/precision of 'v' for 'rm' and handles both Whole and Real numbers based on 'v'
  162. func (rm *rm) FmtNumber(num float64, v uint64) string {
  163. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  164. l := len(s) + 4 + 3*len(s[:len(s)-int(v)-1])/3
  165. count := 0
  166. inWhole := v == 0
  167. b := make([]byte, 0, l)
  168. for i := len(s) - 1; i >= 0; i-- {
  169. if s[i] == '.' {
  170. b = append(b, rm.decimal[0])
  171. inWhole = true
  172. continue
  173. }
  174. if inWhole {
  175. if count == 3 {
  176. for j := len(rm.group) - 1; j >= 0; j-- {
  177. b = append(b, rm.group[j])
  178. }
  179. count = 1
  180. } else {
  181. count++
  182. }
  183. }
  184. b = append(b, s[i])
  185. }
  186. if num < 0 {
  187. for j := len(rm.minus) - 1; j >= 0; j-- {
  188. b = append(b, rm.minus[j])
  189. }
  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 'rm' 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 (rm *rm) FmtPercent(num float64, v uint64) string {
  200. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  201. l := len(s) + 7
  202. b := make([]byte, 0, l)
  203. for i := len(s) - 1; i >= 0; i-- {
  204. if s[i] == '.' {
  205. b = append(b, rm.decimal[0])
  206. continue
  207. }
  208. b = append(b, s[i])
  209. }
  210. if num < 0 {
  211. for j := len(rm.minus) - 1; j >= 0; j-- {
  212. b = append(b, rm.minus[j])
  213. }
  214. }
  215. // reverse
  216. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  217. b[i], b[j] = b[j], b[i]
  218. }
  219. b = append(b, rm.percentSuffix...)
  220. b = append(b, rm.percent...)
  221. return string(b)
  222. }
  223. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'rm'
  224. func (rm *rm) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  225. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  226. symbol := rm.currencies[currency]
  227. l := len(s) + len(symbol) + 6 + 3*len(s[:len(s)-int(v)-1])/3
  228. count := 0
  229. inWhole := v == 0
  230. b := make([]byte, 0, l)
  231. for i := len(s) - 1; i >= 0; i-- {
  232. if s[i] == '.' {
  233. b = append(b, rm.decimal[0])
  234. inWhole = true
  235. continue
  236. }
  237. if inWhole {
  238. if count == 3 {
  239. for j := len(rm.group) - 1; j >= 0; j-- {
  240. b = append(b, rm.group[j])
  241. }
  242. count = 1
  243. } else {
  244. count++
  245. }
  246. }
  247. b = append(b, s[i])
  248. }
  249. if num < 0 {
  250. for j := len(rm.minus) - 1; j >= 0; j-- {
  251. b = append(b, rm.minus[j])
  252. }
  253. }
  254. // reverse
  255. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  256. b[i], b[j] = b[j], b[i]
  257. }
  258. if int(v) < 2 {
  259. if v == 0 {
  260. b = append(b, rm.decimal...)
  261. }
  262. for i := 0; i < 2-int(v); i++ {
  263. b = append(b, '0')
  264. }
  265. }
  266. b = append(b, rm.currencyPositiveSuffix...)
  267. b = append(b, symbol...)
  268. return string(b)
  269. }
  270. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'rm'
  271. // in accounting notation.
  272. func (rm *rm) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  273. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  274. symbol := rm.currencies[currency]
  275. l := len(s) + len(symbol) + 6 + 3*len(s[:len(s)-int(v)-1])/3
  276. count := 0
  277. inWhole := v == 0
  278. b := make([]byte, 0, l)
  279. for i := len(s) - 1; i >= 0; i-- {
  280. if s[i] == '.' {
  281. b = append(b, rm.decimal[0])
  282. inWhole = true
  283. continue
  284. }
  285. if inWhole {
  286. if count == 3 {
  287. for j := len(rm.group) - 1; j >= 0; j-- {
  288. b = append(b, rm.group[j])
  289. }
  290. count = 1
  291. } else {
  292. count++
  293. }
  294. }
  295. b = append(b, s[i])
  296. }
  297. if num < 0 {
  298. for j := len(rm.minus) - 1; j >= 0; j-- {
  299. b = append(b, rm.minus[j])
  300. }
  301. }
  302. // reverse
  303. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  304. b[i], b[j] = b[j], b[i]
  305. }
  306. if int(v) < 2 {
  307. if v == 0 {
  308. b = append(b, rm.decimal...)
  309. }
  310. for i := 0; i < 2-int(v); i++ {
  311. b = append(b, '0')
  312. }
  313. }
  314. if num < 0 {
  315. b = append(b, rm.currencyNegativeSuffix...)
  316. b = append(b, symbol...)
  317. } else {
  318. b = append(b, rm.currencyPositiveSuffix...)
  319. b = append(b, symbol...)
  320. }
  321. return string(b)
  322. }
  323. // FmtDateShort returns the short date representation of 't' for 'rm'
  324. func (rm *rm) FmtDateShort(t time.Time) string {
  325. b := make([]byte, 0, 32)
  326. if t.Day() < 10 {
  327. b = append(b, '0')
  328. }
  329. b = strconv.AppendInt(b, int64(t.Day()), 10)
  330. b = append(b, []byte{0x2d}...)
  331. if t.Month() < 10 {
  332. b = append(b, '0')
  333. }
  334. b = strconv.AppendInt(b, int64(t.Month()), 10)
  335. b = append(b, []byte{0x2d}...)
  336. if t.Year() > 9 {
  337. b = append(b, strconv.Itoa(t.Year())[2:]...)
  338. } else {
  339. b = append(b, strconv.Itoa(t.Year())[1:]...)
  340. }
  341. return string(b)
  342. }
  343. // FmtDateMedium returns the medium date representation of 't' for 'rm'
  344. func (rm *rm) FmtDateMedium(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{0x2d}...)
  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{0x2d}...)
  356. b = strconv.AppendInt(b, int64(t.Year()), 10)
  357. return string(b)
  358. }
  359. // FmtDateLong returns the long date representation of 't' for 'rm'
  360. func (rm *rm) FmtDateLong(t time.Time) string {
  361. b := make([]byte, 0, 32)
  362. b = strconv.AppendInt(b, int64(t.Day()), 10)
  363. b = append(b, []byte{0x20, 0x64, 0x61}...)
  364. b = append(b, []byte{0x20}...)
  365. b = append(b, rm.monthsWide[t.Month()]...)
  366. b = append(b, []byte{0x20}...)
  367. b = strconv.AppendInt(b, int64(t.Year()), 10)
  368. return string(b)
  369. }
  370. // FmtDateFull returns the full date representation of 't' for 'rm'
  371. func (rm *rm) FmtDateFull(t time.Time) string {
  372. b := make([]byte, 0, 32)
  373. b = append(b, rm.daysWide[t.Weekday()]...)
  374. b = append(b, []byte{0x2c, 0x20, 0x69, 0x6c, 0x73}...)
  375. b = append(b, []byte{0x20}...)
  376. b = strconv.AppendInt(b, int64(t.Day()), 10)
  377. b = append(b, []byte{0x20, 0x64, 0x61}...)
  378. b = append(b, []byte{0x20}...)
  379. b = append(b, rm.monthsWide[t.Month()]...)
  380. b = append(b, []byte{0x20}...)
  381. b = strconv.AppendInt(b, int64(t.Year()), 10)
  382. return string(b)
  383. }
  384. // FmtTimeShort returns the short time representation of 't' for 'rm'
  385. func (rm *rm) FmtTimeShort(t time.Time) string {
  386. b := make([]byte, 0, 32)
  387. if t.Hour() < 10 {
  388. b = append(b, '0')
  389. }
  390. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  391. b = append(b, rm.timeSeparator...)
  392. if t.Minute() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  396. return string(b)
  397. }
  398. // FmtTimeMedium returns the medium time representation of 't' for 'rm'
  399. func (rm *rm) FmtTimeMedium(t time.Time) string {
  400. b := make([]byte, 0, 32)
  401. if t.Hour() < 10 {
  402. b = append(b, '0')
  403. }
  404. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  405. b = append(b, rm.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, rm.timeSeparator...)
  411. if t.Second() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Second()), 10)
  415. return string(b)
  416. }
  417. // FmtTimeLong returns the long time representation of 't' for 'rm'
  418. func (rm *rm) FmtTimeLong(t time.Time) string {
  419. b := make([]byte, 0, 32)
  420. if t.Hour() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  424. b = append(b, rm.timeSeparator...)
  425. if t.Minute() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  429. b = append(b, rm.timeSeparator...)
  430. if t.Second() < 10 {
  431. b = append(b, '0')
  432. }
  433. b = strconv.AppendInt(b, int64(t.Second()), 10)
  434. b = append(b, []byte{0x20}...)
  435. tz, _ := t.Zone()
  436. b = append(b, tz...)
  437. return string(b)
  438. }
  439. // FmtTimeFull returns the full time representation of 't' for 'rm'
  440. func (rm *rm) FmtTimeFull(t time.Time) string {
  441. b := make([]byte, 0, 32)
  442. if t.Hour() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  446. b = append(b, rm.timeSeparator...)
  447. if t.Minute() < 10 {
  448. b = append(b, '0')
  449. }
  450. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  451. b = append(b, rm.timeSeparator...)
  452. if t.Second() < 10 {
  453. b = append(b, '0')
  454. }
  455. b = strconv.AppendInt(b, int64(t.Second()), 10)
  456. b = append(b, []byte{0x20}...)
  457. tz, _ := t.Zone()
  458. if btz, ok := rm.timezones[tz]; ok {
  459. b = append(b, btz...)
  460. } else {
  461. b = append(b, tz...)
  462. }
  463. return string(b)
  464. }