gd.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. package gd
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type gd 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 'gd' locale
  41. func New() locales.Translator {
  42. return &gd{
  43. locale: "gd",
  44. pluralsCardinal: []locales.PluralRule{2, 3, 4, 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", "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", "JP¥", "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{"", "Faoi", "Gearr", "Màrt", "Gibl", "Cèit", "Ògmh", "Iuch", "Lùna", "Sult", "Dàmh", "Samh", "Dùbh"},
  58. monthsNarrow: []string{"", "F", "G", "M", "G", "C", "Ò", "I", "L", "S", "D", "S", "D"},
  59. monthsWide: []string{"", "dhen Fhaoilleach", "dhen Ghearran", "dhen Mhàrt", "dhen Ghiblean", "dhen Chèitean", "dhen Ògmhios", "dhen Iuchar", "dhen Lùnastal", "dhen t-Sultain", "dhen Dàmhair", "dhen t-Samhain", "dhen Dùbhlachd"},
  60. daysAbbreviated: []string{"DiD", "DiL", "DiM", "DiC", "Dia", "Dih", "DiS"},
  61. daysNarrow: []string{"D", "L", "M", "C", "A", "H", "S"},
  62. daysShort: []string{"Dò", "Lu", "Mà", "Ci", "Da", "hA", "Sa"},
  63. daysWide: []string{"DiDòmhnaich", "DiLuain", "DiMàirt", "DiCiadain", "DiarDaoin", "DihAoine", "DiSathairne"},
  64. periodsAbbreviated: []string{"m", "f"},
  65. periodsNarrow: []string{"m", "f"},
  66. periodsWide: []string{"m", "f"},
  67. erasAbbreviated: []string{"RC", "AD"},
  68. erasNarrow: []string{"R", "A"},
  69. erasWide: []string{"Ro Chrìosta", "An dèidh Chrìosta"},
  70. timezones: map[string]string{"HKT": "Bun-àm Hong Kong", "HNT": "Bun-àm Talamh an Èisg", "WIB": "Àm nan Innd-Innse an Iar", "MST": "Bun-àm Macàthu", "LHST": "Bun-àm Lord Howe", "JDT": "Tìde samhraidh na Seapaine", "CLST": "Tìde samhraidh na Sile", "WIT": "Àm nan Innd-Innse an Ear", "HAST": "Bun-àm nan Eileanan Hawai’i ’s Aleutach", "WAT": "Bun-àm Afraga an Iar", "WARST": "Tìde samhraidh na h-Argantaine Siaraich", "GYT": "Àm Guidheàna", "AST": "Bun-àm a’ Chuain Siar", "TMST": "Tìde samhraidh Turcmanastàin", "AWST": "Bun-àm Astràilia an Iar", "CHAST": "Bun-àm Chatham", "COST": "Tìde samhraidh Coloimbia", "∅∅∅": "Tìde samhraidh Acre", "WART": "Bun-àm na h-Argantaine Siaraich", "IST": "Àm nan Innseachan", "GMT": "Greenwich Mean Time", "ARST": "Tìde samhraidh na h-Argantaine", "MYT": "Àm Mhalaidhsea", "CDT": "Tìde samhraidh Meadhan Aimeireaga a Tuath", "ACWST": "Bun-àm Meadhan Astràilia an Iar", "ACWDT": "Tìde samhraidh Meadhan Astràilia an Iar", "OESZ": "Tìde samhraidh na Roinn-Eòrpa an Ear", "EAT": "Àm Afraga an Ear", "AKST": "Bun-àm Alaska", "CST": "Bun-àm Meadhan Aimeireaga a Tuath", "HADT": "Tìde Samhraidh nan Eileanan Hawai’i ’s Aleutach", "HAT": "Tìde samhraidh Talamh an Èisg", "MDT": "Tìde samhraidh Macàthu", "PST": "Bun-àm a’ Chuain Sèimh", "MEZ": "Bun-àm Meadhan na Roinn-Eòrpa", "NZST": "Bun-àm Shealainn Nuaidh", "UYT": "Bun-àm Uruguaidh", "AEDT": "Tìde samhraidh Astràilia an Ear", "ART": "Bun-àm na h-Argantaine", "AKDT": "Tìde samhraidh Alaska", "JST": "Bun-àm na Seapaine", "UYST": "Tìde samhraidh Uruguaidh", "ECT": "Àm Eacuadoir", "BT": "Àm Butàin", "MESZ": "Tìde samhraidh Meadhan na Roinn-Eòrpa", "WEZ": "Bun-àm na Roinn-Eòrpa an Iar", "WESZ": "Tìde samhraidh na Roinn-Eòrpa an Iar", "ACST": "Bun-àm Meadhan Astràilia", "PDT": "Tìde samhraidh a’ Chuain Sèimh", "NZDT": "Tìde samhraidh Shealainn Nuaidh", "COT": "Bun-àm Coloimbia", "ADT": "Tìde samhraidh a’ Chuain Siar", "SGT": "Àm Singeapòr", "AWDT": "Tìde samhraidh Astràilia an Iar", "ChST": "Àm Chamorro", "HKST": "Tìde samhraidh Hong Kong", "CHADT": "Tìde samhraidh Chatham", "WAST": "Tìde Samhraidh Afraga an Iar", "GFT": "Àm Guidheàna na Frainge", "WITA": "Àm Meadhan nan Innd-Innse", "SRT": "Àm Suranaim", "BOT": "Àm Boilibhia", "EST": "Bun-àm Aimeireaga a Tuath an Ear", "EDT": "Tìde samhraidh Aimeireaga a Tuath an Ear", "SAST": "Àm Afraga a Deas", "OEZ": "Bun-àm na Roinn-Eòrpa an Ear", "ACDT": "Tìde samhraidh Meadhan Astràilia", "VET": "Àm na Bheiniseala", "TMT": "Bun-àm Turcmanastàin", "LHDT": "Tìde samhraidh Lord Howe", "AEST": "Bun-àm Astràilia an Ear", "CLT": "Bun-àm na Sile", "CAT": "Àm Meadhan Afraga"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (gd *gd) Locale() string {
  75. return gd.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'gd'
  78. func (gd *gd) PluralsCardinal() []locales.PluralRule {
  79. return gd.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'gd'
  82. func (gd *gd) PluralsOrdinal() []locales.PluralRule {
  83. return gd.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'gd'
  86. func (gd *gd) PluralsRange() []locales.PluralRule {
  87. return gd.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'gd'
  90. func (gd *gd) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. if n == 1 || n == 11 {
  93. return locales.PluralRuleOne
  94. } else if n == 2 || n == 12 {
  95. return locales.PluralRuleTwo
  96. } else if (n >= 3 && n <= 10) || (n >= 13 && n <= 19) {
  97. return locales.PluralRuleFew
  98. }
  99. return locales.PluralRuleOther
  100. }
  101. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'gd'
  102. func (gd *gd) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  103. return locales.PluralRuleUnknown
  104. }
  105. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'gd'
  106. func (gd *gd) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  107. return locales.PluralRuleUnknown
  108. }
  109. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  110. func (gd *gd) MonthAbbreviated(month time.Month) string {
  111. return gd.monthsAbbreviated[month]
  112. }
  113. // MonthsAbbreviated returns the locales abbreviated months
  114. func (gd *gd) MonthsAbbreviated() []string {
  115. return gd.monthsAbbreviated[1:]
  116. }
  117. // MonthNarrow returns the locales narrow month given the 'month' provided
  118. func (gd *gd) MonthNarrow(month time.Month) string {
  119. return gd.monthsNarrow[month]
  120. }
  121. // MonthsNarrow returns the locales narrow months
  122. func (gd *gd) MonthsNarrow() []string {
  123. return gd.monthsNarrow[1:]
  124. }
  125. // MonthWide returns the locales wide month given the 'month' provided
  126. func (gd *gd) MonthWide(month time.Month) string {
  127. return gd.monthsWide[month]
  128. }
  129. // MonthsWide returns the locales wide months
  130. func (gd *gd) MonthsWide() []string {
  131. return gd.monthsWide[1:]
  132. }
  133. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  134. func (gd *gd) WeekdayAbbreviated(weekday time.Weekday) string {
  135. return gd.daysAbbreviated[weekday]
  136. }
  137. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  138. func (gd *gd) WeekdaysAbbreviated() []string {
  139. return gd.daysAbbreviated
  140. }
  141. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  142. func (gd *gd) WeekdayNarrow(weekday time.Weekday) string {
  143. return gd.daysNarrow[weekday]
  144. }
  145. // WeekdaysNarrow returns the locales narrow weekdays
  146. func (gd *gd) WeekdaysNarrow() []string {
  147. return gd.daysNarrow
  148. }
  149. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  150. func (gd *gd) WeekdayShort(weekday time.Weekday) string {
  151. return gd.daysShort[weekday]
  152. }
  153. // WeekdaysShort returns the locales short weekdays
  154. func (gd *gd) WeekdaysShort() []string {
  155. return gd.daysShort
  156. }
  157. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  158. func (gd *gd) WeekdayWide(weekday time.Weekday) string {
  159. return gd.daysWide[weekday]
  160. }
  161. // WeekdaysWide returns the locales wide weekdays
  162. func (gd *gd) WeekdaysWide() []string {
  163. return gd.daysWide
  164. }
  165. // FmtNumber returns 'num' with digits/precision of 'v' for 'gd' and handles both Whole and Real numbers based on 'v'
  166. func (gd *gd) FmtNumber(num float64, v uint64) string {
  167. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  168. l := len(s) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  169. count := 0
  170. inWhole := v == 0
  171. b := make([]byte, 0, l)
  172. for i := len(s) - 1; i >= 0; i-- {
  173. if s[i] == '.' {
  174. for j := len(gd.decimal) - 1; j >= 0; j-- {
  175. b = append(b, gd.decimal[j])
  176. }
  177. inWhole = true
  178. continue
  179. }
  180. if inWhole {
  181. if count == 3 {
  182. for j := len(gd.group) - 1; j >= 0; j-- {
  183. b = append(b, gd.group[j])
  184. }
  185. count = 1
  186. } else {
  187. count++
  188. }
  189. }
  190. b = append(b, s[i])
  191. }
  192. if num < 0 {
  193. for j := len(gd.minus) - 1; j >= 0; j-- {
  194. b = append(b, gd.minus[j])
  195. }
  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 'gd' 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 (gd *gd) FmtPercent(num float64, v uint64) string {
  206. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  207. l := len(s) + 8
  208. b := make([]byte, 0, l)
  209. for i := len(s) - 1; i >= 0; i-- {
  210. if s[i] == '.' {
  211. for j := len(gd.decimal) - 1; j >= 0; j-- {
  212. b = append(b, gd.decimal[j])
  213. }
  214. continue
  215. }
  216. b = append(b, s[i])
  217. }
  218. if num < 0 {
  219. for j := len(gd.minus) - 1; j >= 0; j-- {
  220. b = append(b, gd.minus[j])
  221. }
  222. }
  223. // reverse
  224. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  225. b[i], b[j] = b[j], b[i]
  226. }
  227. b = append(b, gd.percent...)
  228. return string(b)
  229. }
  230. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'gd'
  231. func (gd *gd) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  232. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  233. symbol := gd.currencies[currency]
  234. l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  235. count := 0
  236. inWhole := v == 0
  237. b := make([]byte, 0, l)
  238. for i := len(s) - 1; i >= 0; i-- {
  239. if s[i] == '.' {
  240. for j := len(gd.decimal) - 1; j >= 0; j-- {
  241. b = append(b, gd.decimal[j])
  242. }
  243. inWhole = true
  244. continue
  245. }
  246. if inWhole {
  247. if count == 3 {
  248. for j := len(gd.group) - 1; j >= 0; j-- {
  249. b = append(b, gd.group[j])
  250. }
  251. count = 1
  252. } else {
  253. count++
  254. }
  255. }
  256. b = append(b, s[i])
  257. }
  258. for j := len(symbol) - 1; j >= 0; j-- {
  259. b = append(b, symbol[j])
  260. }
  261. if num < 0 {
  262. for j := len(gd.minus) - 1; j >= 0; j-- {
  263. b = append(b, gd.minus[j])
  264. }
  265. }
  266. // reverse
  267. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  268. b[i], b[j] = b[j], b[i]
  269. }
  270. if int(v) < 2 {
  271. if v == 0 {
  272. b = append(b, gd.decimal...)
  273. }
  274. for i := 0; i < 2-int(v); i++ {
  275. b = append(b, '0')
  276. }
  277. }
  278. return string(b)
  279. }
  280. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'gd'
  281. // in accounting notation.
  282. func (gd *gd) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  283. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  284. symbol := gd.currencies[currency]
  285. l := len(s) + len(symbol) + 8 + 2*len(s[:len(s)-int(v)-1])/3
  286. count := 0
  287. inWhole := v == 0
  288. b := make([]byte, 0, l)
  289. for i := len(s) - 1; i >= 0; i-- {
  290. if s[i] == '.' {
  291. for j := len(gd.decimal) - 1; j >= 0; j-- {
  292. b = append(b, gd.decimal[j])
  293. }
  294. inWhole = true
  295. continue
  296. }
  297. if inWhole {
  298. if count == 3 {
  299. for j := len(gd.group) - 1; j >= 0; j-- {
  300. b = append(b, gd.group[j])
  301. }
  302. count = 1
  303. } else {
  304. count++
  305. }
  306. }
  307. b = append(b, s[i])
  308. }
  309. if num < 0 {
  310. for j := len(symbol) - 1; j >= 0; j-- {
  311. b = append(b, symbol[j])
  312. }
  313. b = append(b, gd.currencyNegativePrefix[0])
  314. } else {
  315. for j := len(symbol) - 1; j >= 0; j-- {
  316. b = append(b, symbol[j])
  317. }
  318. }
  319. // reverse
  320. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  321. b[i], b[j] = b[j], b[i]
  322. }
  323. if int(v) < 2 {
  324. if v == 0 {
  325. b = append(b, gd.decimal...)
  326. }
  327. for i := 0; i < 2-int(v); i++ {
  328. b = append(b, '0')
  329. }
  330. }
  331. if num < 0 {
  332. b = append(b, gd.currencyNegativeSuffix...)
  333. }
  334. return string(b)
  335. }
  336. // FmtDateShort returns the short date representation of 't' for 'gd'
  337. func (gd *gd) FmtDateShort(t time.Time) string {
  338. b := make([]byte, 0, 32)
  339. if t.Day() < 10 {
  340. b = append(b, '0')
  341. }
  342. b = strconv.AppendInt(b, int64(t.Day()), 10)
  343. b = append(b, []byte{0x2f}...)
  344. if t.Month() < 10 {
  345. b = append(b, '0')
  346. }
  347. b = strconv.AppendInt(b, int64(t.Month()), 10)
  348. b = append(b, []byte{0x2f}...)
  349. b = strconv.AppendInt(b, int64(t.Year()), 10)
  350. return string(b)
  351. }
  352. // FmtDateMedium returns the medium date representation of 't' for 'gd'
  353. func (gd *gd) FmtDateMedium(t time.Time) string {
  354. b := make([]byte, 0, 32)
  355. b = strconv.AppendInt(b, int64(t.Day()), 10)
  356. b = append(b, []byte{0x20}...)
  357. b = append(b, gd.monthsAbbreviated[t.Month()]...)
  358. b = append(b, []byte{0x20}...)
  359. b = strconv.AppendInt(b, int64(t.Year()), 10)
  360. return string(b)
  361. }
  362. // FmtDateLong returns the long date representation of 't' for 'gd'
  363. func (gd *gd) FmtDateLong(t time.Time) string {
  364. b := make([]byte, 0, 32)
  365. b = strconv.AppendInt(b, int64(t.Day()), 10)
  366. b = append(b, []byte{0x64, 0x27, 0x6d, 0x68, 0x27, 0x20}...)
  367. b = append(b, gd.monthsWide[t.Month()]...)
  368. b = append(b, []byte{0x20}...)
  369. b = strconv.AppendInt(b, int64(t.Year()), 10)
  370. return string(b)
  371. }
  372. // FmtDateFull returns the full date representation of 't' for 'gd'
  373. func (gd *gd) FmtDateFull(t time.Time) string {
  374. b := make([]byte, 0, 32)
  375. b = append(b, gd.daysWide[t.Weekday()]...)
  376. b = append(b, []byte{0x2c, 0x20}...)
  377. b = strconv.AppendInt(b, int64(t.Day()), 10)
  378. b = append(b, []byte{0x2c, 0x20, 0x64, 0x27, 0x6d, 0x68, 0x27, 0x20}...)
  379. b = append(b, gd.monthsWide[t.Month()]...)
  380. b = append(b, []byte{0x20}...)
  381. b = strconv.AppendInt(b, int64(t.Year()), 10)
  382. return string(b)
  383. }
  384. // FmtTimeShort returns the short time representation of 't' for 'gd'
  385. func (gd *gd) FmtTimeShort(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, gd.timeSeparator...)
  392. if t.Minute() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  396. return string(b)
  397. }
  398. // FmtTimeMedium returns the medium time representation of 't' for 'gd'
  399. func (gd *gd) FmtTimeMedium(t time.Time) string {
  400. b := make([]byte, 0, 32)
  401. if t.Hour() < 10 {
  402. b = append(b, '0')
  403. }
  404. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  405. b = append(b, gd.timeSeparator...)
  406. if t.Minute() < 10 {
  407. b = append(b, '0')
  408. }
  409. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  410. b = append(b, gd.timeSeparator...)
  411. if t.Second() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Second()), 10)
  415. return string(b)
  416. }
  417. // FmtTimeLong returns the long time representation of 't' for 'gd'
  418. func (gd *gd) FmtTimeLong(t time.Time) string {
  419. b := make([]byte, 0, 32)
  420. if t.Hour() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  424. b = append(b, gd.timeSeparator...)
  425. if t.Minute() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  429. b = append(b, gd.timeSeparator...)
  430. if t.Second() < 10 {
  431. b = append(b, '0')
  432. }
  433. b = strconv.AppendInt(b, int64(t.Second()), 10)
  434. b = append(b, []byte{0x20}...)
  435. tz, _ := t.Zone()
  436. b = append(b, tz...)
  437. return string(b)
  438. }
  439. // FmtTimeFull returns the full time representation of 't' for 'gd'
  440. func (gd *gd) FmtTimeFull(t time.Time) string {
  441. b := make([]byte, 0, 32)
  442. if t.Hour() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  446. b = append(b, gd.timeSeparator...)
  447. if t.Minute() < 10 {
  448. b = append(b, '0')
  449. }
  450. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  451. b = append(b, gd.timeSeparator...)
  452. if t.Second() < 10 {
  453. b = append(b, '0')
  454. }
  455. b = strconv.AppendInt(b, int64(t.Second()), 10)
  456. b = append(b, []byte{0x20}...)
  457. tz, _ := t.Zone()
  458. if btz, ok := gd.timezones[tz]; ok {
  459. b = append(b, btz...)
  460. } else {
  461. b = append(b, tz...)
  462. }
  463. return string(b)
  464. }