ps.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. package ps
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ps 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. currencyPositiveSuffix string
  23. currencyNegativeSuffix string
  24. monthsAbbreviated []string
  25. monthsNarrow []string
  26. monthsWide []string
  27. daysAbbreviated []string
  28. daysNarrow []string
  29. daysShort []string
  30. daysWide []string
  31. periodsAbbreviated []string
  32. periodsNarrow []string
  33. periodsShort []string
  34. periodsWide []string
  35. erasAbbreviated []string
  36. erasNarrow []string
  37. erasWide []string
  38. timezones map[string]string
  39. }
  40. // New returns a new instance of translator for the 'ps' locale
  41. func New() locales.Translator {
  42. return &ps{
  43. locale: "ps",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  47. decimal: "٫",
  48. group: "٬",
  49. minus: "‎-‎",
  50. percent: "٪",
  51. perMille: "؉",
  52. timeSeparator: ":",
  53. inifinity: "∞",
  54. currencies: []string{"ADP", "AED", "AFA", "؋", "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"},
  55. currencyPositiveSuffix: " ",
  56. currencyNegativeSuffix: " ",
  57. monthsAbbreviated: []string{"", "جنوري", "فبروري", "مارچ", "اپریل", "مۍ", "جون", "جولای", "اګست", "سپتمبر", "اکتوبر", "نومبر", "دسمبر"},
  58. monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  59. monthsWide: []string{"", "جنوري", "فبروري", "مارچ", "اپریل", "مۍ", "جون", "جولای", "اګست", "سپتمبر", "اکتوبر", "نومبر", "دسمبر"},
  60. daysAbbreviated: []string{"یکشنبه", "دوشنبه", "سه\u200cشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"},
  61. daysShort: []string{"یکشنبه", "دوشنبه", "سه\u200cشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"},
  62. daysWide: []string{"یکشنبه", "دوشنبه", "سه\u200cشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"},
  63. periodsAbbreviated: []string{"غ.م.", "غ.و."},
  64. periodsNarrow: []string{"غ.م.", "غ.و."},
  65. periodsWide: []string{"غ.م.", "غ.و."},
  66. erasAbbreviated: []string{"له میلاد وړاندې", "م."},
  67. erasNarrow: []string{"", ""},
  68. erasWide: []string{"له میلاد څخه وړاندې", "له میلاد څخه وروسته"},
  69. timezones: map[string]string{"OEZ": "OEZ", "ART": "ART", "HNOG": "HNOG", "WITA": "WITA", "SAST": "SAST", "WAT": "WAT", "∅∅∅": "∅∅∅", "TMT": "TMT", "SGT": "SGT", "AST": "AST", "MDT": "MDT", "ACWST": "ACWST", "ACWDT": "ACWDT", "MESZ": "MESZ", "HNT": "HNT", "AWST": "AWST", "AWDT": "AWDT", "IST": "IST", "COT": "COT", "CHAST": "CHAST", "LHDT": "LHDT", "ACDT": "ACDT", "HADT": "HADT", "SRT": "SRT", "HAT": "HAT", "HEPM": "HEPM", "NZDT": "NZDT", "HNCU": "HNCU", "MYT": "MYT", "BOT": "BOT", "GMT": "گرينويچ وخت", "HENOMX": "HENOMX", "CDT": "CDT", "ADT": "ADT", "HAST": "HAST", "MEZ": "MEZ", "CLST": "CLST", "EDT": "EDT", "HEOG": "HEOG", "HNPM": "HNPM", "NZST": "NZST", "HNNOMX": "HNNOMX", "HNPMX": "HNPMX", "VET": "VET", "LHST": "LHST", "JDT": "JDT", "GFT": "GFT", "WART": "WART", "AEST": "AEST", "ECT": "ECT", "WARST": "WARST", "ACST": "ACST", "HECU": "HECU", "COST": "COST", "WIB": "WIB", "MST": "MST", "WESZ": "د لودیځې اورپا د اوړي وخت", "HKT": "HKT", "JST": "JST", "WAST": "WAST", "EAT": "EAT", "CST": "CST", "UYT": "UYT", "WEZ": "د لودیځې اروپا معیاري وخت", "HKST": "HKST", "AEDT": "AEDT", "AKDT": "AKDT", "WIT": "WIT", "CAT": "CAT", "UYST": "UYST", "HEEG": "HEEG", "ChST": "ChST", "OESZ": "OESZ", "EST": "EST", "GYT": "GYT", "ARST": "ARST", "PST": "PST", "PDT": "PDT", "TMST": "TMST", "HEPMX": "HEPMX", "AKST": "AKST", "BT": "BT", "CHADT": "CHADT", "CLT": "CLT", "HNEG": "HNEG"},
  70. }
  71. }
  72. // Locale returns the current translators string locale
  73. func (ps *ps) Locale() string {
  74. return ps.locale
  75. }
  76. // PluralsCardinal returns the list of cardinal plural rules associated with 'ps'
  77. func (ps *ps) PluralsCardinal() []locales.PluralRule {
  78. return ps.pluralsCardinal
  79. }
  80. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ps'
  81. func (ps *ps) PluralsOrdinal() []locales.PluralRule {
  82. return ps.pluralsOrdinal
  83. }
  84. // PluralsRange returns the list of range plural rules associated with 'ps'
  85. func (ps *ps) PluralsRange() []locales.PluralRule {
  86. return ps.pluralsRange
  87. }
  88. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ps'
  89. func (ps *ps) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  90. n := math.Abs(num)
  91. if n == 1 {
  92. return locales.PluralRuleOne
  93. }
  94. return locales.PluralRuleOther
  95. }
  96. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ps'
  97. func (ps *ps) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  98. return locales.PluralRuleUnknown
  99. }
  100. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ps'
  101. func (ps *ps) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  102. return locales.PluralRuleUnknown
  103. }
  104. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  105. func (ps *ps) MonthAbbreviated(month time.Month) string {
  106. return ps.monthsAbbreviated[month]
  107. }
  108. // MonthsAbbreviated returns the locales abbreviated months
  109. func (ps *ps) MonthsAbbreviated() []string {
  110. return ps.monthsAbbreviated[1:]
  111. }
  112. // MonthNarrow returns the locales narrow month given the 'month' provided
  113. func (ps *ps) MonthNarrow(month time.Month) string {
  114. return ps.monthsNarrow[month]
  115. }
  116. // MonthsNarrow returns the locales narrow months
  117. func (ps *ps) MonthsNarrow() []string {
  118. return ps.monthsNarrow[1:]
  119. }
  120. // MonthWide returns the locales wide month given the 'month' provided
  121. func (ps *ps) MonthWide(month time.Month) string {
  122. return ps.monthsWide[month]
  123. }
  124. // MonthsWide returns the locales wide months
  125. func (ps *ps) MonthsWide() []string {
  126. return ps.monthsWide[1:]
  127. }
  128. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  129. func (ps *ps) WeekdayAbbreviated(weekday time.Weekday) string {
  130. return ps.daysAbbreviated[weekday]
  131. }
  132. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  133. func (ps *ps) WeekdaysAbbreviated() []string {
  134. return ps.daysAbbreviated
  135. }
  136. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  137. func (ps *ps) WeekdayNarrow(weekday time.Weekday) string {
  138. return ps.daysNarrow[weekday]
  139. }
  140. // WeekdaysNarrow returns the locales narrow weekdays
  141. func (ps *ps) WeekdaysNarrow() []string {
  142. return ps.daysNarrow
  143. }
  144. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  145. func (ps *ps) WeekdayShort(weekday time.Weekday) string {
  146. return ps.daysShort[weekday]
  147. }
  148. // WeekdaysShort returns the locales short weekdays
  149. func (ps *ps) WeekdaysShort() []string {
  150. return ps.daysShort
  151. }
  152. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  153. func (ps *ps) WeekdayWide(weekday time.Weekday) string {
  154. return ps.daysWide[weekday]
  155. }
  156. // WeekdaysWide returns the locales wide weekdays
  157. func (ps *ps) WeekdaysWide() []string {
  158. return ps.daysWide
  159. }
  160. // FmtNumber returns 'num' with digits/precision of 'v' for 'ps' and handles both Whole and Real numbers based on 'v'
  161. func (ps *ps) FmtNumber(num float64, v uint64) string {
  162. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  163. l := len(s) + 9 + 2*len(s[:len(s)-int(v)-1])/3
  164. count := 0
  165. inWhole := v == 0
  166. b := make([]byte, 0, l)
  167. for i := len(s) - 1; i >= 0; i-- {
  168. if s[i] == '.' {
  169. for j := len(ps.decimal) - 1; j >= 0; j-- {
  170. b = append(b, ps.decimal[j])
  171. }
  172. inWhole = true
  173. continue
  174. }
  175. if inWhole {
  176. if count == 3 {
  177. for j := len(ps.group) - 1; j >= 0; j-- {
  178. b = append(b, ps.group[j])
  179. }
  180. count = 1
  181. } else {
  182. count++
  183. }
  184. }
  185. b = append(b, s[i])
  186. }
  187. if num < 0 {
  188. for j := len(ps.minus) - 1; j >= 0; j-- {
  189. b = append(b, ps.minus[j])
  190. }
  191. }
  192. // reverse
  193. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  194. b[i], b[j] = b[j], b[i]
  195. }
  196. return string(b)
  197. }
  198. // FmtPercent returns 'num' with digits/precision of 'v' for 'ps' and handles both Whole and Real numbers based on 'v'
  199. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  200. func (ps *ps) FmtPercent(num float64, v uint64) string {
  201. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  202. l := len(s) + 11
  203. b := make([]byte, 0, l)
  204. for i := len(s) - 1; i >= 0; i-- {
  205. if s[i] == '.' {
  206. for j := len(ps.decimal) - 1; j >= 0; j-- {
  207. b = append(b, ps.decimal[j])
  208. }
  209. continue
  210. }
  211. b = append(b, s[i])
  212. }
  213. if num < 0 {
  214. for j := len(ps.minus) - 1; j >= 0; j-- {
  215. b = append(b, ps.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, ps.percent...)
  223. return string(b)
  224. }
  225. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ps'
  226. func (ps *ps) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  227. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  228. symbol := ps.currencies[currency]
  229. l := len(s) + len(symbol) + 11 + 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. for j := len(ps.decimal) - 1; j >= 0; j-- {
  236. b = append(b, ps.decimal[j])
  237. }
  238. inWhole = true
  239. continue
  240. }
  241. if inWhole {
  242. if count == 3 {
  243. for j := len(ps.group) - 1; j >= 0; j-- {
  244. b = append(b, ps.group[j])
  245. }
  246. count = 1
  247. } else {
  248. count++
  249. }
  250. }
  251. b = append(b, s[i])
  252. }
  253. if num < 0 {
  254. for j := len(ps.minus) - 1; j >= 0; j-- {
  255. b = append(b, ps.minus[j])
  256. }
  257. }
  258. // reverse
  259. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  260. b[i], b[j] = b[j], b[i]
  261. }
  262. if int(v) < 2 {
  263. if v == 0 {
  264. b = append(b, ps.decimal...)
  265. }
  266. for i := 0; i < 2-int(v); i++ {
  267. b = append(b, '0')
  268. }
  269. }
  270. b = append(b, ps.currencyPositiveSuffix...)
  271. b = append(b, symbol...)
  272. return string(b)
  273. }
  274. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ps'
  275. // in accounting notation.
  276. func (ps *ps) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  277. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  278. symbol := ps.currencies[currency]
  279. l := len(s) + len(symbol) + 11 + 2*len(s[:len(s)-int(v)-1])/3
  280. count := 0
  281. inWhole := v == 0
  282. b := make([]byte, 0, l)
  283. for i := len(s) - 1; i >= 0; i-- {
  284. if s[i] == '.' {
  285. for j := len(ps.decimal) - 1; j >= 0; j-- {
  286. b = append(b, ps.decimal[j])
  287. }
  288. inWhole = true
  289. continue
  290. }
  291. if inWhole {
  292. if count == 3 {
  293. for j := len(ps.group) - 1; j >= 0; j-- {
  294. b = append(b, ps.group[j])
  295. }
  296. count = 1
  297. } else {
  298. count++
  299. }
  300. }
  301. b = append(b, s[i])
  302. }
  303. if num < 0 {
  304. for j := len(ps.minus) - 1; j >= 0; j-- {
  305. b = append(b, ps.minus[j])
  306. }
  307. }
  308. // reverse
  309. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  310. b[i], b[j] = b[j], b[i]
  311. }
  312. if int(v) < 2 {
  313. if v == 0 {
  314. b = append(b, ps.decimal...)
  315. }
  316. for i := 0; i < 2-int(v); i++ {
  317. b = append(b, '0')
  318. }
  319. }
  320. if num < 0 {
  321. b = append(b, ps.currencyNegativeSuffix...)
  322. b = append(b, symbol...)
  323. } else {
  324. b = append(b, ps.currencyPositiveSuffix...)
  325. b = append(b, symbol...)
  326. }
  327. return string(b)
  328. }
  329. // FmtDateShort returns the short date representation of 't' for 'ps'
  330. func (ps *ps) FmtDateShort(t time.Time) string {
  331. b := make([]byte, 0, 32)
  332. if t.Year() > 0 {
  333. b = strconv.AppendInt(b, int64(t.Year()), 10)
  334. } else {
  335. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  336. }
  337. b = append(b, []byte{0x2f}...)
  338. b = strconv.AppendInt(b, int64(t.Month()), 10)
  339. b = append(b, []byte{0x2f}...)
  340. b = strconv.AppendInt(b, int64(t.Day()), 10)
  341. return string(b)
  342. }
  343. // FmtDateMedium returns the medium date representation of 't' for 'ps'
  344. func (ps *ps) FmtDateMedium(t time.Time) string {
  345. b := make([]byte, 0, 32)
  346. if t.Year() > 0 {
  347. b = strconv.AppendInt(b, int64(t.Year()), 10)
  348. } else {
  349. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  350. }
  351. b = append(b, []byte{0x20}...)
  352. b = append(b, ps.monthsAbbreviated[t.Month()]...)
  353. b = append(b, []byte{0x20}...)
  354. b = strconv.AppendInt(b, int64(t.Day()), 10)
  355. return string(b)
  356. }
  357. // FmtDateLong returns the long date representation of 't' for 'ps'
  358. func (ps *ps) FmtDateLong(t time.Time) string {
  359. b := make([]byte, 0, 32)
  360. b = append(b, []byte{0xd8, 0xaf, 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. b = append(b, []byte{0x20, 0xd8, 0xaf, 0x20}...)
  367. b = append(b, ps.monthsWide[t.Month()]...)
  368. b = append(b, []byte{0x20}...)
  369. b = strconv.AppendInt(b, int64(t.Day()), 10)
  370. return string(b)
  371. }
  372. // FmtDateFull returns the full date representation of 't' for 'ps'
  373. func (ps *ps) FmtDateFull(t time.Time) string {
  374. b := make([]byte, 0, 32)
  375. b = append(b, ps.daysWide[t.Weekday()]...)
  376. b = append(b, []byte{0x20, 0xd8, 0xaf, 0x20}...)
  377. if t.Year() > 0 {
  378. b = strconv.AppendInt(b, int64(t.Year()), 10)
  379. } else {
  380. b = strconv.AppendInt(b, int64(t.Year()*-1), 10)
  381. }
  382. b = append(b, []byte{0x20, 0xd8, 0xaf, 0x20}...)
  383. b = append(b, ps.monthsWide[t.Month()]...)
  384. b = append(b, []byte{0x20}...)
  385. b = strconv.AppendInt(b, int64(t.Day()), 10)
  386. return string(b)
  387. }
  388. // FmtTimeShort returns the short time representation of 't' for 'ps'
  389. func (ps *ps) FmtTimeShort(t time.Time) string {
  390. b := make([]byte, 0, 32)
  391. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  392. b = append(b, ps.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 'ps'
  400. func (ps *ps) FmtTimeMedium(t time.Time) string {
  401. b := make([]byte, 0, 32)
  402. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  403. b = append(b, ps.timeSeparator...)
  404. if t.Minute() < 10 {
  405. b = append(b, '0')
  406. }
  407. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  408. b = append(b, ps.timeSeparator...)
  409. if t.Second() < 10 {
  410. b = append(b, '0')
  411. }
  412. b = strconv.AppendInt(b, int64(t.Second()), 10)
  413. return string(b)
  414. }
  415. // FmtTimeLong returns the long time representation of 't' for 'ps'
  416. func (ps *ps) FmtTimeLong(t time.Time) string {
  417. b := make([]byte, 0, 32)
  418. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  419. b = append(b, ps.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, ps.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, 0x28}...)
  430. tz, _ := t.Zone()
  431. b = append(b, tz...)
  432. b = append(b, []byte{0x29}...)
  433. return string(b)
  434. }
  435. // FmtTimeFull returns the full time representation of 't' for 'ps'
  436. func (ps *ps) FmtTimeFull(t time.Time) string {
  437. b := make([]byte, 0, 32)
  438. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  439. b = append(b, ps.timeSeparator...)
  440. if t.Minute() < 10 {
  441. b = append(b, '0')
  442. }
  443. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  444. b = append(b, ps.timeSeparator...)
  445. if t.Second() < 10 {
  446. b = append(b, '0')
  447. }
  448. b = strconv.AppendInt(b, int64(t.Second()), 10)
  449. b = append(b, []byte{0x20, 0x28}...)
  450. tz, _ := t.Zone()
  451. if btz, ok := ps.timezones[tz]; ok {
  452. b = append(b, btz...)
  453. } else {
  454. b = append(b, tz...)
  455. }
  456. b = append(b, []byte{0x29}...)
  457. return string(b)
  458. }