ga.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. package ga
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ga 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. currencyNegativePrefix 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 'ga' locale
  41. func New() locales.Translator {
  42. return &ga{
  43. locale: "ga",
  44. pluralsCardinal: []locales.PluralRule{2, 3, 4, 5, 6},
  45. pluralsOrdinal: []locales.PluralRule{2, 6},
  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", "BYR", "BZD", "CA$", "CDF", "CHE ", "CHF", "CHW ", "CLE", "CLF", "CLP", "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", "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. currencyNegativePrefix: "(",
  56. currencyNegativeSuffix: ")",
  57. monthsAbbreviated: []string{"", "Ean", "Feabh", "Márta", "Aib", "Beal", "Meith", "Iúil", "Lún", "MFómh", "DFómh", "Samh", "Noll"},
  58. monthsNarrow: []string{"", "E", "F", "M", "A", "B", "M", "I", "L", "M", "D", "S", "N"},
  59. monthsWide: []string{"", "Eanáir", "Feabhra", "Márta", "Aibreán", "Bealtaine", "Meitheamh", "Iúil", "Lúnasa", "Meán Fómhair", "Deireadh Fómhair", "Samhain", "Nollaig"},
  60. daysAbbreviated: []string{"Domh", "Luan", "Máirt", "Céad", "Déar", "Aoine", "Sath"},
  61. daysNarrow: []string{"D", "L", "M", "C", "D", "A", "S"},
  62. daysShort: []string{"Do", "Lu", "Má", "Cé", "Dé", "Ao", "Sa"},
  63. daysWide: []string{"Dé Domhnaigh", "Dé Luain", "Dé Máirt", "Dé Céadaoin", "Déardaoin", "Dé hAoine", "Dé Sathairn"},
  64. periodsAbbreviated: []string{"a.m.", "p.m."},
  65. periodsNarrow: []string{"a", "p"},
  66. periodsWide: []string{"a.m.", "p.m."},
  67. erasAbbreviated: []string{"RC", "AD"},
  68. erasNarrow: []string{"RC", "AD"},
  69. erasWide: []string{"Roimh Chríost", "Anno Domini"},
  70. timezones: map[string]string{"EDT": "Am Samhraidh an Oirthir", "WIT": "Am Oirthear na hIndinéise", "TMT": "Am Caighdeánach na Tuircméanastáine", "JST": "Am Caighdeánach na Seapáine", "MESZ": "Am Samhraidh Lár na hEorpa", "MST": "Am Caighdeánach na Sléibhte", "CHAST": "Am Caighdeánach Chatham", "CHADT": "Am Samhraidh Chatham", "PDT": "Am Samhraidh an Aigéin Chiúin", "BOT": "Am na Bolaive", "WAST": "Am Samhraidh Iarthar na hAfraice", "TMST": "Am Samhraidh na Tuircméanastáine", "SRT": "Am Shuranam", "WEZ": "Am Caighdeánach Iarthar na hEorpa", "CAT": "Am Lár na hAfraice", "WART": "Am Caighdeánach Iarthar na hAirgintíne", "JDT": "Am Samhraidh na Seapáine", "MEZ": "Am Caighdeánach Lár na hEorpa", "NZDT": "Am Samhraidh na Nua-Shéalainne", "AST": "Am Caighdeánach an Atlantaigh", "WITA": "Am Lár na hIndinéise", "ACWST": "Am Caighdeánach Mheániarthar na hAstráile", "ChST": "Am Caighdeánach Seamórach", "HNT": "Am Caighdeánach Thalamh an Éisc", "MYT": "Am na Malaeisia", "UYT": "Am Caighdeánach Uragua", "HAST": "Am Caighdeánach Haváí-Ailiúit", "WARST": "Am Samhraidh Iarthar na hAirgintíne", "BT": "Am na Bútáine", "UYST": "Am Samhraidh Uragua", "MDT": "Am Samhraidh na Sléibhte", "HADT": "Am Samhraidh Haváí-Ailiúit", "SGT": "Am Caighdeánach Shingeapór", "WAT": "Am Caighdeánach Iarthar na hAfraice", "COST": "Am Samhraidh na Colóime", "HKT": "Am Caighdeánach Hong Cong", "AKST": "Am Caighdeánach Alasca", "AKDT": "Am Samhraidh Alasca", "COT": "Am Caighdeánach na Colóime", "GFT": "Am Ghuáin na Fraince", "OEZ": "Am Caighdeánach Oirthear na hEorpa", "GYT": "Am na Guáine", "CST": "Am Caighdeánach Lárnach", "CLST": "Am Samhraidh na Sile", "WESZ": "Am Samhraidh Iarthar na hEorpa", "ACWDT": "Am Samhraidh Mheániarthar na hAstráile", "AWST": "Am Caighdeánach Iarthar na hAstráile", "CDT": "Am Samhraidh Lárnach", "WIB": "Am Iarthar na hIndinéise", "OESZ": "Am Samhraidh Oirthear na hEorpa", "ART": "Am Caighdeánach na hAirgintíne", "LHDT": "Am Samhraidh Lord Howe", "AEST": "Am Caighdeánach Oirthear na hAstráile", "ACDT": "Am Samhraidh Lár na hAstráile", "ARST": "Am Samhraidh na hAirgintíne", "LHST": "Am Caighdeánach Lord Howe", "AWDT": "Am Samhraidh Iarthar na hAstráile", "EST": "Am Caighdeánach an Oirthir", "IST": "Am Caighdeánach na hIndia", "GMT": "Meán-Am Greenwich", "PST": "Am Caighdeánach an Aigéin Chiúin", "NZST": "Am Caighdeánach na Nua-Shéalainne", "SAST": "Am Caighdeánach na hAfraice Theas", "EAT": "Am Oirthear na hAfraice", "ACST": "Am Caighdeánach Lár na hAstráile", "CLT": "Am Caighdeánach na Sile", "ADT": "Am Samhraidh an Atlantaigh", "HKST": "Am Samhraidh Hong Cong", "HAT": "Am Samhraidh Thalamh an Éisc", "VET": "Am Veiniséala", "AEDT": "Am Samhraidh Oirthear na hAstráile", "∅∅∅": "Am Samhraidh Bhrasília", "ECT": "Am Eacuadór"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (ga *ga) Locale() string {
  75. return ga.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'ga'
  78. func (ga *ga) PluralsCardinal() []locales.PluralRule {
  79. return ga.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ga'
  82. func (ga *ga) PluralsOrdinal() []locales.PluralRule {
  83. return ga.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'ga'
  86. func (ga *ga) PluralsRange() []locales.PluralRule {
  87. return ga.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ga'
  90. func (ga *ga) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. if n == 1 {
  93. return locales.PluralRuleOne
  94. } else if n == 2 {
  95. return locales.PluralRuleTwo
  96. } else if n >= 3 && n <= 6 {
  97. return locales.PluralRuleFew
  98. } else if n >= 7 && n <= 10 {
  99. return locales.PluralRuleMany
  100. }
  101. return locales.PluralRuleOther
  102. }
  103. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ga'
  104. func (ga *ga) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  105. n := math.Abs(num)
  106. if n == 1 {
  107. return locales.PluralRuleOne
  108. }
  109. return locales.PluralRuleOther
  110. }
  111. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ga'
  112. func (ga *ga) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  113. return locales.PluralRuleUnknown
  114. }
  115. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  116. func (ga *ga) MonthAbbreviated(month time.Month) string {
  117. return ga.monthsAbbreviated[month]
  118. }
  119. // MonthsAbbreviated returns the locales abbreviated months
  120. func (ga *ga) MonthsAbbreviated() []string {
  121. return ga.monthsAbbreviated[1:]
  122. }
  123. // MonthNarrow returns the locales narrow month given the 'month' provided
  124. func (ga *ga) MonthNarrow(month time.Month) string {
  125. return ga.monthsNarrow[month]
  126. }
  127. // MonthsNarrow returns the locales narrow months
  128. func (ga *ga) MonthsNarrow() []string {
  129. return ga.monthsNarrow[1:]
  130. }
  131. // MonthWide returns the locales wide month given the 'month' provided
  132. func (ga *ga) MonthWide(month time.Month) string {
  133. return ga.monthsWide[month]
  134. }
  135. // MonthsWide returns the locales wide months
  136. func (ga *ga) MonthsWide() []string {
  137. return ga.monthsWide[1:]
  138. }
  139. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  140. func (ga *ga) WeekdayAbbreviated(weekday time.Weekday) string {
  141. return ga.daysAbbreviated[weekday]
  142. }
  143. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  144. func (ga *ga) WeekdaysAbbreviated() []string {
  145. return ga.daysAbbreviated
  146. }
  147. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  148. func (ga *ga) WeekdayNarrow(weekday time.Weekday) string {
  149. return ga.daysNarrow[weekday]
  150. }
  151. // WeekdaysNarrow returns the locales narrow weekdays
  152. func (ga *ga) WeekdaysNarrow() []string {
  153. return ga.daysNarrow
  154. }
  155. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  156. func (ga *ga) WeekdayShort(weekday time.Weekday) string {
  157. return ga.daysShort[weekday]
  158. }
  159. // WeekdaysShort returns the locales short weekdays
  160. func (ga *ga) WeekdaysShort() []string {
  161. return ga.daysShort
  162. }
  163. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  164. func (ga *ga) WeekdayWide(weekday time.Weekday) string {
  165. return ga.daysWide[weekday]
  166. }
  167. // WeekdaysWide returns the locales wide weekdays
  168. func (ga *ga) WeekdaysWide() []string {
  169. return ga.daysWide
  170. }
  171. // FmtNumber returns 'num' with digits/precision of 'v' for 'ga' and handles both Whole and Real numbers based on 'v'
  172. func (ga *ga) FmtNumber(num float64, v uint64) string {
  173. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  174. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  175. count := 0
  176. inWhole := v == 0
  177. b := make([]byte, 0, l)
  178. for i := len(s) - 1; i >= 0; i-- {
  179. if s[i] == '.' {
  180. b = append(b, ga.decimal[0])
  181. inWhole = true
  182. continue
  183. }
  184. if inWhole {
  185. if count == 3 {
  186. b = append(b, ga.group[0])
  187. count = 1
  188. } else {
  189. count++
  190. }
  191. }
  192. b = append(b, s[i])
  193. }
  194. if num < 0 {
  195. b = append(b, ga.minus[0])
  196. }
  197. // reverse
  198. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  199. b[i], b[j] = b[j], b[i]
  200. }
  201. return string(b)
  202. }
  203. // FmtPercent returns 'num' with digits/precision of 'v' for 'ga' and handles both Whole and Real numbers based on 'v'
  204. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  205. func (ga *ga) FmtPercent(num float64, v uint64) string {
  206. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  207. l := len(s) + 3
  208. b := make([]byte, 0, l)
  209. for i := len(s) - 1; i >= 0; i-- {
  210. if s[i] == '.' {
  211. b = append(b, ga.decimal[0])
  212. continue
  213. }
  214. b = append(b, s[i])
  215. }
  216. if num < 0 {
  217. b = append(b, ga.minus[0])
  218. }
  219. // reverse
  220. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  221. b[i], b[j] = b[j], b[i]
  222. }
  223. b = append(b, ga.percent...)
  224. return string(b)
  225. }
  226. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ga'
  227. func (ga *ga) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  228. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  229. symbol := ga.currencies[currency]
  230. l := len(s) + len(symbol) + 2 + 1*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, ga.decimal[0])
  237. inWhole = true
  238. continue
  239. }
  240. if inWhole {
  241. if count == 3 {
  242. b = append(b, ga.group[0])
  243. count = 1
  244. } else {
  245. count++
  246. }
  247. }
  248. b = append(b, s[i])
  249. }
  250. for j := len(symbol) - 1; j >= 0; j-- {
  251. b = append(b, symbol[j])
  252. }
  253. if num < 0 {
  254. b = append(b, ga.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, ga.decimal...)
  263. }
  264. for i := 0; i < 2-int(v); i++ {
  265. b = append(b, '0')
  266. }
  267. }
  268. return string(b)
  269. }
  270. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ga'
  271. // in accounting notation.
  272. func (ga *ga) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  273. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  274. symbol := ga.currencies[currency]
  275. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  276. count := 0
  277. inWhole := v == 0
  278. b := make([]byte, 0, l)
  279. for i := len(s) - 1; i >= 0; i-- {
  280. if s[i] == '.' {
  281. b = append(b, ga.decimal[0])
  282. inWhole = true
  283. continue
  284. }
  285. if inWhole {
  286. if count == 3 {
  287. b = append(b, ga.group[0])
  288. count = 1
  289. } else {
  290. count++
  291. }
  292. }
  293. b = append(b, s[i])
  294. }
  295. if num < 0 {
  296. for j := len(symbol) - 1; j >= 0; j-- {
  297. b = append(b, symbol[j])
  298. }
  299. b = append(b, ga.currencyNegativePrefix[0])
  300. } else {
  301. for j := len(symbol) - 1; j >= 0; j-- {
  302. b = append(b, symbol[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, ga.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, ga.currencyNegativeSuffix...)
  319. }
  320. return string(b)
  321. }
  322. // FmtDateShort returns the short date representation of 't' for 'ga'
  323. func (ga *ga) FmtDateShort(t time.Time) string {
  324. b := make([]byte, 0, 32)
  325. if t.Day() < 10 {
  326. b = append(b, '0')
  327. }
  328. b = strconv.AppendInt(b, int64(t.Day()), 10)
  329. b = append(b, []byte{0x2f}...)
  330. if t.Month() < 10 {
  331. b = append(b, '0')
  332. }
  333. b = strconv.AppendInt(b, int64(t.Month()), 10)
  334. b = append(b, []byte{0x2f}...)
  335. b = strconv.AppendInt(b, int64(t.Year()), 10)
  336. return string(b)
  337. }
  338. // FmtDateMedium returns the medium date representation of 't' for 'ga'
  339. func (ga *ga) FmtDateMedium(t time.Time) string {
  340. b := make([]byte, 0, 32)
  341. b = strconv.AppendInt(b, int64(t.Day()), 10)
  342. b = append(b, []byte{0x20}...)
  343. b = append(b, ga.monthsAbbreviated[t.Month()]...)
  344. b = append(b, []byte{0x20}...)
  345. b = strconv.AppendInt(b, int64(t.Year()), 10)
  346. return string(b)
  347. }
  348. // FmtDateLong returns the long date representation of 't' for 'ga'
  349. func (ga *ga) FmtDateLong(t time.Time) string {
  350. b := make([]byte, 0, 32)
  351. b = strconv.AppendInt(b, int64(t.Day()), 10)
  352. b = append(b, []byte{0x20}...)
  353. b = append(b, ga.monthsWide[t.Month()]...)
  354. b = append(b, []byte{0x20}...)
  355. b = strconv.AppendInt(b, int64(t.Year()), 10)
  356. return string(b)
  357. }
  358. // FmtDateFull returns the full date representation of 't' for 'ga'
  359. func (ga *ga) FmtDateFull(t time.Time) string {
  360. b := make([]byte, 0, 32)
  361. b = append(b, ga.daysWide[t.Weekday()]...)
  362. b = append(b, []byte{0x20}...)
  363. b = strconv.AppendInt(b, int64(t.Day()), 10)
  364. b = append(b, []byte{0x20}...)
  365. b = append(b, ga.monthsWide[t.Month()]...)
  366. b = append(b, []byte{0x20}...)
  367. b = strconv.AppendInt(b, int64(t.Year()), 10)
  368. return string(b)
  369. }
  370. // FmtTimeShort returns the short time representation of 't' for 'ga'
  371. func (ga *ga) FmtTimeShort(t time.Time) string {
  372. b := make([]byte, 0, 32)
  373. if t.Hour() < 10 {
  374. b = append(b, '0')
  375. }
  376. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  377. b = append(b, ga.timeSeparator...)
  378. if t.Minute() < 10 {
  379. b = append(b, '0')
  380. }
  381. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  382. return string(b)
  383. }
  384. // FmtTimeMedium returns the medium time representation of 't' for 'ga'
  385. func (ga *ga) FmtTimeMedium(t time.Time) string {
  386. b := make([]byte, 0, 32)
  387. if t.Hour() < 10 {
  388. b = append(b, '0')
  389. }
  390. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  391. b = append(b, ga.timeSeparator...)
  392. if t.Minute() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  396. b = append(b, ga.timeSeparator...)
  397. if t.Second() < 10 {
  398. b = append(b, '0')
  399. }
  400. b = strconv.AppendInt(b, int64(t.Second()), 10)
  401. return string(b)
  402. }
  403. // FmtTimeLong returns the long time representation of 't' for 'ga'
  404. func (ga *ga) FmtTimeLong(t time.Time) string {
  405. b := make([]byte, 0, 32)
  406. if t.Hour() < 10 {
  407. b = append(b, '0')
  408. }
  409. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  410. b = append(b, ga.timeSeparator...)
  411. if t.Minute() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  415. b = append(b, ga.timeSeparator...)
  416. if t.Second() < 10 {
  417. b = append(b, '0')
  418. }
  419. b = strconv.AppendInt(b, int64(t.Second()), 10)
  420. b = append(b, []byte{0x20}...)
  421. tz, _ := t.Zone()
  422. b = append(b, tz...)
  423. return string(b)
  424. }
  425. // FmtTimeFull returns the full time representation of 't' for 'ga'
  426. func (ga *ga) FmtTimeFull(t time.Time) string {
  427. b := make([]byte, 0, 32)
  428. if t.Hour() < 10 {
  429. b = append(b, '0')
  430. }
  431. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  432. b = append(b, ga.timeSeparator...)
  433. if t.Minute() < 10 {
  434. b = append(b, '0')
  435. }
  436. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  437. b = append(b, ga.timeSeparator...)
  438. if t.Second() < 10 {
  439. b = append(b, '0')
  440. }
  441. b = strconv.AppendInt(b, int64(t.Second()), 10)
  442. b = append(b, []byte{0x20}...)
  443. tz, _ := t.Zone()
  444. if btz, ok := ga.timezones[tz]; ok {
  445. b = append(b, btz...)
  446. } else {
  447. b = append(b, tz...)
  448. }
  449. return string(b)
  450. }