mt.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. package mt
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type mt 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. monthsAbbreviated []string
  23. monthsNarrow []string
  24. monthsWide []string
  25. daysAbbreviated []string
  26. daysNarrow []string
  27. daysShort []string
  28. daysWide []string
  29. periodsAbbreviated []string
  30. periodsNarrow []string
  31. periodsShort []string
  32. periodsWide []string
  33. erasAbbreviated []string
  34. erasNarrow []string
  35. erasWide []string
  36. timezones map[string]string
  37. }
  38. // New returns a new instance of translator for the 'mt' locale
  39. func New() locales.Translator {
  40. return &mt{
  41. locale: "mt",
  42. pluralsCardinal: []locales.PluralRule{2, 4, 5, 6},
  43. pluralsOrdinal: nil,
  44. pluralsRange: nil,
  45. decimal: ".",
  46. group: ",",
  47. minus: "-",
  48. percent: "%",
  49. perMille: "‰",
  50. timeSeparator: ":",
  51. inifinity: "∞",
  52. 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", "R$", "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", "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", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "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", "Rs", "NZ$", "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", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
  53. monthsAbbreviated: []string{"", "Jan", "Fra", "Mar", "Apr", "Mej", "Ġun", "Lul", "Aww", "Set", "Ott", "Nov", "Diċ"},
  54. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "Ġ", "L", "A", "S", "O", "N", "D"},
  55. monthsWide: []string{"", "Jannar", "Frar", "Marzu", "April", "Mejju", "Ġunju", "Lulju", "Awwissu", "Settembru", "Ottubru", "Novembru", "Diċembru"},
  56. daysAbbreviated: []string{"Ħad", "Tne", "Tli", "Erb", "Ħam", "Ġim", "Sib"},
  57. daysNarrow: []string{"Ħd", "T", "Tl", "Er", "Ħm", "Ġm", "Sb"},
  58. daysShort: []string{"Ħad", "Tne", "Tli", "Erb", "Ħam", "Ġim", "Sib"},
  59. daysWide: []string{"Il-Ħadd", "It-Tnejn", "It-Tlieta", "L-Erbgħa", "Il-Ħamis", "Il-Ġimgħa", "Is-Sibt"},
  60. periodsAbbreviated: []string{"AM", "PM"},
  61. periodsNarrow: []string{"am", "pm"},
  62. periodsWide: []string{"AM", "PM"},
  63. erasAbbreviated: []string{"QK", "WK"},
  64. erasNarrow: []string{"", ""},
  65. erasWide: []string{"Qabel Kristu", "Wara Kristu"},
  66. timezones: map[string]string{"BT": "BT", "NZST": "NZST", "HKST": "HKST", "HAT": "HAT", "SRT": "SRT", "AWST": "AWST", "HNPMX": "HNPMX", "MDT": "MDT", "UYST": "UYST", "WIT": "WIT", "ART": "ART", "ARST": "ARST", "HEEG": "HEEG", "HEPM": "HEPM", "HNCU": "HNCU", "WESZ": "WESZ", "EST": "EST", "SAST": "SAST", "LHST": "LHST", "WITA": "WITA", "OESZ": "OESZ", "CHADT": "CHADT", "CDT": "CDT", "PST": "PST", "HNNOMX": "HNNOMX", "MST": "MST", "JDT": "JDT", "EDT": "EDT", "GFT": "GFT", "AKDT": "AKDT", "SGT": "SGT", "MESZ": "Ħin Ċentrali Ewropew tas-Sajf", "VET": "VET", "∅∅∅": "∅∅∅", "CST": "CST", "AWDT": "AWDT", "EAT": "EAT", "CAT": "CAT", "WIB": "WIB", "NZDT": "NZDT", "WARST": "WARST", "COT": "COT", "AEST": "AEST", "WAT": "WAT", "HNOG": "HNOG", "IST": "IST", "HAST": "HAST", "AST": "AST", "AEDT": "AEDT", "ACWST": "ACWST", "ADT": "ADT", "OEZ": "OEZ", "ACST": "ACST", "CLST": "CLST", "UYT": "UYT", "TMST": "TMST", "HADT": "HADT", "COST": "COST", "GMT": "GMT", "GYT": "GYT", "CHAST": "CHAST", "HECU": "HECU", "CLT": "CLT", "ACWDT": "ACWDT", "HNEG": "HNEG", "MEZ": "Ħin Ċentrali Ewropew Standard", "WAST": "WAST", "BOT": "BOT", "AKST": "AKST", "HEOG": "HEOG", "HNPM": "HNPM", "TMT": "TMT", "PDT": "PDT", "HEPMX": "HEPMX", "MYT": "MYT", "HNT": "HNT", "HENOMX": "HENOMX", "ACDT": "ACDT", "LHDT": "LHDT", "WART": "WART", "HKT": "HKT", "ChST": "ChST", "JST": "JST", "ECT": "ECT", "WEZ": "WEZ"},
  67. }
  68. }
  69. // Locale returns the current translators string locale
  70. func (mt *mt) Locale() string {
  71. return mt.locale
  72. }
  73. // PluralsCardinal returns the list of cardinal plural rules associated with 'mt'
  74. func (mt *mt) PluralsCardinal() []locales.PluralRule {
  75. return mt.pluralsCardinal
  76. }
  77. // PluralsOrdinal returns the list of ordinal plural rules associated with 'mt'
  78. func (mt *mt) PluralsOrdinal() []locales.PluralRule {
  79. return mt.pluralsOrdinal
  80. }
  81. // PluralsRange returns the list of range plural rules associated with 'mt'
  82. func (mt *mt) PluralsRange() []locales.PluralRule {
  83. return mt.pluralsRange
  84. }
  85. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'mt'
  86. func (mt *mt) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  87. n := math.Abs(num)
  88. nMod100 := math.Mod(n, 100)
  89. if n == 1 {
  90. return locales.PluralRuleOne
  91. } else if (n == 0) || (nMod100 >= 2 && nMod100 <= 10) {
  92. return locales.PluralRuleFew
  93. } else if nMod100 >= 11 && nMod100 <= 19 {
  94. return locales.PluralRuleMany
  95. }
  96. return locales.PluralRuleOther
  97. }
  98. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'mt'
  99. func (mt *mt) 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 'mt'
  103. func (mt *mt) 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 (mt *mt) MonthAbbreviated(month time.Month) string {
  108. return mt.monthsAbbreviated[month]
  109. }
  110. // MonthsAbbreviated returns the locales abbreviated months
  111. func (mt *mt) MonthsAbbreviated() []string {
  112. return mt.monthsAbbreviated[1:]
  113. }
  114. // MonthNarrow returns the locales narrow month given the 'month' provided
  115. func (mt *mt) MonthNarrow(month time.Month) string {
  116. return mt.monthsNarrow[month]
  117. }
  118. // MonthsNarrow returns the locales narrow months
  119. func (mt *mt) MonthsNarrow() []string {
  120. return mt.monthsNarrow[1:]
  121. }
  122. // MonthWide returns the locales wide month given the 'month' provided
  123. func (mt *mt) MonthWide(month time.Month) string {
  124. return mt.monthsWide[month]
  125. }
  126. // MonthsWide returns the locales wide months
  127. func (mt *mt) MonthsWide() []string {
  128. return mt.monthsWide[1:]
  129. }
  130. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  131. func (mt *mt) WeekdayAbbreviated(weekday time.Weekday) string {
  132. return mt.daysAbbreviated[weekday]
  133. }
  134. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  135. func (mt *mt) WeekdaysAbbreviated() []string {
  136. return mt.daysAbbreviated
  137. }
  138. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  139. func (mt *mt) WeekdayNarrow(weekday time.Weekday) string {
  140. return mt.daysNarrow[weekday]
  141. }
  142. // WeekdaysNarrow returns the locales narrow weekdays
  143. func (mt *mt) WeekdaysNarrow() []string {
  144. return mt.daysNarrow
  145. }
  146. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  147. func (mt *mt) WeekdayShort(weekday time.Weekday) string {
  148. return mt.daysShort[weekday]
  149. }
  150. // WeekdaysShort returns the locales short weekdays
  151. func (mt *mt) WeekdaysShort() []string {
  152. return mt.daysShort
  153. }
  154. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  155. func (mt *mt) WeekdayWide(weekday time.Weekday) string {
  156. return mt.daysWide[weekday]
  157. }
  158. // WeekdaysWide returns the locales wide weekdays
  159. func (mt *mt) WeekdaysWide() []string {
  160. return mt.daysWide
  161. }
  162. // Decimal returns the decimal point of number
  163. func (mt *mt) Decimal() string {
  164. return mt.decimal
  165. }
  166. // Group returns the group of number
  167. func (mt *mt) Group() string {
  168. return mt.group
  169. }
  170. // Group returns the minus sign of number
  171. func (mt *mt) Minus() string {
  172. return mt.minus
  173. }
  174. // FmtNumber returns 'num' with digits/precision of 'v' for 'mt' and handles both Whole and Real numbers based on 'v'
  175. func (mt *mt) FmtNumber(num float64, v uint64) string {
  176. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  177. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  178. count := 0
  179. inWhole := v == 0
  180. b := make([]byte, 0, l)
  181. for i := len(s) - 1; i >= 0; i-- {
  182. if s[i] == '.' {
  183. b = append(b, mt.decimal[0])
  184. inWhole = true
  185. continue
  186. }
  187. if inWhole {
  188. if count == 3 {
  189. b = append(b, mt.group[0])
  190. count = 1
  191. } else {
  192. count++
  193. }
  194. }
  195. b = append(b, s[i])
  196. }
  197. if num < 0 {
  198. b = append(b, mt.minus[0])
  199. }
  200. // reverse
  201. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  202. b[i], b[j] = b[j], b[i]
  203. }
  204. return string(b)
  205. }
  206. // FmtPercent returns 'num' with digits/precision of 'v' for 'mt' and handles both Whole and Real numbers based on 'v'
  207. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  208. func (mt *mt) FmtPercent(num float64, v uint64) string {
  209. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  210. l := len(s) + 3
  211. b := make([]byte, 0, l)
  212. for i := len(s) - 1; i >= 0; i-- {
  213. if s[i] == '.' {
  214. b = append(b, mt.decimal[0])
  215. continue
  216. }
  217. b = append(b, s[i])
  218. }
  219. if num < 0 {
  220. b = append(b, mt.minus[0])
  221. }
  222. // reverse
  223. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  224. b[i], b[j] = b[j], b[i]
  225. }
  226. b = append(b, mt.percent...)
  227. return string(b)
  228. }
  229. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mt'
  230. func (mt *mt) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  231. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  232. symbol := mt.currencies[currency]
  233. l := len(s) + len(symbol) + 2 + 1*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. b = append(b, mt.decimal[0])
  240. inWhole = true
  241. continue
  242. }
  243. if inWhole {
  244. if count == 3 {
  245. b = append(b, mt.group[0])
  246. count = 1
  247. } else {
  248. count++
  249. }
  250. }
  251. b = append(b, s[i])
  252. }
  253. for j := len(symbol) - 1; j >= 0; j-- {
  254. b = append(b, symbol[j])
  255. }
  256. if num < 0 {
  257. b = append(b, mt.minus[0])
  258. }
  259. // reverse
  260. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  261. b[i], b[j] = b[j], b[i]
  262. }
  263. if int(v) < 2 {
  264. if v == 0 {
  265. b = append(b, mt.decimal...)
  266. }
  267. for i := 0; i < 2-int(v); i++ {
  268. b = append(b, '0')
  269. }
  270. }
  271. return string(b)
  272. }
  273. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mt'
  274. // in accounting notation.
  275. func (mt *mt) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  276. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  277. symbol := mt.currencies[currency]
  278. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  279. count := 0
  280. inWhole := v == 0
  281. b := make([]byte, 0, l)
  282. for i := len(s) - 1; i >= 0; i-- {
  283. if s[i] == '.' {
  284. b = append(b, mt.decimal[0])
  285. inWhole = true
  286. continue
  287. }
  288. if inWhole {
  289. if count == 3 {
  290. b = append(b, mt.group[0])
  291. count = 1
  292. } else {
  293. count++
  294. }
  295. }
  296. b = append(b, s[i])
  297. }
  298. if num < 0 {
  299. for j := len(symbol) - 1; j >= 0; j-- {
  300. b = append(b, symbol[j])
  301. }
  302. b = append(b, mt.minus[0])
  303. } else {
  304. for j := len(symbol) - 1; j >= 0; j-- {
  305. b = append(b, symbol[j])
  306. }
  307. }
  308. // reverse
  309. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  310. b[i], b[j] = b[j], b[i]
  311. }
  312. if int(v) < 2 {
  313. if v == 0 {
  314. b = append(b, mt.decimal...)
  315. }
  316. for i := 0; i < 2-int(v); i++ {
  317. b = append(b, '0')
  318. }
  319. }
  320. return string(b)
  321. }
  322. // FmtDateShort returns the short date representation of 't' for 'mt'
  323. func (mt *mt) FmtDateShort(t time.Time) string {
  324. b := make([]byte, 0, 32)
  325. if t.Day() < 10 {
  326. b = append(b, '0')
  327. }
  328. b = strconv.AppendInt(b, int64(t.Day()), 10)
  329. b = append(b, []byte{0x2f}...)
  330. if t.Month() < 10 {
  331. b = append(b, '0')
  332. }
  333. b = strconv.AppendInt(b, int64(t.Month()), 10)
  334. b = append(b, []byte{0x2f}...)
  335. if t.Year() > 0 {
  336. b = strconv.AppendInt(b, int64(t.Year()), 10)
  337. } else {
  338. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  339. }
  340. return string(b)
  341. }
  342. // FmtDateMedium returns the medium date representation of 't' for 'mt'
  343. func (mt *mt) FmtDateMedium(t time.Time) string {
  344. b := make([]byte, 0, 32)
  345. if t.Day() < 10 {
  346. b = append(b, '0')
  347. }
  348. b = strconv.AppendInt(b, int64(t.Day()), 10)
  349. b = append(b, []byte{0x20}...)
  350. b = append(b, mt.monthsAbbreviated[t.Month()]...)
  351. b = append(b, []byte{0x20}...)
  352. if t.Year() > 0 {
  353. b = strconv.AppendInt(b, int64(t.Year()), 10)
  354. } else {
  355. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  356. }
  357. return string(b)
  358. }
  359. // FmtDateLong returns the long date representation of 't' for 'mt'
  360. func (mt *mt) 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, 0x74, 0x61}...)
  364. b = append(b, []byte{0xe2, 0x80, 0x99, 0x20}...)
  365. b = append(b, mt.monthsWide[t.Month()]...)
  366. b = append(b, []byte{0x20}...)
  367. if t.Year() > 0 {
  368. b = strconv.AppendInt(b, int64(t.Year()), 10)
  369. } else {
  370. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  371. }
  372. return string(b)
  373. }
  374. // FmtDateFull returns the full date representation of 't' for 'mt'
  375. func (mt *mt) FmtDateFull(t time.Time) string {
  376. b := make([]byte, 0, 32)
  377. b = append(b, mt.daysWide[t.Weekday()]...)
  378. b = append(b, []byte{0x2c, 0x20}...)
  379. b = strconv.AppendInt(b, int64(t.Day()), 10)
  380. b = append(b, []byte{0x20, 0x74, 0x61}...)
  381. b = append(b, []byte{0xe2, 0x80, 0x99, 0x20}...)
  382. b = append(b, mt.monthsWide[t.Month()]...)
  383. b = append(b, []byte{0x20}...)
  384. if t.Year() > 0 {
  385. b = strconv.AppendInt(b, int64(t.Year()), 10)
  386. } else {
  387. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  388. }
  389. return string(b)
  390. }
  391. // FmtTimeShort returns the short time representation of 't' for 'mt'
  392. func (mt *mt) 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, mt.timeSeparator...)
  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 'mt'
  406. func (mt *mt) 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, mt.timeSeparator...)
  413. if t.Minute() < 10 {
  414. b = append(b, '0')
  415. }
  416. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  417. b = append(b, mt.timeSeparator...)
  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 'mt'
  425. func (mt *mt) 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, mt.timeSeparator...)
  432. if t.Minute() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  436. b = append(b, mt.timeSeparator...)
  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 'mt'
  447. func (mt *mt) 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, mt.timeSeparator...)
  454. if t.Minute() < 10 {
  455. b = append(b, '0')
  456. }
  457. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  458. b = append(b, mt.timeSeparator...)
  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 := mt.timezones[tz]; ok {
  466. b = append(b, btz...)
  467. } else {
  468. b = append(b, tz...)
  469. }
  470. return string(b)
  471. }