ksh.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. package ksh
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ksh 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 'ksh' locale
  42. func New() locales.Translator {
  43. return &ksh{
  44. locale: "ksh",
  45. pluralsCardinal: []locales.PluralRule{1, 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{"", "Jan", "Fäb", "Mäz", "Apr", "Mai", "Jun", "Jul", "Ouj", "Säp", "Okt", "Nov", "Dez"},
  60. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "O", "S", "O", "N", "D"},
  61. monthsWide: []string{"", "Jannewa", "Fäbrowa", "Määz", "Aprell", "Mai", "Juuni", "Juuli", "Oujoß", "Septämber", "Oktohber", "Novämber", "Dezämber"},
  62. daysAbbreviated: []string{"Su.", "Mo.", "Di.", "Me.", "Du.", "Fr.", "Sa."},
  63. daysNarrow: []string{"S", "M", "D", "M", "D", "F", "S"},
  64. daysShort: []string{"Su", "Mo", "Di", "Me", "Du", "Fr", "Sa"},
  65. daysWide: []string{"Sunndaach", "Mohndaach", "Dinnsdaach", "Metwoch", "Dunnersdaach", "Friidaach", "Samsdaach"},
  66. periodsAbbreviated: []string{"v.M.", "n.M."},
  67. periodsWide: []string{"Uhr vörmiddaachs", "Uhr nommendaachs"},
  68. erasAbbreviated: []string{"v. Chr.", "n. Chr."},
  69. erasNarrow: []string{"vC", "nC"},
  70. erasWide: []string{"vür Krestos", "noh Krestos"},
  71. timezones: map[string]string{"HADT": "HADT", "HKT": "HKT", "JST": "JST", "ARST": "ARST", "PDT": "PDT", "UYST": "UYST", "WIB": "WIB", "ACWDT": "ACWDT", "AWDT": "AWDT", "MESZ": "Meddel-Europpa sing Summerzick", "OESZ": "Oß-Europpa sing Summerzick", "EAT": "Oß-Affrekaanesche Zigg", "HEPMX": "HEPMX", "MYT": "MYT", "BT": "BT", "HEOG": "HEOG", "HNT": "HNT", "CLST": "CLST", "HENOMX": "HENOMX", "COT": "COT", "HNPMX": "HNPMX", "AKST": "AKST", "ADT": "ADT", "MST": "MST", "AKDT": "AKDT", "HAST": "HAST", "HAT": "HAT", "HNOG": "HNOG", "∅∅∅": "∅∅∅", "HKST": "HKST", "HECU": "HECU", "HNEG": "HNEG", "GFT": "GFT", "ACST": "ACST", "WAT": "Jewöhnlijje Wäß-Affrekaanesche Zigg", "HNCU": "HNCU", "UYT": "UYT", "WEZ": "Weß-Europpa sing jewöhnlijje Zick", "AWST": "AWST", "TMT": "TMT", "CAT": "Zentraal-Affrekaanesche Zigg", "SGT": "SGT", "WIT": "WIT", "MEZ": "Meddel-Europpa sing jewöhnlijje Zick", "IST": "IST", "NZDT": "NZDT", "BOT": "BOT", "HNNOMX": "HNNOMX", "AST": "AST", "VET": "VET", "HEPM": "HEPM", "WARST": "WARST", "COST": "COST", "CST": "CST", "HNPM": "HNPM", "WAST": "Wäß-Affrekaanesche Sommerzigg", "CDT": "CDT", "MDT": "MDT", "JDT": "JDT", "LHDT": "LHDT", "GMT": "Greenwich sing Standat-Zick", "SRT": "SRT", "AEST": "AEST", "NZST": "NZST", "ACDT": "ACDT", "WART": "WART", "EST": "EST", "GYT": "GYT", "ART": "ART", "WITA": "WITA", "SAST": "Söd-Affrekaanesche Zigg", "CLT": "CLT", "TMST": "TMST", "ChST": "ChST", "OEZ": "Oß-Europpa sing jewöhnlijje Zick", "ACWST": "ACWST", "CHAST": "CHAST", "LHST": "LHST", "ECT": "ECT", "CHADT": "CHADT", "HEEG": "HEEG", "EDT": "EDT", "PST": "PST", "WESZ": "Weß-Europpa sing Summerzick", "AEDT": "AEDT"},
  72. }
  73. }
  74. // Locale returns the current translators string locale
  75. func (ksh *ksh) Locale() string {
  76. return ksh.locale
  77. }
  78. // PluralsCardinal returns the list of cardinal plural rules associated with 'ksh'
  79. func (ksh *ksh) PluralsCardinal() []locales.PluralRule {
  80. return ksh.pluralsCardinal
  81. }
  82. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ksh'
  83. func (ksh *ksh) PluralsOrdinal() []locales.PluralRule {
  84. return ksh.pluralsOrdinal
  85. }
  86. // PluralsRange returns the list of range plural rules associated with 'ksh'
  87. func (ksh *ksh) PluralsRange() []locales.PluralRule {
  88. return ksh.pluralsRange
  89. }
  90. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ksh'
  91. func (ksh *ksh) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  92. n := math.Abs(num)
  93. if n == 0 {
  94. return locales.PluralRuleZero
  95. } else if n == 1 {
  96. return locales.PluralRuleOne
  97. }
  98. return locales.PluralRuleOther
  99. }
  100. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ksh'
  101. func (ksh *ksh) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  102. return locales.PluralRuleUnknown
  103. }
  104. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ksh'
  105. func (ksh *ksh) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  106. return locales.PluralRuleUnknown
  107. }
  108. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  109. func (ksh *ksh) MonthAbbreviated(month time.Month) string {
  110. return ksh.monthsAbbreviated[month]
  111. }
  112. // MonthsAbbreviated returns the locales abbreviated months
  113. func (ksh *ksh) MonthsAbbreviated() []string {
  114. return ksh.monthsAbbreviated[1:]
  115. }
  116. // MonthNarrow returns the locales narrow month given the 'month' provided
  117. func (ksh *ksh) MonthNarrow(month time.Month) string {
  118. return ksh.monthsNarrow[month]
  119. }
  120. // MonthsNarrow returns the locales narrow months
  121. func (ksh *ksh) MonthsNarrow() []string {
  122. return ksh.monthsNarrow[1:]
  123. }
  124. // MonthWide returns the locales wide month given the 'month' provided
  125. func (ksh *ksh) MonthWide(month time.Month) string {
  126. return ksh.monthsWide[month]
  127. }
  128. // MonthsWide returns the locales wide months
  129. func (ksh *ksh) MonthsWide() []string {
  130. return ksh.monthsWide[1:]
  131. }
  132. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  133. func (ksh *ksh) WeekdayAbbreviated(weekday time.Weekday) string {
  134. return ksh.daysAbbreviated[weekday]
  135. }
  136. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  137. func (ksh *ksh) WeekdaysAbbreviated() []string {
  138. return ksh.daysAbbreviated
  139. }
  140. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  141. func (ksh *ksh) WeekdayNarrow(weekday time.Weekday) string {
  142. return ksh.daysNarrow[weekday]
  143. }
  144. // WeekdaysNarrow returns the locales narrow weekdays
  145. func (ksh *ksh) WeekdaysNarrow() []string {
  146. return ksh.daysNarrow
  147. }
  148. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  149. func (ksh *ksh) WeekdayShort(weekday time.Weekday) string {
  150. return ksh.daysShort[weekday]
  151. }
  152. // WeekdaysShort returns the locales short weekdays
  153. func (ksh *ksh) WeekdaysShort() []string {
  154. return ksh.daysShort
  155. }
  156. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  157. func (ksh *ksh) WeekdayWide(weekday time.Weekday) string {
  158. return ksh.daysWide[weekday]
  159. }
  160. // WeekdaysWide returns the locales wide weekdays
  161. func (ksh *ksh) WeekdaysWide() []string {
  162. return ksh.daysWide
  163. }
  164. // FmtNumber returns 'num' with digits/precision of 'v' for 'ksh' and handles both Whole and Real numbers based on 'v'
  165. func (ksh *ksh) FmtNumber(num float64, v uint64) string {
  166. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  167. l := len(s) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  168. count := 0
  169. inWhole := v == 0
  170. b := make([]byte, 0, l)
  171. for i := len(s) - 1; i >= 0; i-- {
  172. if s[i] == '.' {
  173. b = append(b, ksh.decimal[0])
  174. inWhole = true
  175. continue
  176. }
  177. if inWhole {
  178. if count == 3 {
  179. for j := len(ksh.group) - 1; j >= 0; j-- {
  180. b = append(b, ksh.group[j])
  181. }
  182. count = 1
  183. } else {
  184. count++
  185. }
  186. }
  187. b = append(b, s[i])
  188. }
  189. if num < 0 {
  190. for j := len(ksh.minus) - 1; j >= 0; j-- {
  191. b = append(b, ksh.minus[j])
  192. }
  193. }
  194. // reverse
  195. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  196. b[i], b[j] = b[j], b[i]
  197. }
  198. return string(b)
  199. }
  200. // FmtPercent returns 'num' with digits/precision of 'v' for 'ksh' and handles both Whole and Real numbers based on 'v'
  201. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  202. func (ksh *ksh) FmtPercent(num float64, v uint64) string {
  203. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  204. l := len(s) + 7
  205. b := make([]byte, 0, l)
  206. for i := len(s) - 1; i >= 0; i-- {
  207. if s[i] == '.' {
  208. b = append(b, ksh.decimal[0])
  209. continue
  210. }
  211. b = append(b, s[i])
  212. }
  213. if num < 0 {
  214. for j := len(ksh.minus) - 1; j >= 0; j-- {
  215. b = append(b, ksh.minus[j])
  216. }
  217. }
  218. // reverse
  219. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  220. b[i], b[j] = b[j], b[i]
  221. }
  222. b = append(b, ksh.percentSuffix...)
  223. b = append(b, ksh.percent...)
  224. return string(b)
  225. }
  226. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ksh'
  227. func (ksh *ksh) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  228. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  229. symbol := ksh.currencies[currency]
  230. l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  231. count := 0
  232. inWhole := v == 0
  233. b := make([]byte, 0, l)
  234. for i := len(s) - 1; i >= 0; i-- {
  235. if s[i] == '.' {
  236. b = append(b, ksh.decimal[0])
  237. inWhole = true
  238. continue
  239. }
  240. if inWhole {
  241. if count == 3 {
  242. for j := len(ksh.group) - 1; j >= 0; j-- {
  243. b = append(b, ksh.group[j])
  244. }
  245. count = 1
  246. } else {
  247. count++
  248. }
  249. }
  250. b = append(b, s[i])
  251. }
  252. if num < 0 {
  253. for j := len(ksh.minus) - 1; j >= 0; j-- {
  254. b = append(b, ksh.minus[j])
  255. }
  256. }
  257. // reverse
  258. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  259. b[i], b[j] = b[j], b[i]
  260. }
  261. if int(v) < 2 {
  262. if v == 0 {
  263. b = append(b, ksh.decimal...)
  264. }
  265. for i := 0; i < 2-int(v); i++ {
  266. b = append(b, '0')
  267. }
  268. }
  269. b = append(b, ksh.currencyPositiveSuffix...)
  270. b = append(b, symbol...)
  271. return string(b)
  272. }
  273. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ksh'
  274. // in accounting notation.
  275. func (ksh *ksh) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  276. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  277. symbol := ksh.currencies[currency]
  278. l := len(s) + len(symbol) + 6 + 2*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, ksh.decimal[0])
  285. inWhole = true
  286. continue
  287. }
  288. if inWhole {
  289. if count == 3 {
  290. for j := len(ksh.group) - 1; j >= 0; j-- {
  291. b = append(b, ksh.group[j])
  292. }
  293. count = 1
  294. } else {
  295. count++
  296. }
  297. }
  298. b = append(b, s[i])
  299. }
  300. if num < 0 {
  301. for j := len(ksh.minus) - 1; j >= 0; j-- {
  302. b = append(b, ksh.minus[j])
  303. }
  304. }
  305. // reverse
  306. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  307. b[i], b[j] = b[j], b[i]
  308. }
  309. if int(v) < 2 {
  310. if v == 0 {
  311. b = append(b, ksh.decimal...)
  312. }
  313. for i := 0; i < 2-int(v); i++ {
  314. b = append(b, '0')
  315. }
  316. }
  317. if num < 0 {
  318. b = append(b, ksh.currencyNegativeSuffix...)
  319. b = append(b, symbol...)
  320. } else {
  321. b = append(b, ksh.currencyPositiveSuffix...)
  322. b = append(b, symbol...)
  323. }
  324. return string(b)
  325. }
  326. // FmtDateShort returns the short date representation of 't' for 'ksh'
  327. func (ksh *ksh) FmtDateShort(t time.Time) string {
  328. b := make([]byte, 0, 32)
  329. b = strconv.AppendInt(b, int64(t.Day()), 10)
  330. b = append(b, []byte{0x2e, 0x20}...)
  331. b = strconv.AppendInt(b, int64(t.Month()), 10)
  332. b = append(b, []byte{0x2e, 0x20}...)
  333. if t.Year() > 0 {
  334. b = strconv.AppendInt(b, int64(t.Year()), 10)
  335. } else {
  336. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  337. }
  338. return string(b)
  339. }
  340. // FmtDateMedium returns the medium date representation of 't' for 'ksh'
  341. func (ksh *ksh) FmtDateMedium(t time.Time) string {
  342. b := make([]byte, 0, 32)
  343. b = strconv.AppendInt(b, int64(t.Day()), 10)
  344. b = append(b, []byte{0x2e, 0x20}...)
  345. b = append(b, ksh.monthsAbbreviated[t.Month()]...)
  346. b = append(b, []byte{0x2e, 0x20}...)
  347. if t.Year() > 0 {
  348. b = strconv.AppendInt(b, int64(t.Year()), 10)
  349. } else {
  350. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  351. }
  352. return string(b)
  353. }
  354. // FmtDateLong returns the long date representation of 't' for 'ksh'
  355. func (ksh *ksh) FmtDateLong(t time.Time) string {
  356. b := make([]byte, 0, 32)
  357. b = strconv.AppendInt(b, int64(t.Day()), 10)
  358. b = append(b, []byte{0x2e, 0x20}...)
  359. b = append(b, ksh.monthsWide[t.Month()]...)
  360. b = append(b, []byte{0x20}...)
  361. if t.Year() > 0 {
  362. b = strconv.AppendInt(b, int64(t.Year()), 10)
  363. } else {
  364. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  365. }
  366. return string(b)
  367. }
  368. // FmtDateFull returns the full date representation of 't' for 'ksh'
  369. func (ksh *ksh) FmtDateFull(t time.Time) string {
  370. b := make([]byte, 0, 32)
  371. b = append(b, ksh.daysWide[t.Weekday()]...)
  372. b = append(b, []byte{0x2c, 0x20, 0x64, 0xc3, 0xa4}...)
  373. b = append(b, []byte{0x20}...)
  374. b = strconv.AppendInt(b, int64(t.Day()), 10)
  375. b = append(b, []byte{0x2e, 0x20}...)
  376. b = append(b, ksh.monthsWide[t.Month()]...)
  377. b = append(b, []byte{0x20}...)
  378. if t.Year() > 0 {
  379. b = strconv.AppendInt(b, int64(t.Year()), 10)
  380. } else {
  381. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  382. }
  383. return string(b)
  384. }
  385. // FmtTimeShort returns the short time representation of 't' for 'ksh'
  386. func (ksh *ksh) FmtTimeShort(t time.Time) string {
  387. b := make([]byte, 0, 32)
  388. if t.Hour() < 10 {
  389. b = append(b, '0')
  390. }
  391. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  392. b = append(b, ksh.timeSeparator...)
  393. if t.Minute() < 10 {
  394. b = append(b, '0')
  395. }
  396. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  397. return string(b)
  398. }
  399. // FmtTimeMedium returns the medium time representation of 't' for 'ksh'
  400. func (ksh *ksh) FmtTimeMedium(t time.Time) string {
  401. b := make([]byte, 0, 32)
  402. if t.Hour() < 10 {
  403. b = append(b, '0')
  404. }
  405. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  406. b = append(b, ksh.timeSeparator...)
  407. if t.Minute() < 10 {
  408. b = append(b, '0')
  409. }
  410. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  411. b = append(b, ksh.timeSeparator...)
  412. if t.Second() < 10 {
  413. b = append(b, '0')
  414. }
  415. b = strconv.AppendInt(b, int64(t.Second()), 10)
  416. return string(b)
  417. }
  418. // FmtTimeLong returns the long time representation of 't' for 'ksh'
  419. func (ksh *ksh) FmtTimeLong(t time.Time) string {
  420. b := make([]byte, 0, 32)
  421. if t.Hour() < 10 {
  422. b = append(b, '0')
  423. }
  424. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  425. b = append(b, ksh.timeSeparator...)
  426. if t.Minute() < 10 {
  427. b = append(b, '0')
  428. }
  429. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  430. b = append(b, ksh.timeSeparator...)
  431. if t.Second() < 10 {
  432. b = append(b, '0')
  433. }
  434. b = strconv.AppendInt(b, int64(t.Second()), 10)
  435. b = append(b, []byte{0x20}...)
  436. tz, _ := t.Zone()
  437. b = append(b, tz...)
  438. return string(b)
  439. }
  440. // FmtTimeFull returns the full time representation of 't' for 'ksh'
  441. func (ksh *ksh) FmtTimeFull(t time.Time) string {
  442. b := make([]byte, 0, 32)
  443. if t.Hour() < 10 {
  444. b = append(b, '0')
  445. }
  446. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  447. b = append(b, ksh.timeSeparator...)
  448. if t.Minute() < 10 {
  449. b = append(b, '0')
  450. }
  451. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  452. b = append(b, ksh.timeSeparator...)
  453. if t.Second() < 10 {
  454. b = append(b, '0')
  455. }
  456. b = strconv.AppendInt(b, int64(t.Second()), 10)
  457. b = append(b, []byte{0x20}...)
  458. tz, _ := t.Zone()
  459. if btz, ok := ksh.timezones[tz]; ok {
  460. b = append(b, btz...)
  461. } else {
  462. b = append(b, tz...)
  463. }
  464. return string(b)
  465. }