tk_TM.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. package tk_TM
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type tk_TM 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 'tk_TM' locale
  42. func New() locales.Translator {
  43. return &tk_TM{
  44. locale: "tk_TM",
  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", "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", "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", "EUR", "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", "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", "SSP", "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"},
  56. percentSuffix: " ",
  57. currencyPositiveSuffix: " ",
  58. currencyNegativeSuffix: " ",
  59. monthsAbbreviated: []string{"", "ýan", "few", "mart", "apr", "maý", "iýun", "iýul", "awg", "sen", "okt", "noý", "dek"},
  60. monthsNarrow: []string{"", "Ý", "F", "M", "A", "M", "I", "I", "A", "S", "O", "N", "D"},
  61. monthsWide: []string{"", "ýanwar", "fewral", "mart", "aprel", "maý", "iýun", "iýul", "awgust", "sentýabr", "oktýabr", "noýabr", "dekabr"},
  62. daysAbbreviated: []string{"ýb", "db", "sb", "çb", "pb", "an", "şb"},
  63. daysNarrow: []string{"Ý", "D", "S", "Ç", "P", "A", "Ş"},
  64. daysWide: []string{"ýekşenbe", "duşenbe", "sişenbe", "çarşenbe", "penşenbe", "anna", "şenbe"},
  65. timezones: map[string]string{"NZST": "Täze Zelandiýa, standart wagt", "∅∅∅": "Amazonka, tomusky wagt", "WIB": "Günbatar Indoneziýa", "ACWST": "Merkezi Awstraliýa, günbatar tarap, standart wagt", "AEDT": "Gündogar Awstraliýa, tomusky wagt", "WAST": "Günbatar Afrika, tomusky wagt", "WART": "Günbatar Argentina, standart wagt", "SGT": "Singapur, standart wagt", "HNPMX": "Meksikan Ýuwaş umman, standart wagt", "AEST": "Gündogar Awstraliýa, standart wagt", "HKT": "Gonkong, standart wagt", "ChST": "Çamorro", "OESZ": "Gündogar Ýewropa, tomusky wagt", "HEPMX": "Meksikan Ýuwaş umman, tomusky wagt", "ARST": "Argentina, tomusky wagt", "AWST": "Günbatar Awstraliýa, standart wagt", "MESZ": "Merkezi Ýewropa, tomusky wagt", "JST": "Ýaponiýa, standart wagt", "HENOMX": "D.g.-G.b. Meksika, tomusky wagt", "ADT": "Atlantika, tomusky wagt", "HEOG": "Günbatar Grenlandiýa, tomusky wagt", "PDT": "Ýuwaş umman, tomusky wagt", "HEPM": "Sen Pýer we Mikelon, tomusky wagt", "EAT": "Gündogar Afrika", "HNCU": "Kuba, standart wagt", "MDT": "MDT", "UYT": "Urugwaý, standart wagt", "AST": "Atlantika, standart wagt", "WIT": "Gündogar Indoneziýa", "NZDT": "Täze Zelandiýa, tomusky wagt", "HECU": "Kuba, tomusky wagt", "WESZ": "Günbatar Ýewropa, tomusky wagt", "MEZ": "Merkezi Ýewropa, standart wagt", "LHST": "Lord-Hau, standart wagt", "IST": "Hindistan", "GFT": "Fransuz Gwiana", "ACDT": "Merkezi Awstraliýa, tomusky wagt", "CDT": "Merkezi Amerika, tomusky wagt", "EDT": "Günorta Amerika, tomusky wagt", "BT": "Butan", "LHDT": "Lord-Hau, tomusky wagt", "CHAST": "Çatem, standart wagt", "CLST": "Çili, tomusky wagt", "COT": "Kolumbiýa, standart wagt", "COST": "Kolumbiýa, tomusky wagt", "EST": "Günorta Amerika, standart wagt", "WITA": "Merkezi Indoneziýa", "ACST": "Merkezi Awstraliýa, standart wagt", "WARST": "Günbatar Argentina, tomusky wagt", "AKST": "Alýaska, standart wagt", "HNPM": "Sen Pýer we Mikelon, standart wagt", "WEZ": "Günbatar Ýewropa, standart wagt", "HNT": "Nýufaundlend, standart wagt", "CHADT": "Çatem, tomusky wagt", "CLT": "Çili, standart wagt", "BOT": "Boliwiýa", "CAT": "Merkezi Afrika", "CST": "Merkezi Amerika, standart wagt", "HAST": "Gawaý-Aleut, standart wagt", "ART": "Argentina, standart wagt", "TMT": "Türkmenistan, standart wagt", "GMT": "Grinwiç boýunça orta wagt", "HNOG": "Günbatar Grenlandiýa, standart wagt", "AWDT": "Günbatar Awstraliýa, tomusky wagt", "HKST": "Gonkong, tomusky wagt", "SAST": "Günorta Afrika, standart wagt", "UYST": "Urugwaý, tomusky wagt", "VET": "Wenesuela", "PST": "Ýuwaş umman, standart wagt", "ACWDT": "Merkezi Awstraliýa, günbatar tarap, tomusky wagt", "JDT": "Ýaponiýa, tomusky wagt", "HEEG": "Gündogar Grenlandiýa, tomusky wagt", "WAT": "Günbatar Afrika, standart wagt", "MYT": "Malaýziýa", "TMST": "Türkmenistan, tomusky wagt", "GYT": "Gaýana", "HADT": "Gawaý-Aleut, tomusky wagt", "HNEG": "Gündogar Grenlandiýa, standart wagt", "OEZ": "Gündogar Ýewropa, standart wagt", "SRT": "Surinam", "HAT": "Nýufaundlend, tomusky wagt", "ECT": "Ekwador", "HNNOMX": "D.g.-G.b. Meksika, standart wagt", "MST": "MST", "AKDT": "Alýaska, tomusky wagt"},
  66. }
  67. }
  68. // Locale returns the current translators string locale
  69. func (tk *tk_TM) Locale() string {
  70. return tk.locale
  71. }
  72. // PluralsCardinal returns the list of cardinal plural rules associated with 'tk_TM'
  73. func (tk *tk_TM) PluralsCardinal() []locales.PluralRule {
  74. return tk.pluralsCardinal
  75. }
  76. // PluralsOrdinal returns the list of ordinal plural rules associated with 'tk_TM'
  77. func (tk *tk_TM) PluralsOrdinal() []locales.PluralRule {
  78. return tk.pluralsOrdinal
  79. }
  80. // PluralsRange returns the list of range plural rules associated with 'tk_TM'
  81. func (tk *tk_TM) PluralsRange() []locales.PluralRule {
  82. return tk.pluralsRange
  83. }
  84. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'tk_TM'
  85. func (tk *tk_TM) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  86. n := math.Abs(num)
  87. if n == 1 {
  88. return locales.PluralRuleOne
  89. }
  90. return locales.PluralRuleOther
  91. }
  92. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'tk_TM'
  93. func (tk *tk_TM) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  94. return locales.PluralRuleUnknown
  95. }
  96. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'tk_TM'
  97. func (tk *tk_TM) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  98. return locales.PluralRuleUnknown
  99. }
  100. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  101. func (tk *tk_TM) MonthAbbreviated(month time.Month) string {
  102. return tk.monthsAbbreviated[month]
  103. }
  104. // MonthsAbbreviated returns the locales abbreviated months
  105. func (tk *tk_TM) MonthsAbbreviated() []string {
  106. return tk.monthsAbbreviated[1:]
  107. }
  108. // MonthNarrow returns the locales narrow month given the 'month' provided
  109. func (tk *tk_TM) MonthNarrow(month time.Month) string {
  110. return tk.monthsNarrow[month]
  111. }
  112. // MonthsNarrow returns the locales narrow months
  113. func (tk *tk_TM) MonthsNarrow() []string {
  114. return tk.monthsNarrow[1:]
  115. }
  116. // MonthWide returns the locales wide month given the 'month' provided
  117. func (tk *tk_TM) MonthWide(month time.Month) string {
  118. return tk.monthsWide[month]
  119. }
  120. // MonthsWide returns the locales wide months
  121. func (tk *tk_TM) MonthsWide() []string {
  122. return tk.monthsWide[1:]
  123. }
  124. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  125. func (tk *tk_TM) WeekdayAbbreviated(weekday time.Weekday) string {
  126. return tk.daysAbbreviated[weekday]
  127. }
  128. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  129. func (tk *tk_TM) WeekdaysAbbreviated() []string {
  130. return tk.daysAbbreviated
  131. }
  132. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  133. func (tk *tk_TM) WeekdayNarrow(weekday time.Weekday) string {
  134. return tk.daysNarrow[weekday]
  135. }
  136. // WeekdaysNarrow returns the locales narrow weekdays
  137. func (tk *tk_TM) WeekdaysNarrow() []string {
  138. return tk.daysNarrow
  139. }
  140. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  141. func (tk *tk_TM) WeekdayShort(weekday time.Weekday) string {
  142. return tk.daysShort[weekday]
  143. }
  144. // WeekdaysShort returns the locales short weekdays
  145. func (tk *tk_TM) WeekdaysShort() []string {
  146. return tk.daysShort
  147. }
  148. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  149. func (tk *tk_TM) WeekdayWide(weekday time.Weekday) string {
  150. return tk.daysWide[weekday]
  151. }
  152. // WeekdaysWide returns the locales wide weekdays
  153. func (tk *tk_TM) WeekdaysWide() []string {
  154. return tk.daysWide
  155. }
  156. // FmtNumber returns 'num' with digits/precision of 'v' for 'tk_TM' and handles both Whole and Real numbers based on 'v'
  157. func (tk *tk_TM) FmtNumber(num float64, v uint64) string {
  158. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  159. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  160. count := 0
  161. inWhole := v == 0
  162. b := make([]byte, 0, l)
  163. for i := len(s) - 1; i >= 0; i-- {
  164. if s[i] == '.' {
  165. b = append(b, tk.decimal[0])
  166. inWhole = true
  167. continue
  168. }
  169. if inWhole {
  170. if count == 3 {
  171. for j := len(tk.group) - 1; j >= 0; j-- {
  172. b = append(b, tk.group[j])
  173. }
  174. count = 1
  175. } else {
  176. count++
  177. }
  178. }
  179. b = append(b, s[i])
  180. }
  181. if num < 0 {
  182. b = append(b, tk.minus[0])
  183. }
  184. // reverse
  185. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  186. b[i], b[j] = b[j], b[i]
  187. }
  188. return string(b)
  189. }
  190. // FmtPercent returns 'num' with digits/precision of 'v' for 'tk_TM' and handles both Whole and Real numbers based on 'v'
  191. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  192. func (tk *tk_TM) FmtPercent(num float64, v uint64) string {
  193. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  194. l := len(s) + 5
  195. b := make([]byte, 0, l)
  196. for i := len(s) - 1; i >= 0; i-- {
  197. if s[i] == '.' {
  198. b = append(b, tk.decimal[0])
  199. continue
  200. }
  201. b = append(b, s[i])
  202. }
  203. if num < 0 {
  204. b = append(b, tk.minus[0])
  205. }
  206. // reverse
  207. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  208. b[i], b[j] = b[j], b[i]
  209. }
  210. b = append(b, tk.percentSuffix...)
  211. b = append(b, tk.percent...)
  212. return string(b)
  213. }
  214. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'tk_TM'
  215. func (tk *tk_TM) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  216. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  217. symbol := tk.currencies[currency]
  218. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  219. count := 0
  220. inWhole := v == 0
  221. b := make([]byte, 0, l)
  222. for i := len(s) - 1; i >= 0; i-- {
  223. if s[i] == '.' {
  224. b = append(b, tk.decimal[0])
  225. inWhole = true
  226. continue
  227. }
  228. if inWhole {
  229. if count == 3 {
  230. for j := len(tk.group) - 1; j >= 0; j-- {
  231. b = append(b, tk.group[j])
  232. }
  233. count = 1
  234. } else {
  235. count++
  236. }
  237. }
  238. b = append(b, s[i])
  239. }
  240. if num < 0 {
  241. b = append(b, tk.minus[0])
  242. }
  243. // reverse
  244. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  245. b[i], b[j] = b[j], b[i]
  246. }
  247. if int(v) < 2 {
  248. if v == 0 {
  249. b = append(b, tk.decimal...)
  250. }
  251. for i := 0; i < 2-int(v); i++ {
  252. b = append(b, '0')
  253. }
  254. }
  255. b = append(b, tk.currencyPositiveSuffix...)
  256. b = append(b, symbol...)
  257. return string(b)
  258. }
  259. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'tk_TM'
  260. // in accounting notation.
  261. func (tk *tk_TM) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  262. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  263. symbol := tk.currencies[currency]
  264. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  265. count := 0
  266. inWhole := v == 0
  267. b := make([]byte, 0, l)
  268. for i := len(s) - 1; i >= 0; i-- {
  269. if s[i] == '.' {
  270. b = append(b, tk.decimal[0])
  271. inWhole = true
  272. continue
  273. }
  274. if inWhole {
  275. if count == 3 {
  276. for j := len(tk.group) - 1; j >= 0; j-- {
  277. b = append(b, tk.group[j])
  278. }
  279. count = 1
  280. } else {
  281. count++
  282. }
  283. }
  284. b = append(b, s[i])
  285. }
  286. if num < 0 {
  287. b = append(b, tk.minus[0])
  288. }
  289. // reverse
  290. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  291. b[i], b[j] = b[j], b[i]
  292. }
  293. if int(v) < 2 {
  294. if v == 0 {
  295. b = append(b, tk.decimal...)
  296. }
  297. for i := 0; i < 2-int(v); i++ {
  298. b = append(b, '0')
  299. }
  300. }
  301. if num < 0 {
  302. b = append(b, tk.currencyNegativeSuffix...)
  303. b = append(b, symbol...)
  304. } else {
  305. b = append(b, tk.currencyPositiveSuffix...)
  306. b = append(b, symbol...)
  307. }
  308. return string(b)
  309. }
  310. // FmtDateShort returns the short date representation of 't' for 'tk_TM'
  311. func (tk *tk_TM) 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{0x2e}...)
  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{0x2e}...)
  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 'tk_TM'
  331. func (tk *tk_TM) FmtDateMedium(t time.Time) string {
  332. b := make([]byte, 0, 32)
  333. b = strconv.AppendInt(b, int64(t.Day()), 10)
  334. b = append(b, []byte{0x20}...)
  335. b = append(b, tk.monthsAbbreviated[t.Month()]...)
  336. b = append(b, []byte{0x20}...)
  337. if t.Year() > 0 {
  338. b = strconv.AppendInt(b, int64(t.Year()), 10)
  339. } else {
  340. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  341. }
  342. return string(b)
  343. }
  344. // FmtDateLong returns the long date representation of 't' for 'tk_TM'
  345. func (tk *tk_TM) FmtDateLong(t time.Time) string {
  346. b := make([]byte, 0, 32)
  347. b = strconv.AppendInt(b, int64(t.Day()), 10)
  348. b = append(b, []byte{0x20}...)
  349. b = append(b, tk.monthsWide[t.Month()]...)
  350. b = append(b, []byte{0x20}...)
  351. if t.Year() > 0 {
  352. b = strconv.AppendInt(b, int64(t.Year()), 10)
  353. } else {
  354. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  355. }
  356. return string(b)
  357. }
  358. // FmtDateFull returns the full date representation of 't' for 'tk_TM'
  359. func (tk *tk_TM) FmtDateFull(t time.Time) string {
  360. b := make([]byte, 0, 32)
  361. b = strconv.AppendInt(b, int64(t.Day()), 10)
  362. b = append(b, []byte{0x20}...)
  363. b = append(b, tk.monthsWide[t.Month()]...)
  364. b = append(b, []byte{0x20}...)
  365. if t.Year() > 0 {
  366. b = strconv.AppendInt(b, int64(t.Year()), 10)
  367. } else {
  368. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  369. }
  370. b = append(b, []byte{0x20}...)
  371. b = append(b, tk.daysWide[t.Weekday()]...)
  372. return string(b)
  373. }
  374. // FmtTimeShort returns the short time representation of 't' for 'tk_TM'
  375. func (tk *tk_TM) FmtTimeShort(t time.Time) string {
  376. b := make([]byte, 0, 32)
  377. if t.Hour() < 10 {
  378. b = append(b, '0')
  379. }
  380. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  381. b = append(b, tk.timeSeparator...)
  382. if t.Minute() < 10 {
  383. b = append(b, '0')
  384. }
  385. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  386. return string(b)
  387. }
  388. // FmtTimeMedium returns the medium time representation of 't' for 'tk_TM'
  389. func (tk *tk_TM) FmtTimeMedium(t time.Time) string {
  390. b := make([]byte, 0, 32)
  391. if t.Hour() < 10 {
  392. b = append(b, '0')
  393. }
  394. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  395. b = append(b, tk.timeSeparator...)
  396. if t.Minute() < 10 {
  397. b = append(b, '0')
  398. }
  399. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  400. b = append(b, tk.timeSeparator...)
  401. if t.Second() < 10 {
  402. b = append(b, '0')
  403. }
  404. b = strconv.AppendInt(b, int64(t.Second()), 10)
  405. return string(b)
  406. }
  407. // FmtTimeLong returns the long time representation of 't' for 'tk_TM'
  408. func (tk *tk_TM) FmtTimeLong(t time.Time) string {
  409. b := make([]byte, 0, 32)
  410. if t.Hour() < 10 {
  411. b = append(b, '0')
  412. }
  413. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  414. b = append(b, tk.timeSeparator...)
  415. if t.Minute() < 10 {
  416. b = append(b, '0')
  417. }
  418. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  419. b = append(b, tk.timeSeparator...)
  420. if t.Second() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Second()), 10)
  424. b = append(b, []byte{0x20}...)
  425. tz, _ := t.Zone()
  426. b = append(b, tz...)
  427. return string(b)
  428. }
  429. // FmtTimeFull returns the full time representation of 't' for 'tk_TM'
  430. func (tk *tk_TM) FmtTimeFull(t time.Time) string {
  431. b := make([]byte, 0, 32)
  432. if t.Hour() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  436. b = append(b, tk.timeSeparator...)
  437. if t.Minute() < 10 {
  438. b = append(b, '0')
  439. }
  440. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  441. b = append(b, tk.timeSeparator...)
  442. if t.Second() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Second()), 10)
  446. b = append(b, []byte{0x20}...)
  447. tz, _ := t.Zone()
  448. if btz, ok := tk.timezones[tz]; ok {
  449. b = append(b, btz...)
  450. } else {
  451. b = append(b, tz...)
  452. }
  453. return string(b)
  454. }