tt.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. package tt
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type tt 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. monthsAbbreviated []string
  24. monthsNarrow []string
  25. monthsWide []string
  26. daysAbbreviated []string
  27. daysNarrow []string
  28. daysShort []string
  29. daysWide []string
  30. periodsAbbreviated []string
  31. periodsNarrow []string
  32. periodsShort []string
  33. periodsWide []string
  34. erasAbbreviated []string
  35. erasNarrow []string
  36. erasWide []string
  37. timezones map[string]string
  38. }
  39. // New returns a new instance of translator for the 'tt' locale
  40. func New() locales.Translator {
  41. return &tt{
  42. locale: "tt",
  43. pluralsCardinal: nil,
  44. pluralsOrdinal: nil,
  45. pluralsRange: nil,
  46. decimal: ",",
  47. group: " ",
  48. minus: "-",
  49. percent: "%",
  50. perMille: "‰",
  51. timeSeparator: ":",
  52. inifinity: "∞",
  53. 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", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "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", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JP¥", "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", "₽", "р.", "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", "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", "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"},
  54. percentSuffix: " ",
  55. monthsAbbreviated: []string{"", "гыйн.", "фев.", "мар.", "апр.", "май", "июнь", "июль", "авг.", "сент.", "окт.", "нояб.", "дек."},
  56. monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  57. monthsWide: []string{"", "гыйнвар", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь"},
  58. daysAbbreviated: []string{"якш.", "дүш.", "сиш.", "чәр.", "пәнҗ.", "җом.", "шим."},
  59. daysNarrow: []string{"Я", "Д", "С", "Ч", "П", "Җ", "Ш"},
  60. daysShort: []string{"якш.", "дүш.", "сиш.", "чәр.", "пәнҗ.", "җом.", "шим."},
  61. daysWide: []string{"якшәмбе", "дүшәмбе", "сишәмбе", "чәршәмбе", "пәнҗешәмбе", "җомга", "шимбә"},
  62. periodsAbbreviated: []string{"AM", "PM"},
  63. periodsNarrow: []string{"AM", "PM"},
  64. periodsWide: []string{"AM", "PM"},
  65. erasAbbreviated: []string{"б.э.к.", "б.э."},
  66. erasNarrow: []string{"", ""},
  67. erasWide: []string{"безнең эрага кадәр", "безнең эра"},
  68. timezones: map[string]string{"COT": "COT", "CHAST": "CHAST", "WIB": "WIB", "MYT": "MYT", "HEOG": "HEOG", "HKT": "HKT", "LHDT": "LHDT", "CST": "Төньяк Америка гадәти үзәк вакыты", "AWDT": "AWDT", "ACWST": "ACWST", "MESZ": "җәйге Үзәк Европа вакыты", "WART": "WART", "∅∅∅": "∅∅∅", "PDT": "Төньяк Америка җәйге Тын океан вакыты", "HNPMX": "HNPMX", "AST": "Төньяк Америка гадәти атлантик вакыты", "AEST": "AEST", "SAST": "SAST", "WAT": "WAT", "HNPM": "HNPM", "WAST": "WAST", "JDT": "JDT", "AKST": "AKST", "CHADT": "CHADT", "AEDT": "AEDT", "HNT": "HNT", "HEPM": "HEPM", "SRT": "SRT", "EST": "Төньяк Америка гадәти көнчыгыш вакыты", "MST": "MST", "NZDT": "NZDT", "BOT": "BOT", "SGT": "SGT", "ACST": "ACST", "WARST": "WARST", "WITA": "WITA", "HNNOMX": "HNNOMX", "CAT": "CAT", "CLT": "CLT", "UYT": "UYT", "HECU": "HECU", "ADT": "Төньяк Америка җәйге атлантик вакыты", "WEZ": "гадәти Көнбатыш Европа вакыты", "GFT": "GFT", "HNEG": "HNEG", "WESZ": "җәйге Көнбатыш Европа вакыты", "AKDT": "AKDT", "EDT": "Төньяк Америка җәйге көнчыгыш вакыты", "ACWDT": "ACWDT", "TMT": "TMT", "HNCU": "HNCU", "AWST": "AWST", "ECT": "ECT", "HEEG": "HEEG", "MEZ": "гадәти Үзәк Европа вакыты", "LHST": "LHST", "OESZ": "җәйге Көнчыгыш Европа вакыты", "COST": "COST", "JST": "JST", "IST": "IST", "VET": "VET", "EAT": "EAT", "TMST": "TMST", "ART": "ART", "UYST": "UYST", "ACDT": "ACDT", "HENOMX": "HENOMX", "MDT": "MDT", "CLST": "CLST", "WIT": "WIT", "HAST": "HAST", "ARST": "ARST", "HEPMX": "HEPMX", "BT": "BT", "NZST": "NZST", "HNOG": "HNOG", "OEZ": "гадәти Көнчыгыш Европа вакыты", "HADT": "HADT", "ChST": "ChST", "PST": "Төньяк Америка гадәти Тын океан вакыты", "GMT": "Гринвич уртача вакыты", "GYT": "GYT", "CDT": "Төньяк Америка җәйге үзәк вакыты", "HKST": "HKST", "HAT": "HAT"},
  69. }
  70. }
  71. // Locale returns the current translators string locale
  72. func (tt *tt) Locale() string {
  73. return tt.locale
  74. }
  75. // PluralsCardinal returns the list of cardinal plural rules associated with 'tt'
  76. func (tt *tt) PluralsCardinal() []locales.PluralRule {
  77. return tt.pluralsCardinal
  78. }
  79. // PluralsOrdinal returns the list of ordinal plural rules associated with 'tt'
  80. func (tt *tt) PluralsOrdinal() []locales.PluralRule {
  81. return tt.pluralsOrdinal
  82. }
  83. // PluralsRange returns the list of range plural rules associated with 'tt'
  84. func (tt *tt) PluralsRange() []locales.PluralRule {
  85. return tt.pluralsRange
  86. }
  87. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'tt'
  88. func (tt *tt) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  89. return locales.PluralRuleUnknown
  90. }
  91. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'tt'
  92. func (tt *tt) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. return locales.PluralRuleUnknown
  94. }
  95. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'tt'
  96. func (tt *tt) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  97. return locales.PluralRuleUnknown
  98. }
  99. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  100. func (tt *tt) MonthAbbreviated(month time.Month) string {
  101. return tt.monthsAbbreviated[month]
  102. }
  103. // MonthsAbbreviated returns the locales abbreviated months
  104. func (tt *tt) MonthsAbbreviated() []string {
  105. return tt.monthsAbbreviated[1:]
  106. }
  107. // MonthNarrow returns the locales narrow month given the 'month' provided
  108. func (tt *tt) MonthNarrow(month time.Month) string {
  109. return tt.monthsNarrow[month]
  110. }
  111. // MonthsNarrow returns the locales narrow months
  112. func (tt *tt) MonthsNarrow() []string {
  113. return tt.monthsNarrow[1:]
  114. }
  115. // MonthWide returns the locales wide month given the 'month' provided
  116. func (tt *tt) MonthWide(month time.Month) string {
  117. return tt.monthsWide[month]
  118. }
  119. // MonthsWide returns the locales wide months
  120. func (tt *tt) MonthsWide() []string {
  121. return tt.monthsWide[1:]
  122. }
  123. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  124. func (tt *tt) WeekdayAbbreviated(weekday time.Weekday) string {
  125. return tt.daysAbbreviated[weekday]
  126. }
  127. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  128. func (tt *tt) WeekdaysAbbreviated() []string {
  129. return tt.daysAbbreviated
  130. }
  131. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  132. func (tt *tt) WeekdayNarrow(weekday time.Weekday) string {
  133. return tt.daysNarrow[weekday]
  134. }
  135. // WeekdaysNarrow returns the locales narrow weekdays
  136. func (tt *tt) WeekdaysNarrow() []string {
  137. return tt.daysNarrow
  138. }
  139. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  140. func (tt *tt) WeekdayShort(weekday time.Weekday) string {
  141. return tt.daysShort[weekday]
  142. }
  143. // WeekdaysShort returns the locales short weekdays
  144. func (tt *tt) WeekdaysShort() []string {
  145. return tt.daysShort
  146. }
  147. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  148. func (tt *tt) WeekdayWide(weekday time.Weekday) string {
  149. return tt.daysWide[weekday]
  150. }
  151. // WeekdaysWide returns the locales wide weekdays
  152. func (tt *tt) WeekdaysWide() []string {
  153. return tt.daysWide
  154. }
  155. // Decimal returns the decimal point of number
  156. func (tt *tt) Decimal() string {
  157. return tt.decimal
  158. }
  159. // Group returns the group of number
  160. func (tt *tt) Group() string {
  161. return tt.group
  162. }
  163. // Group returns the minus sign of number
  164. func (tt *tt) Minus() string {
  165. return tt.minus
  166. }
  167. // FmtNumber returns 'num' with digits/precision of 'v' for 'tt' and handles both Whole and Real numbers based on 'v'
  168. func (tt *tt) FmtNumber(num float64, v uint64) string {
  169. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  170. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  171. count := 0
  172. inWhole := v == 0
  173. b := make([]byte, 0, l)
  174. for i := len(s) - 1; i >= 0; i-- {
  175. if s[i] == '.' {
  176. b = append(b, tt.decimal[0])
  177. inWhole = true
  178. continue
  179. }
  180. if inWhole {
  181. if count == 3 {
  182. for j := len(tt.group) - 1; j >= 0; j-- {
  183. b = append(b, tt.group[j])
  184. }
  185. count = 1
  186. } else {
  187. count++
  188. }
  189. }
  190. b = append(b, s[i])
  191. }
  192. if num < 0 {
  193. b = append(b, tt.minus[0])
  194. }
  195. // reverse
  196. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  197. b[i], b[j] = b[j], b[i]
  198. }
  199. return string(b)
  200. }
  201. // FmtPercent returns 'num' with digits/precision of 'v' for 'tt' and handles both Whole and Real numbers based on 'v'
  202. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  203. func (tt *tt) FmtPercent(num float64, v uint64) string {
  204. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  205. l := len(s) + 5
  206. b := make([]byte, 0, l)
  207. for i := len(s) - 1; i >= 0; i-- {
  208. if s[i] == '.' {
  209. b = append(b, tt.decimal[0])
  210. continue
  211. }
  212. b = append(b, s[i])
  213. }
  214. if num < 0 {
  215. b = append(b, tt.minus[0])
  216. }
  217. // reverse
  218. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  219. b[i], b[j] = b[j], b[i]
  220. }
  221. b = append(b, tt.percentSuffix...)
  222. b = append(b, tt.percent...)
  223. return string(b)
  224. }
  225. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'tt'
  226. func (tt *tt) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  227. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  228. symbol := tt.currencies[currency]
  229. l := len(s) + len(symbol) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  230. count := 0
  231. inWhole := v == 0
  232. b := make([]byte, 0, l)
  233. for i := len(s) - 1; i >= 0; i-- {
  234. if s[i] == '.' {
  235. b = append(b, tt.decimal[0])
  236. inWhole = true
  237. continue
  238. }
  239. if inWhole {
  240. if count == 3 {
  241. for j := len(tt.group) - 1; j >= 0; j-- {
  242. b = append(b, tt.group[j])
  243. }
  244. count = 1
  245. } else {
  246. count++
  247. }
  248. }
  249. b = append(b, s[i])
  250. }
  251. if num < 0 {
  252. b = append(b, tt.minus[0])
  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, tt.decimal...)
  261. }
  262. for i := 0; i < 2-int(v); i++ {
  263. b = append(b, '0')
  264. }
  265. }
  266. b = append(b, symbol...)
  267. return string(b)
  268. }
  269. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'tt'
  270. // in accounting notation.
  271. func (tt *tt) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  272. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  273. symbol := tt.currencies[currency]
  274. l := len(s) + len(symbol) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  275. count := 0
  276. inWhole := v == 0
  277. b := make([]byte, 0, l)
  278. for i := len(s) - 1; i >= 0; i-- {
  279. if s[i] == '.' {
  280. b = append(b, tt.decimal[0])
  281. inWhole = true
  282. continue
  283. }
  284. if inWhole {
  285. if count == 3 {
  286. for j := len(tt.group) - 1; j >= 0; j-- {
  287. b = append(b, tt.group[j])
  288. }
  289. count = 1
  290. } else {
  291. count++
  292. }
  293. }
  294. b = append(b, s[i])
  295. }
  296. if num < 0 {
  297. b = append(b, tt.minus[0])
  298. }
  299. // reverse
  300. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  301. b[i], b[j] = b[j], b[i]
  302. }
  303. if int(v) < 2 {
  304. if v == 0 {
  305. b = append(b, tt.decimal...)
  306. }
  307. for i := 0; i < 2-int(v); i++ {
  308. b = append(b, '0')
  309. }
  310. }
  311. if num < 0 {
  312. b = append(b, symbol...)
  313. } else {
  314. b = append(b, symbol...)
  315. }
  316. return string(b)
  317. }
  318. // FmtDateShort returns the short date representation of 't' for 'tt'
  319. func (tt *tt) FmtDateShort(t time.Time) string {
  320. b := make([]byte, 0, 32)
  321. if t.Day() < 10 {
  322. b = append(b, '0')
  323. }
  324. b = strconv.AppendInt(b, int64(t.Day()), 10)
  325. b = append(b, []byte{0x2e}...)
  326. if t.Month() < 10 {
  327. b = append(b, '0')
  328. }
  329. b = strconv.AppendInt(b, int64(t.Month()), 10)
  330. b = append(b, []byte{0x2e}...)
  331. if t.Year() > 0 {
  332. b = strconv.AppendInt(b, int64(t.Year()), 10)
  333. } else {
  334. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  335. }
  336. return string(b)
  337. }
  338. // FmtDateMedium returns the medium date representation of 't' for 'tt'
  339. func (tt *tt) FmtDateMedium(t time.Time) string {
  340. b := make([]byte, 0, 32)
  341. b = strconv.AppendInt(b, int64(t.Day()), 10)
  342. b = append(b, []byte{0x20}...)
  343. b = append(b, tt.monthsAbbreviated[t.Month()]...)
  344. b = append(b, []byte{0x2c, 0x20}...)
  345. if t.Year() > 0 {
  346. b = strconv.AppendInt(b, int64(t.Year()), 10)
  347. } else {
  348. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  349. }
  350. b = append(b, []byte{0x20, 0xd0, 0xb5, 0xd0, 0xbb}...)
  351. return string(b)
  352. }
  353. // FmtDateLong returns the long date representation of 't' for 'tt'
  354. func (tt *tt) FmtDateLong(t time.Time) string {
  355. b := make([]byte, 0, 32)
  356. b = strconv.AppendInt(b, int64(t.Day()), 10)
  357. b = append(b, []byte{0x20}...)
  358. b = append(b, tt.monthsWide[t.Month()]...)
  359. b = append(b, []byte{0x2c, 0x20}...)
  360. if t.Year() > 0 {
  361. b = strconv.AppendInt(b, int64(t.Year()), 10)
  362. } else {
  363. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  364. }
  365. b = append(b, []byte{0x20, 0xd0, 0xb5, 0xd0, 0xbb}...)
  366. return string(b)
  367. }
  368. // FmtDateFull returns the full date representation of 't' for 'tt'
  369. func (tt *tt) FmtDateFull(t time.Time) string {
  370. b := make([]byte, 0, 32)
  371. b = strconv.AppendInt(b, int64(t.Day()), 10)
  372. b = append(b, []byte{0x20}...)
  373. b = append(b, tt.monthsWide[t.Month()]...)
  374. b = append(b, []byte{0x2c, 0x20}...)
  375. if t.Year() > 0 {
  376. b = strconv.AppendInt(b, int64(t.Year()), 10)
  377. } else {
  378. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  379. }
  380. b = append(b, []byte{0x20, 0xd0, 0xb5, 0xd0, 0xbb}...)
  381. b = append(b, []byte{0x2c, 0x20}...)
  382. b = append(b, tt.daysWide[t.Weekday()]...)
  383. return string(b)
  384. }
  385. // FmtTimeShort returns the short time representation of 't' for 'tt'
  386. func (tt *tt) FmtTimeShort(t time.Time) string {
  387. b := make([]byte, 0, 32)
  388. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  389. b = append(b, tt.timeSeparator...)
  390. if t.Minute() < 10 {
  391. b = append(b, '0')
  392. }
  393. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  394. return string(b)
  395. }
  396. // FmtTimeMedium returns the medium time representation of 't' for 'tt'
  397. func (tt *tt) FmtTimeMedium(t time.Time) string {
  398. b := make([]byte, 0, 32)
  399. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  400. b = append(b, tt.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, tt.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 'tt'
  413. func (tt *tt) FmtTimeLong(t time.Time) string {
  414. b := make([]byte, 0, 32)
  415. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  416. b = append(b, tt.timeSeparator...)
  417. if t.Minute() < 10 {
  418. b = append(b, '0')
  419. }
  420. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  421. b = append(b, tt.timeSeparator...)
  422. if t.Second() < 10 {
  423. b = append(b, '0')
  424. }
  425. b = strconv.AppendInt(b, int64(t.Second()), 10)
  426. b = append(b, []byte{0x20}...)
  427. tz, _ := t.Zone()
  428. b = append(b, tz...)
  429. return string(b)
  430. }
  431. // FmtTimeFull returns the full time representation of 't' for 'tt'
  432. func (tt *tt) FmtTimeFull(t time.Time) string {
  433. b := make([]byte, 0, 32)
  434. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  435. b = append(b, tt.timeSeparator...)
  436. if t.Minute() < 10 {
  437. b = append(b, '0')
  438. }
  439. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  440. b = append(b, tt.timeSeparator...)
  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 := tt.timezones[tz]; ok {
  448. b = append(b, btz...)
  449. } else {
  450. b = append(b, tz...)
  451. }
  452. return string(b)
  453. }