ast.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. package ast
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ast 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 'ast' locale
  41. func New() locales.Translator {
  42. return &ast{
  43. locale: "ast",
  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", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "A$", "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", "CA$", "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", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "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", "MX$", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZ$", "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", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "CFPF", "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{"", "xin", "feb", "mar", "abr", "may", "xun", "xnt", "ago", "set", "och", "pay", "avi"},
  58. monthsNarrow: []string{"", "X", "F", "M", "A", "M", "X", "X", "A", "S", "O", "P", "A"},
  59. monthsWide: []string{"", "de xineru", "de febreru", "de marzu", "d’abril", "de mayu", "de xunu", "de xunetu", "d’agostu", "de setiembre", "d’ochobre", "de payares", "d’avientu"},
  60. daysAbbreviated: []string{"dom", "llu", "mar", "mié", "xue", "vie", "sáb"},
  61. daysNarrow: []string{"D", "L", "M", "M", "X", "V", "S"},
  62. daysShort: []string{"do", "ll", "ma", "mi", "xu", "vi", "sá"},
  63. daysWide: []string{"domingu", "llunes", "martes", "miércoles", "xueves", "vienres", "sábadu"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"a", "p"},
  66. periodsWide: []string{"de la mañana", "de la tarde"},
  67. erasAbbreviated: []string{"e.C.", "d.C."},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"enantes de Cristu", "después de Cristu"},
  70. timezones: map[string]string{"PDT": "Hora braniega del Pacíficu norteamericanu", "EDT": "Hora braniega del este norteamericanu", "ACWST": "Hora estándar d’Australia central del oeste", "HKST": "Hora braniega de Ḥong Kong", "SRT": "Hora del Surinam", "CHAST": "Hora estándar de Chatham", "SGT": "Hora estándar de Singapur", "HEPM": "Hora braniega de Saint Pierre y Miquelon", "EAT": "Hora d’África del este", "COT": "Hora estándar de Colombia", "COST": "Hora braniega de Colombia", "AWDT": "Hora braniega d’Australia del oeste", "AST": "Hora estándar del Atlánticu", "AKST": "Hora estándar d’Alaska", "CLST": "Hora braniega de Chile", "CHADT": "Hora braniega de Chatham", "LHDT": "Hora braniega de Lord Howe", "SAST": "Hora de Sudáfrica", "WESZ": "Hora braniega d’Europa Occidental", "JST": "Hora estándar de Xapón", "ACST": "Hora estándar d’Australia central", "HNOG": "Hora estándar de Groenlandia occidental", "MESZ": "Hora braniega d’Europa Central", "LHST": "Hora estándar de Lord Howe", "WART": "Hora estándar occidental d’Arxentina", "TMST": "Hora braniega del Turkmenistán", "AWST": "Hora estándar d’Australia del oeste", "NZDT": "Hora braniega de Nueva Zelanda", "HEOG": "Hora braniega de Groenlandia occidental", "TMT": "Hora estándar del Turkmenistán", "ART": "Hora estándar d’Arxentina", "UYT": "Hora estándar del Uruguái", "NZST": "Hora estándar de Nueva Zelanda", "MYT": "Hora de Malasia", "AKDT": "Hora braniega d’Alaska", "HADT": "Hora braniega de Hawaii-Aleutianes", "ChST": "Hora estándar de Chamorro", "HNPMX": "Hora estándar del Pacíficu de Méxicu", "WAST": "Hora braniega d’África del oeste", "IST": "Hora estándar de la India", "HNT": "Hora estándar de Newfoundland", "CAT": "Hora d’África central", "UYST": "Hora braniega del Uruguái", "HECU": "Hora braniega de Cuba", "PST": "Hora estándar del Pacíficu norteamericanu", "ADT": "Hora braniega del Atlánticu", "EST": "Hora estándar del este norteamericanu", "CLT": "Hora estándar de Chile", "OESZ": "Hora braniega d’Europa del Este", "HNCU": "Hora estándar de Cuba", "HEPMX": "Hora braniega del Pacíficu de Méxicu", "ACWDT": "Hora braniega d’Australia central del oeste", "GYT": "Hora de La Guyana", "GFT": "Hora de La Guyana Francesa", "HENOMX": "Hora braniega del noroeste de Méxicu", "MST": "Hora estándar de les montañes norteamericanes", "MDT": "Hora braniega de les montañes norteamericanes", "HEEG": "Hora braniega de Groenlandia oriental", "HKT": "Hora estándar de Ḥong Kong", "HNEG": "Hora estándar de Groenlandia oriental", "CST": "Hora estándar central norteamericana", "AEST": "Hora estándar d’Australia del este", "WAT": "Hora estándar d’África del oeste", "WEZ": "Hora estándar d’Europa Occidental", "BT": "Hora de Bután", "JDT": "Hora braniega de Xapón", "ACDT": "Hora braniega d’Australia central", "HAT": "Hora braniega de Newfoundland", "HNPM": "Hora estándar de Saint Pierre y Miquelon", "OEZ": "Hora estándar d’Europa del Este", "HAST": "Hora estándar de Hawaii-Aleutianes", "AEDT": "Hora braniega d’Australia del este", "WIB": "Hora d’Indonesia del oeste", "∅∅∅": "hora braniega d’Acre", "VET": "Hora de Venezuela", "CDT": "Hora braniega central norteamericana", "WITA": "Hora d’Indonesia central", "WIT": "Hora d’Indonesia del este", "WARST": "Hora braniega occidental d’Arxentina", "ARST": "Hora braniega d’Arxentina", "GMT": "Hora media de Greenwich", "BOT": "Hora de Bolivia", "ECT": "Hora d’Ecuador", "MEZ": "Hora estándar d’Europa Central", "HNNOMX": "Hora estándar del noroeste de Méxicu"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (ast *ast) Locale() string {
  75. return ast.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'ast'
  78. func (ast *ast) PluralsCardinal() []locales.PluralRule {
  79. return ast.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ast'
  82. func (ast *ast) PluralsOrdinal() []locales.PluralRule {
  83. return ast.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'ast'
  86. func (ast *ast) PluralsRange() []locales.PluralRule {
  87. return ast.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ast'
  90. func (ast *ast) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. if i == 1 && v == 0 {
  94. return locales.PluralRuleOne
  95. }
  96. return locales.PluralRuleOther
  97. }
  98. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ast'
  99. func (ast *ast) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  100. return locales.PluralRuleUnknown
  101. }
  102. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ast'
  103. func (ast *ast) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  104. return locales.PluralRuleUnknown
  105. }
  106. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  107. func (ast *ast) MonthAbbreviated(month time.Month) string {
  108. return ast.monthsAbbreviated[month]
  109. }
  110. // MonthsAbbreviated returns the locales abbreviated months
  111. func (ast *ast) MonthsAbbreviated() []string {
  112. return ast.monthsAbbreviated[1:]
  113. }
  114. // MonthNarrow returns the locales narrow month given the 'month' provided
  115. func (ast *ast) MonthNarrow(month time.Month) string {
  116. return ast.monthsNarrow[month]
  117. }
  118. // MonthsNarrow returns the locales narrow months
  119. func (ast *ast) MonthsNarrow() []string {
  120. return ast.monthsNarrow[1:]
  121. }
  122. // MonthWide returns the locales wide month given the 'month' provided
  123. func (ast *ast) MonthWide(month time.Month) string {
  124. return ast.monthsWide[month]
  125. }
  126. // MonthsWide returns the locales wide months
  127. func (ast *ast) MonthsWide() []string {
  128. return ast.monthsWide[1:]
  129. }
  130. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  131. func (ast *ast) WeekdayAbbreviated(weekday time.Weekday) string {
  132. return ast.daysAbbreviated[weekday]
  133. }
  134. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  135. func (ast *ast) WeekdaysAbbreviated() []string {
  136. return ast.daysAbbreviated
  137. }
  138. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  139. func (ast *ast) WeekdayNarrow(weekday time.Weekday) string {
  140. return ast.daysNarrow[weekday]
  141. }
  142. // WeekdaysNarrow returns the locales narrow weekdays
  143. func (ast *ast) WeekdaysNarrow() []string {
  144. return ast.daysNarrow
  145. }
  146. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  147. func (ast *ast) WeekdayShort(weekday time.Weekday) string {
  148. return ast.daysShort[weekday]
  149. }
  150. // WeekdaysShort returns the locales short weekdays
  151. func (ast *ast) WeekdaysShort() []string {
  152. return ast.daysShort
  153. }
  154. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  155. func (ast *ast) WeekdayWide(weekday time.Weekday) string {
  156. return ast.daysWide[weekday]
  157. }
  158. // WeekdaysWide returns the locales wide weekdays
  159. func (ast *ast) WeekdaysWide() []string {
  160. return ast.daysWide
  161. }
  162. // Decimal returns the decimal point of number
  163. func (ast *ast) Decimal() string {
  164. return ast.decimal
  165. }
  166. // Group returns the group of number
  167. func (ast *ast) Group() string {
  168. return ast.group
  169. }
  170. // Group returns the minus sign of number
  171. func (ast *ast) Minus() string {
  172. return ast.minus
  173. }
  174. // FmtNumber returns 'num' with digits/precision of 'v' for 'ast' and handles both Whole and Real numbers based on 'v'
  175. func (ast *ast) FmtNumber(num float64, v uint64) string {
  176. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  177. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  178. count := 0
  179. inWhole := v == 0
  180. b := make([]byte, 0, l)
  181. for i := len(s) - 1; i >= 0; i-- {
  182. if s[i] == '.' {
  183. b = append(b, ast.decimal[0])
  184. inWhole = true
  185. continue
  186. }
  187. if inWhole {
  188. if count == 3 {
  189. b = append(b, ast.group[0])
  190. count = 1
  191. } else {
  192. count++
  193. }
  194. }
  195. b = append(b, s[i])
  196. }
  197. if num < 0 {
  198. b = append(b, ast.minus[0])
  199. }
  200. // reverse
  201. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  202. b[i], b[j] = b[j], b[i]
  203. }
  204. return string(b)
  205. }
  206. // FmtPercent returns 'num' with digits/precision of 'v' for 'ast' and handles both Whole and Real numbers based on 'v'
  207. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  208. func (ast *ast) FmtPercent(num float64, v uint64) string {
  209. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  210. l := len(s) + 3
  211. b := make([]byte, 0, l)
  212. for i := len(s) - 1; i >= 0; i-- {
  213. if s[i] == '.' {
  214. b = append(b, ast.decimal[0])
  215. continue
  216. }
  217. b = append(b, s[i])
  218. }
  219. if num < 0 {
  220. b = append(b, ast.minus[0])
  221. }
  222. // reverse
  223. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  224. b[i], b[j] = b[j], b[i]
  225. }
  226. b = append(b, ast.percent...)
  227. return string(b)
  228. }
  229. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ast'
  230. func (ast *ast) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  231. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  232. symbol := ast.currencies[currency]
  233. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  234. count := 0
  235. inWhole := v == 0
  236. b := make([]byte, 0, l)
  237. for i := len(s) - 1; i >= 0; i-- {
  238. if s[i] == '.' {
  239. b = append(b, ast.decimal[0])
  240. inWhole = true
  241. continue
  242. }
  243. if inWhole {
  244. if count == 3 {
  245. b = append(b, ast.group[0])
  246. count = 1
  247. } else {
  248. count++
  249. }
  250. }
  251. b = append(b, s[i])
  252. }
  253. if num < 0 {
  254. b = append(b, ast.minus[0])
  255. }
  256. // reverse
  257. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  258. b[i], b[j] = b[j], b[i]
  259. }
  260. if int(v) < 2 {
  261. if v == 0 {
  262. b = append(b, ast.decimal...)
  263. }
  264. for i := 0; i < 2-int(v); i++ {
  265. b = append(b, '0')
  266. }
  267. }
  268. b = append(b, ast.currencyPositiveSuffix...)
  269. b = append(b, symbol...)
  270. return string(b)
  271. }
  272. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ast'
  273. // in accounting notation.
  274. func (ast *ast) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  275. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  276. symbol := ast.currencies[currency]
  277. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  278. count := 0
  279. inWhole := v == 0
  280. b := make([]byte, 0, l)
  281. for i := len(s) - 1; i >= 0; i-- {
  282. if s[i] == '.' {
  283. b = append(b, ast.decimal[0])
  284. inWhole = true
  285. continue
  286. }
  287. if inWhole {
  288. if count == 3 {
  289. b = append(b, ast.group[0])
  290. count = 1
  291. } else {
  292. count++
  293. }
  294. }
  295. b = append(b, s[i])
  296. }
  297. if num < 0 {
  298. b = append(b, ast.minus[0])
  299. }
  300. // reverse
  301. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  302. b[i], b[j] = b[j], b[i]
  303. }
  304. if int(v) < 2 {
  305. if v == 0 {
  306. b = append(b, ast.decimal...)
  307. }
  308. for i := 0; i < 2-int(v); i++ {
  309. b = append(b, '0')
  310. }
  311. }
  312. if num < 0 {
  313. b = append(b, ast.currencyNegativeSuffix...)
  314. b = append(b, symbol...)
  315. } else {
  316. b = append(b, ast.currencyPositiveSuffix...)
  317. b = append(b, symbol...)
  318. }
  319. return string(b)
  320. }
  321. // FmtDateShort returns the short date representation of 't' for 'ast'
  322. func (ast *ast) FmtDateShort(t time.Time) string {
  323. b := make([]byte, 0, 32)
  324. b = strconv.AppendInt(b, int64(t.Day()), 10)
  325. b = append(b, []byte{0x2f}...)
  326. b = strconv.AppendInt(b, int64(t.Month()), 10)
  327. b = append(b, []byte{0x2f}...)
  328. if t.Year() > 9 {
  329. b = append(b, strconv.Itoa(t.Year())[2:]...)
  330. } else {
  331. b = append(b, strconv.Itoa(t.Year())[1:]...)
  332. }
  333. return string(b)
  334. }
  335. // FmtDateMedium returns the medium date representation of 't' for 'ast'
  336. func (ast *ast) FmtDateMedium(t time.Time) string {
  337. b := make([]byte, 0, 32)
  338. b = strconv.AppendInt(b, int64(t.Day()), 10)
  339. b = append(b, []byte{0x20}...)
  340. b = append(b, ast.monthsAbbreviated[t.Month()]...)
  341. b = append(b, []byte{0x20}...)
  342. if t.Year() > 0 {
  343. b = strconv.AppendInt(b, int64(t.Year()), 10)
  344. } else {
  345. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  346. }
  347. return string(b)
  348. }
  349. // FmtDateLong returns the long date representation of 't' for 'ast'
  350. func (ast *ast) FmtDateLong(t time.Time) string {
  351. b := make([]byte, 0, 32)
  352. b = strconv.AppendInt(b, int64(t.Day()), 10)
  353. b = append(b, []byte{0x20}...)
  354. b = append(b, ast.monthsWide[t.Month()]...)
  355. b = append(b, []byte{0x20, 0x64, 0x65}...)
  356. b = append(b, []byte{0x20}...)
  357. if t.Year() > 0 {
  358. b = strconv.AppendInt(b, int64(t.Year()), 10)
  359. } else {
  360. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  361. }
  362. return string(b)
  363. }
  364. // FmtDateFull returns the full date representation of 't' for 'ast'
  365. func (ast *ast) FmtDateFull(t time.Time) string {
  366. b := make([]byte, 0, 32)
  367. b = append(b, ast.daysWide[t.Weekday()]...)
  368. b = append(b, []byte{0x2c, 0x20}...)
  369. b = strconv.AppendInt(b, int64(t.Day()), 10)
  370. b = append(b, []byte{0x20}...)
  371. b = append(b, ast.monthsWide[t.Month()]...)
  372. b = append(b, []byte{0x20, 0x64, 0x65}...)
  373. b = append(b, []byte{0x20}...)
  374. if t.Year() > 0 {
  375. b = strconv.AppendInt(b, int64(t.Year()), 10)
  376. } else {
  377. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  378. }
  379. return string(b)
  380. }
  381. // FmtTimeShort returns the short time representation of 't' for 'ast'
  382. func (ast *ast) FmtTimeShort(t time.Time) string {
  383. b := make([]byte, 0, 32)
  384. if t.Hour() < 10 {
  385. b = append(b, '0')
  386. }
  387. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  388. b = append(b, ast.timeSeparator...)
  389. if t.Minute() < 10 {
  390. b = append(b, '0')
  391. }
  392. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  393. return string(b)
  394. }
  395. // FmtTimeMedium returns the medium time representation of 't' for 'ast'
  396. func (ast *ast) FmtTimeMedium(t time.Time) string {
  397. b := make([]byte, 0, 32)
  398. if t.Hour() < 10 {
  399. b = append(b, '0')
  400. }
  401. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  402. b = append(b, ast.timeSeparator...)
  403. if t.Minute() < 10 {
  404. b = append(b, '0')
  405. }
  406. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  407. b = append(b, ast.timeSeparator...)
  408. if t.Second() < 10 {
  409. b = append(b, '0')
  410. }
  411. b = strconv.AppendInt(b, int64(t.Second()), 10)
  412. return string(b)
  413. }
  414. // FmtTimeLong returns the long time representation of 't' for 'ast'
  415. func (ast *ast) FmtTimeLong(t time.Time) string {
  416. b := make([]byte, 0, 32)
  417. if t.Hour() < 10 {
  418. b = append(b, '0')
  419. }
  420. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  421. b = append(b, ast.timeSeparator...)
  422. if t.Minute() < 10 {
  423. b = append(b, '0')
  424. }
  425. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  426. b = append(b, ast.timeSeparator...)
  427. if t.Second() < 10 {
  428. b = append(b, '0')
  429. }
  430. b = strconv.AppendInt(b, int64(t.Second()), 10)
  431. b = append(b, []byte{0x20}...)
  432. tz, _ := t.Zone()
  433. b = append(b, tz...)
  434. return string(b)
  435. }
  436. // FmtTimeFull returns the full time representation of 't' for 'ast'
  437. func (ast *ast) FmtTimeFull(t time.Time) string {
  438. b := make([]byte, 0, 32)
  439. if t.Hour() < 10 {
  440. b = append(b, '0')
  441. }
  442. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  443. b = append(b, ast.timeSeparator...)
  444. if t.Minute() < 10 {
  445. b = append(b, '0')
  446. }
  447. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  448. b = append(b, ast.timeSeparator...)
  449. if t.Second() < 10 {
  450. b = append(b, '0')
  451. }
  452. b = strconv.AppendInt(b, int64(t.Second()), 10)
  453. b = append(b, []byte{0x20}...)
  454. tz, _ := t.Zone()
  455. if btz, ok := ast.timezones[tz]; ok {
  456. b = append(b, btz...)
  457. } else {
  458. b = append(b, tz...)
  459. }
  460. return string(b)
  461. }