tk_TM.go 20 KB

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