mt.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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", "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", "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{"ACWDT": "ACWDT", "NZDT": "NZDT", "MEZ": "Ħin Ċentrali Ewropew Standard", "BOT": "BOT", "MDT": "MDT", "GYT": "GYT", "WIB": "WIB", "HKST": "HKST", "GMT": "GMT", "GFT": "GFT", "HENOMX": "HENOMX", "COT": "COT", "PDT": "PDT", "WITA": "WITA", "HEPM": "HEPM", "IST": "IST", "WAST": "WAST", "HNPMX": "HNPMX", "UYT": "UYT", "VET": "VET", "HEOG": "HEOG", "AWST": "AWST", "CHAST": "CHAST", "HEPMX": "HEPMX", "AST": "AST", "WIT": "WIT", "AWDT": "AWDT", "CLST": "CLST", "TMST": "TMST", "OESZ": "OESZ", "CDT": "CDT", "ACWST": "ACWST", "PST": "PST", "HEEG": "HEEG", "MYT": "MYT", "BT": "BT", "JDT": "JDT", "HNCU": "HNCU", "UYST": "UYST", "HAT": "HAT", "CLT": "CLT", "TMT": "TMT", "AEDT": "AEDT", "MESZ": "Ħin Ċentrali Ewropew tas-Sajf", "LHDT": "LHDT", "ARST": "ARST", "SAST": "SAST", "JST": "JST", "HNEG": "HNEG", "WAT": "WAT", "EDT": "EDT", "HADT": "HADT", "ART": "ART", "OEZ": "OEZ", "ECT": "ECT", "HECU": "HECU", "EST": "EST", "AKDT": "AKDT", "ACDT": "ACDT", "HNOG": "HNOG", "EAT": "EAT", "COST": "COST", "SGT": "SGT", "HAST": "HAST", "SRT": "SRT", "HNT": "HNT", "HNNOMX": "HNNOMX", "WARST": "WARST", "WESZ": "WESZ", "HKT": "HKT", "CAT": "CAT", "ACST": "ACST", "AEST": "AEST", "CHADT": "CHADT", "ChST": "ChST", "HNPM": "HNPM", "NZST": "NZST", "LHST": "LHST", "∅∅∅": "∅∅∅", "WART": "WART", "MST": "MST", "ADT": "ADT", "WEZ": "WEZ", "AKST": "AKST", "CST": "CST"},
  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. // FmtNumber returns 'num' with digits/precision of 'v' for 'mt' and handles both Whole and Real numbers based on 'v'
  163. func (mt *mt) FmtNumber(num float64, v uint64) string {
  164. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  165. l := len(s) + 2 + 1*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, mt.decimal[0])
  172. inWhole = true
  173. continue
  174. }
  175. if inWhole {
  176. if count == 3 {
  177. b = append(b, mt.group[0])
  178. count = 1
  179. } else {
  180. count++
  181. }
  182. }
  183. b = append(b, s[i])
  184. }
  185. if num < 0 {
  186. b = append(b, mt.minus[0])
  187. }
  188. // reverse
  189. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  190. b[i], b[j] = b[j], b[i]
  191. }
  192. return string(b)
  193. }
  194. // FmtPercent returns 'num' with digits/precision of 'v' for 'mt' and handles both Whole and Real numbers based on 'v'
  195. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  196. func (mt *mt) FmtPercent(num float64, v uint64) string {
  197. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  198. l := len(s) + 3
  199. b := make([]byte, 0, l)
  200. for i := len(s) - 1; i >= 0; i-- {
  201. if s[i] == '.' {
  202. b = append(b, mt.decimal[0])
  203. continue
  204. }
  205. b = append(b, s[i])
  206. }
  207. if num < 0 {
  208. b = append(b, mt.minus[0])
  209. }
  210. // reverse
  211. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  212. b[i], b[j] = b[j], b[i]
  213. }
  214. b = append(b, mt.percent...)
  215. return string(b)
  216. }
  217. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mt'
  218. func (mt *mt) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  219. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  220. symbol := mt.currencies[currency]
  221. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  222. count := 0
  223. inWhole := v == 0
  224. b := make([]byte, 0, l)
  225. for i := len(s) - 1; i >= 0; i-- {
  226. if s[i] == '.' {
  227. b = append(b, mt.decimal[0])
  228. inWhole = true
  229. continue
  230. }
  231. if inWhole {
  232. if count == 3 {
  233. b = append(b, mt.group[0])
  234. count = 1
  235. } else {
  236. count++
  237. }
  238. }
  239. b = append(b, s[i])
  240. }
  241. for j := len(symbol) - 1; j >= 0; j-- {
  242. b = append(b, symbol[j])
  243. }
  244. if num < 0 {
  245. b = append(b, mt.minus[0])
  246. }
  247. // reverse
  248. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  249. b[i], b[j] = b[j], b[i]
  250. }
  251. if int(v) < 2 {
  252. if v == 0 {
  253. b = append(b, mt.decimal...)
  254. }
  255. for i := 0; i < 2-int(v); i++ {
  256. b = append(b, '0')
  257. }
  258. }
  259. return string(b)
  260. }
  261. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mt'
  262. // in accounting notation.
  263. func (mt *mt) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  264. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  265. symbol := mt.currencies[currency]
  266. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  267. count := 0
  268. inWhole := v == 0
  269. b := make([]byte, 0, l)
  270. for i := len(s) - 1; i >= 0; i-- {
  271. if s[i] == '.' {
  272. b = append(b, mt.decimal[0])
  273. inWhole = true
  274. continue
  275. }
  276. if inWhole {
  277. if count == 3 {
  278. b = append(b, mt.group[0])
  279. count = 1
  280. } else {
  281. count++
  282. }
  283. }
  284. b = append(b, s[i])
  285. }
  286. if num < 0 {
  287. for j := len(symbol) - 1; j >= 0; j-- {
  288. b = append(b, symbol[j])
  289. }
  290. b = append(b, mt.minus[0])
  291. } else {
  292. for j := len(symbol) - 1; j >= 0; j-- {
  293. b = append(b, symbol[j])
  294. }
  295. }
  296. // reverse
  297. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  298. b[i], b[j] = b[j], b[i]
  299. }
  300. if int(v) < 2 {
  301. if v == 0 {
  302. b = append(b, mt.decimal...)
  303. }
  304. for i := 0; i < 2-int(v); i++ {
  305. b = append(b, '0')
  306. }
  307. }
  308. return string(b)
  309. }
  310. // FmtDateShort returns the short date representation of 't' for 'mt'
  311. func (mt *mt) FmtDateShort(t time.Time) string {
  312. b := make([]byte, 0, 32)
  313. if t.Day() < 10 {
  314. b = append(b, '0')
  315. }
  316. b = strconv.AppendInt(b, int64(t.Day()), 10)
  317. b = append(b, []byte{0x2f}...)
  318. if t.Month() < 10 {
  319. b = append(b, '0')
  320. }
  321. b = strconv.AppendInt(b, int64(t.Month()), 10)
  322. b = append(b, []byte{0x2f}...)
  323. if t.Year() > 0 {
  324. b = strconv.AppendInt(b, int64(t.Year()), 10)
  325. } else {
  326. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  327. }
  328. return string(b)
  329. }
  330. // FmtDateMedium returns the medium date representation of 't' for 'mt'
  331. func (mt *mt) FmtDateMedium(t time.Time) string {
  332. b := make([]byte, 0, 32)
  333. if t.Day() < 10 {
  334. b = append(b, '0')
  335. }
  336. b = strconv.AppendInt(b, int64(t.Day()), 10)
  337. b = append(b, []byte{0x20}...)
  338. b = append(b, mt.monthsAbbreviated[t.Month()]...)
  339. b = append(b, []byte{0x20}...)
  340. if t.Year() > 0 {
  341. b = strconv.AppendInt(b, int64(t.Year()), 10)
  342. } else {
  343. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  344. }
  345. return string(b)
  346. }
  347. // FmtDateLong returns the long date representation of 't' for 'mt'
  348. func (mt *mt) FmtDateLong(t time.Time) string {
  349. b := make([]byte, 0, 32)
  350. b = strconv.AppendInt(b, int64(t.Day()), 10)
  351. b = append(b, []byte{0x20, 0x74, 0x61}...)
  352. b = append(b, []byte{0xe2, 0x80, 0x99, 0x20}...)
  353. b = append(b, mt.monthsWide[t.Month()]...)
  354. b = append(b, []byte{0x20}...)
  355. if t.Year() > 0 {
  356. b = strconv.AppendInt(b, int64(t.Year()), 10)
  357. } else {
  358. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  359. }
  360. return string(b)
  361. }
  362. // FmtDateFull returns the full date representation of 't' for 'mt'
  363. func (mt *mt) FmtDateFull(t time.Time) string {
  364. b := make([]byte, 0, 32)
  365. b = append(b, mt.daysWide[t.Weekday()]...)
  366. b = append(b, []byte{0x2c, 0x20}...)
  367. b = strconv.AppendInt(b, int64(t.Day()), 10)
  368. b = append(b, []byte{0x20, 0x74, 0x61}...)
  369. b = append(b, []byte{0xe2, 0x80, 0x99, 0x20}...)
  370. b = append(b, mt.monthsWide[t.Month()]...)
  371. b = append(b, []byte{0x20}...)
  372. if t.Year() > 0 {
  373. b = strconv.AppendInt(b, int64(t.Year()), 10)
  374. } else {
  375. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  376. }
  377. return string(b)
  378. }
  379. // FmtTimeShort returns the short time representation of 't' for 'mt'
  380. func (mt *mt) FmtTimeShort(t time.Time) string {
  381. b := make([]byte, 0, 32)
  382. if t.Hour() < 10 {
  383. b = append(b, '0')
  384. }
  385. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  386. b = append(b, mt.timeSeparator...)
  387. if t.Minute() < 10 {
  388. b = append(b, '0')
  389. }
  390. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  391. return string(b)
  392. }
  393. // FmtTimeMedium returns the medium time representation of 't' for 'mt'
  394. func (mt *mt) FmtTimeMedium(t time.Time) string {
  395. b := make([]byte, 0, 32)
  396. if t.Hour() < 10 {
  397. b = append(b, '0')
  398. }
  399. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  400. b = append(b, mt.timeSeparator...)
  401. if t.Minute() < 10 {
  402. b = append(b, '0')
  403. }
  404. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  405. b = append(b, mt.timeSeparator...)
  406. if t.Second() < 10 {
  407. b = append(b, '0')
  408. }
  409. b = strconv.AppendInt(b, int64(t.Second()), 10)
  410. return string(b)
  411. }
  412. // FmtTimeLong returns the long time representation of 't' for 'mt'
  413. func (mt *mt) FmtTimeLong(t time.Time) string {
  414. b := make([]byte, 0, 32)
  415. if t.Hour() < 10 {
  416. b = append(b, '0')
  417. }
  418. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  419. b = append(b, mt.timeSeparator...)
  420. if t.Minute() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  424. b = append(b, mt.timeSeparator...)
  425. if t.Second() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Second()), 10)
  429. b = append(b, []byte{0x20}...)
  430. tz, _ := t.Zone()
  431. b = append(b, tz...)
  432. return string(b)
  433. }
  434. // FmtTimeFull returns the full time representation of 't' for 'mt'
  435. func (mt *mt) FmtTimeFull(t time.Time) string {
  436. b := make([]byte, 0, 32)
  437. if t.Hour() < 10 {
  438. b = append(b, '0')
  439. }
  440. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  441. b = append(b, mt.timeSeparator...)
  442. if t.Minute() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  446. b = append(b, mt.timeSeparator...)
  447. if t.Second() < 10 {
  448. b = append(b, '0')
  449. }
  450. b = strconv.AppendInt(b, int64(t.Second()), 10)
  451. b = append(b, []byte{0x20}...)
  452. tz, _ := t.Zone()
  453. if btz, ok := mt.timezones[tz]; ok {
  454. b = append(b, btz...)
  455. } else {
  456. b = append(b, tz...)
  457. }
  458. return string(b)
  459. }