pt.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. package pt
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type pt 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. currencyPositivePrefix string
  23. currencyNegativePrefix 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 'pt' locale
  41. func New() locales.Translator {
  42. return &pt{
  43. locale: "pt",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: []locales.PluralRule{6},
  46. pluralsRange: []locales.PluralRule{2, 6},
  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", "AU$", "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", "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", "Esc.", "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", "US$", "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. currencyPositivePrefix: " ",
  56. currencyNegativePrefix: " ",
  57. monthsAbbreviated: []string{"", "jan", "fev", "mar", "abr", "mai", "jun", "jul", "ago", "set", "out", "nov", "dez"},
  58. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  59. monthsWide: []string{"", "janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro"},
  60. daysAbbreviated: []string{"dom", "seg", "ter", "qua", "qui", "sex", "sáb"},
  61. daysNarrow: []string{"D", "S", "T", "Q", "Q", "S", "S"},
  62. daysShort: []string{"dom", "seg", "ter", "qua", "qui", "sex", "sáb"},
  63. daysWide: []string{"domingo", "segunda-feira", "terça-feira", "quarta-feira", "quinta-feira", "sexta-feira", "sábado"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"AM", "PM"},
  66. periodsWide: []string{"AM", "PM"},
  67. erasAbbreviated: []string{"a.C.", "d.C."},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"antes de Cristo", "depois de Cristo"},
  70. timezones: map[string]string{"ChST": "Horário de Chamorro", "CHADT": "Horário de Verão de Chatham", "AKST": "Horário Padrão do Alasca", "OEZ": "Horário Padrão da Europa Oriental", "HNNOMX": "Horário Padrão do Noroeste do México", "BOT": "Horário da Bolívia", "ACWDT": "Horário de Verão da Austrália Centro-Ocidental", "WART": "Horário Padrão da Argentina Ocidental", "MEZ": "Horário Padrão da Europa Central", "HKT": "Horário Padrão de Hong Kong", "AEDT": "Horário de Verão da Austrália Oriental", "WESZ": "Horário de Verão da Europa Ocidental", "WARST": "Horário de Verão da Argentina Ocidental", "HNCU": "Horário Padrão de Cuba", "WITA": "Horário da Indonésia Central", "SRT": "Horário do Suriname", "GMT": "Horário do Meridiano de Greenwich", "AST": "Horário Padrão do Atlântico", "ADT": "Horário de Verão do Atlântico", "ACST": "Horário Padrão da Austrália Central", "ACDT": "Horário de Verão da Austrália Central", "LHST": "Horário Padrão de Lord Howe", "HEPM": "Horário de Verão de Saint Pierre e Miquelon", "CST": "Horário Padrão Central", "HNPMX": "Horário Padrão do Pacífico Mexicano", "AEST": "Horário Padrão da Austrália Oriental", "HNOG": "Horário Padrão da Groenlândia Ocidental", "HEOG": "Horário de Verão da Groenlândia Ocidental", "TMT": "Horário Padrão do Turcomenistão", "ARST": "Horário de Verão da Argentina", "IST": "Horário Padrão da Índia", "CLST": "Horário de Verão do Chile", "∅∅∅": "Horário de Verão dos Açores", "CDT": "Horário de Verão Central", "PST": "Horário Padrão do Pacífico", "NZST": "Horário Padrão da Nova Zelândia", "MYT": "Horário da Malásia", "VET": "Horário da Venezuela", "MST": "Horário Padrão de Macau", "TMST": "Horário de Verão do Turcomenistão", "UYST": "Horário de Verão do Uruguai", "PDT": "Horário de Verão do Pacífico", "AWST": "Horário Padrão da Austrália Ocidental", "HKST": "Horário de Verão de Hong Kong", "HNT": "Horário Padrão da Terra Nova", "JDT": "Horário de Verão do Japão", "EAT": "Horário da África Oriental", "BT": "Horário do Butão", "GFT": "Horário da Guiana Francesa", "CHAST": "Horário Padrão de Chatham", "HEPMX": "Horário de Verão do Pacífico Mexicano", "EST": "Horário Padrão do Leste", "HEEG": "Horário de Verão da Groelândia Oriental", "MESZ": "Horário de Verão da Europa Central", "HAT": "Horário de Verão da Terra Nova", "MDT": "Horário de Verão de Macau", "HADT": "Horário de Verão do Havaí e Ilhas Aleutas", "COST": "Horário de Verão da Colômbia", "SGT": "Horário Padrão de Cingapura", "EDT": "Horário de Verão do Leste", "HAST": "Horário Padrão do Havaí e Ilhas Aleutas", "ART": "Horário Padrão da Argentina", "WEZ": "Horário Padrão da Europa Ocidental", "WIB": "Horário da Indonésia Ocidental", "JST": "Horário Padrão do Japão", "HENOMX": "Horário de Verão do Noroeste do México", "CAT": "Horário da África Central", "OESZ": "Horário de Verão da Europa Oriental", "HECU": "Horário de Verão de Cuba", "WAST": "Horário de Verão da África Ocidental", "AKDT": "Horário de Verão do Alasca", "LHDT": "Horário de Verão de Lord Howe", "ACWST": "Horário Padrão da Austrália Centro-Ocidental", "HNEG": "Horário Padrão da Groelândia Oriental", "CLT": "Horário Padrão do Chile", "COT": "Horário Padrão da Colômbia", "GYT": "Horário da Guiana", "NZDT": "Horário de Verão da Nova Zelândia", "ECT": "Horário do Equador", "UYT": "Horário Padrão do Uruguai", "AWDT": "Horário de Verão da Austrália Ocidental", "SAST": "Horário da África do Sul", "WAT": "Horário Padrão da África Ocidental", "HNPM": "Horário Padrão de Saint Pierre e Miquelon", "WIT": "Horário da Indonésia Oriental"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (pt *pt) Locale() string {
  75. return pt.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'pt'
  78. func (pt *pt) PluralsCardinal() []locales.PluralRule {
  79. return pt.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'pt'
  82. func (pt *pt) PluralsOrdinal() []locales.PluralRule {
  83. return pt.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'pt'
  86. func (pt *pt) PluralsRange() []locales.PluralRule {
  87. return pt.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'pt'
  90. func (pt *pt) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. if i >= 0 && i <= 1 {
  94. return locales.PluralRuleOne
  95. }
  96. return locales.PluralRuleOther
  97. }
  98. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'pt'
  99. func (pt *pt) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  100. return locales.PluralRuleOther
  101. }
  102. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'pt'
  103. func (pt *pt) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  104. start := pt.CardinalPluralRule(num1, v1)
  105. end := pt.CardinalPluralRule(num2, v2)
  106. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  107. return locales.PluralRuleOne
  108. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  109. return locales.PluralRuleOther
  110. }
  111. return locales.PluralRuleOther
  112. }
  113. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  114. func (pt *pt) MonthAbbreviated(month time.Month) string {
  115. return pt.monthsAbbreviated[month]
  116. }
  117. // MonthsAbbreviated returns the locales abbreviated months
  118. func (pt *pt) MonthsAbbreviated() []string {
  119. return pt.monthsAbbreviated[1:]
  120. }
  121. // MonthNarrow returns the locales narrow month given the 'month' provided
  122. func (pt *pt) MonthNarrow(month time.Month) string {
  123. return pt.monthsNarrow[month]
  124. }
  125. // MonthsNarrow returns the locales narrow months
  126. func (pt *pt) MonthsNarrow() []string {
  127. return pt.monthsNarrow[1:]
  128. }
  129. // MonthWide returns the locales wide month given the 'month' provided
  130. func (pt *pt) MonthWide(month time.Month) string {
  131. return pt.monthsWide[month]
  132. }
  133. // MonthsWide returns the locales wide months
  134. func (pt *pt) MonthsWide() []string {
  135. return pt.monthsWide[1:]
  136. }
  137. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  138. func (pt *pt) WeekdayAbbreviated(weekday time.Weekday) string {
  139. return pt.daysAbbreviated[weekday]
  140. }
  141. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  142. func (pt *pt) WeekdaysAbbreviated() []string {
  143. return pt.daysAbbreviated
  144. }
  145. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  146. func (pt *pt) WeekdayNarrow(weekday time.Weekday) string {
  147. return pt.daysNarrow[weekday]
  148. }
  149. // WeekdaysNarrow returns the locales narrow weekdays
  150. func (pt *pt) WeekdaysNarrow() []string {
  151. return pt.daysNarrow
  152. }
  153. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  154. func (pt *pt) WeekdayShort(weekday time.Weekday) string {
  155. return pt.daysShort[weekday]
  156. }
  157. // WeekdaysShort returns the locales short weekdays
  158. func (pt *pt) WeekdaysShort() []string {
  159. return pt.daysShort
  160. }
  161. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  162. func (pt *pt) WeekdayWide(weekday time.Weekday) string {
  163. return pt.daysWide[weekday]
  164. }
  165. // WeekdaysWide returns the locales wide weekdays
  166. func (pt *pt) WeekdaysWide() []string {
  167. return pt.daysWide
  168. }
  169. // Decimal returns the decimal point of number
  170. func (pt *pt) Decimal() string {
  171. return pt.decimal
  172. }
  173. // Group returns the group of number
  174. func (pt *pt) Group() string {
  175. return pt.group
  176. }
  177. // Group returns the minus sign of number
  178. func (pt *pt) Minus() string {
  179. return pt.minus
  180. }
  181. // FmtNumber returns 'num' with digits/precision of 'v' for 'pt' and handles both Whole and Real numbers based on 'v'
  182. func (pt *pt) FmtNumber(num float64, v uint64) string {
  183. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  184. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  185. count := 0
  186. inWhole := v == 0
  187. b := make([]byte, 0, l)
  188. for i := len(s) - 1; i >= 0; i-- {
  189. if s[i] == '.' {
  190. b = append(b, pt.decimal[0])
  191. inWhole = true
  192. continue
  193. }
  194. if inWhole {
  195. if count == 3 {
  196. b = append(b, pt.group[0])
  197. count = 1
  198. } else {
  199. count++
  200. }
  201. }
  202. b = append(b, s[i])
  203. }
  204. if num < 0 {
  205. b = append(b, pt.minus[0])
  206. }
  207. // reverse
  208. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  209. b[i], b[j] = b[j], b[i]
  210. }
  211. return string(b)
  212. }
  213. // FmtPercent returns 'num' with digits/precision of 'v' for 'pt' and handles both Whole and Real numbers based on 'v'
  214. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  215. func (pt *pt) FmtPercent(num float64, v uint64) string {
  216. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  217. l := len(s) + 3
  218. b := make([]byte, 0, l)
  219. for i := len(s) - 1; i >= 0; i-- {
  220. if s[i] == '.' {
  221. b = append(b, pt.decimal[0])
  222. continue
  223. }
  224. b = append(b, s[i])
  225. }
  226. if num < 0 {
  227. b = append(b, pt.minus[0])
  228. }
  229. // reverse
  230. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  231. b[i], b[j] = b[j], b[i]
  232. }
  233. b = append(b, pt.percent...)
  234. return string(b)
  235. }
  236. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'pt'
  237. func (pt *pt) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  238. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  239. symbol := pt.currencies[currency]
  240. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  241. count := 0
  242. inWhole := v == 0
  243. b := make([]byte, 0, l)
  244. for i := len(s) - 1; i >= 0; i-- {
  245. if s[i] == '.' {
  246. b = append(b, pt.decimal[0])
  247. inWhole = true
  248. continue
  249. }
  250. if inWhole {
  251. if count == 3 {
  252. b = append(b, pt.group[0])
  253. count = 1
  254. } else {
  255. count++
  256. }
  257. }
  258. b = append(b, s[i])
  259. }
  260. for j := len(symbol) - 1; j >= 0; j-- {
  261. b = append(b, symbol[j])
  262. }
  263. for j := len(pt.currencyPositivePrefix) - 1; j >= 0; j-- {
  264. b = append(b, pt.currencyPositivePrefix[j])
  265. }
  266. if num < 0 {
  267. b = append(b, pt.minus[0])
  268. }
  269. // reverse
  270. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  271. b[i], b[j] = b[j], b[i]
  272. }
  273. if int(v) < 2 {
  274. if v == 0 {
  275. b = append(b, pt.decimal...)
  276. }
  277. for i := 0; i < 2-int(v); i++ {
  278. b = append(b, '0')
  279. }
  280. }
  281. return string(b)
  282. }
  283. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'pt'
  284. // in accounting notation.
  285. func (pt *pt) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  286. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  287. symbol := pt.currencies[currency]
  288. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  289. count := 0
  290. inWhole := v == 0
  291. b := make([]byte, 0, l)
  292. for i := len(s) - 1; i >= 0; i-- {
  293. if s[i] == '.' {
  294. b = append(b, pt.decimal[0])
  295. inWhole = true
  296. continue
  297. }
  298. if inWhole {
  299. if count == 3 {
  300. b = append(b, pt.group[0])
  301. count = 1
  302. } else {
  303. count++
  304. }
  305. }
  306. b = append(b, s[i])
  307. }
  308. if num < 0 {
  309. for j := len(symbol) - 1; j >= 0; j-- {
  310. b = append(b, symbol[j])
  311. }
  312. for j := len(pt.currencyNegativePrefix) - 1; j >= 0; j-- {
  313. b = append(b, pt.currencyNegativePrefix[j])
  314. }
  315. b = append(b, pt.minus[0])
  316. } else {
  317. for j := len(symbol) - 1; j >= 0; j-- {
  318. b = append(b, symbol[j])
  319. }
  320. for j := len(pt.currencyPositivePrefix) - 1; j >= 0; j-- {
  321. b = append(b, pt.currencyPositivePrefix[j])
  322. }
  323. }
  324. // reverse
  325. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  326. b[i], b[j] = b[j], b[i]
  327. }
  328. if int(v) < 2 {
  329. if v == 0 {
  330. b = append(b, pt.decimal...)
  331. }
  332. for i := 0; i < 2-int(v); i++ {
  333. b = append(b, '0')
  334. }
  335. }
  336. return string(b)
  337. }
  338. // FmtDateShort returns the short date representation of 't' for 'pt'
  339. func (pt *pt) FmtDateShort(t time.Time) string {
  340. b := make([]byte, 0, 32)
  341. if t.Day() < 10 {
  342. b = append(b, '0')
  343. }
  344. b = strconv.AppendInt(b, int64(t.Day()), 10)
  345. b = append(b, []byte{0x2f}...)
  346. if t.Month() < 10 {
  347. b = append(b, '0')
  348. }
  349. b = strconv.AppendInt(b, int64(t.Month()), 10)
  350. b = append(b, []byte{0x2f}...)
  351. if t.Year() > 0 {
  352. b = strconv.AppendInt(b, int64(t.Year()), 10)
  353. } else {
  354. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  355. }
  356. return string(b)
  357. }
  358. // FmtDateMedium returns the medium date representation of 't' for 'pt'
  359. func (pt *pt) FmtDateMedium(t time.Time) string {
  360. b := make([]byte, 0, 32)
  361. b = strconv.AppendInt(b, int64(t.Day()), 10)
  362. b = append(b, []byte{0x20, 0x64, 0x65}...)
  363. b = append(b, []byte{0x20}...)
  364. b = append(b, pt.monthsAbbreviated[t.Month()]...)
  365. b = append(b, []byte{0x20, 0x64, 0x65}...)
  366. b = append(b, []byte{0x20}...)
  367. if t.Year() > 0 {
  368. b = strconv.AppendInt(b, int64(t.Year()), 10)
  369. } else {
  370. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  371. }
  372. return string(b)
  373. }
  374. // FmtDateLong returns the long date representation of 't' for 'pt'
  375. func (pt *pt) FmtDateLong(t time.Time) string {
  376. b := make([]byte, 0, 32)
  377. b = strconv.AppendInt(b, int64(t.Day()), 10)
  378. b = append(b, []byte{0x20, 0x64, 0x65}...)
  379. b = append(b, []byte{0x20}...)
  380. b = append(b, pt.monthsWide[t.Month()]...)
  381. b = append(b, []byte{0x20, 0x64, 0x65}...)
  382. b = append(b, []byte{0x20}...)
  383. if t.Year() > 0 {
  384. b = strconv.AppendInt(b, int64(t.Year()), 10)
  385. } else {
  386. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  387. }
  388. return string(b)
  389. }
  390. // FmtDateFull returns the full date representation of 't' for 'pt'
  391. func (pt *pt) FmtDateFull(t time.Time) string {
  392. b := make([]byte, 0, 32)
  393. b = append(b, pt.daysWide[t.Weekday()]...)
  394. b = append(b, []byte{0x2c, 0x20}...)
  395. b = strconv.AppendInt(b, int64(t.Day()), 10)
  396. b = append(b, []byte{0x20, 0x64, 0x65}...)
  397. b = append(b, []byte{0x20}...)
  398. b = append(b, pt.monthsWide[t.Month()]...)
  399. b = append(b, []byte{0x20, 0x64, 0x65}...)
  400. b = append(b, []byte{0x20}...)
  401. if t.Year() > 0 {
  402. b = strconv.AppendInt(b, int64(t.Year()), 10)
  403. } else {
  404. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  405. }
  406. return string(b)
  407. }
  408. // FmtTimeShort returns the short time representation of 't' for 'pt'
  409. func (pt *pt) FmtTimeShort(t time.Time) string {
  410. b := make([]byte, 0, 32)
  411. if t.Hour() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  415. b = append(b, pt.timeSeparator...)
  416. if t.Minute() < 10 {
  417. b = append(b, '0')
  418. }
  419. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  420. return string(b)
  421. }
  422. // FmtTimeMedium returns the medium time representation of 't' for 'pt'
  423. func (pt *pt) FmtTimeMedium(t time.Time) string {
  424. b := make([]byte, 0, 32)
  425. if t.Hour() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  429. b = append(b, pt.timeSeparator...)
  430. if t.Minute() < 10 {
  431. b = append(b, '0')
  432. }
  433. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  434. b = append(b, pt.timeSeparator...)
  435. if t.Second() < 10 {
  436. b = append(b, '0')
  437. }
  438. b = strconv.AppendInt(b, int64(t.Second()), 10)
  439. return string(b)
  440. }
  441. // FmtTimeLong returns the long time representation of 't' for 'pt'
  442. func (pt *pt) FmtTimeLong(t time.Time) string {
  443. b := make([]byte, 0, 32)
  444. if t.Hour() < 10 {
  445. b = append(b, '0')
  446. }
  447. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  448. b = append(b, pt.timeSeparator...)
  449. if t.Minute() < 10 {
  450. b = append(b, '0')
  451. }
  452. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  453. b = append(b, pt.timeSeparator...)
  454. if t.Second() < 10 {
  455. b = append(b, '0')
  456. }
  457. b = strconv.AppendInt(b, int64(t.Second()), 10)
  458. b = append(b, []byte{0x20}...)
  459. tz, _ := t.Zone()
  460. b = append(b, tz...)
  461. return string(b)
  462. }
  463. // FmtTimeFull returns the full time representation of 't' for 'pt'
  464. func (pt *pt) FmtTimeFull(t time.Time) string {
  465. b := make([]byte, 0, 32)
  466. if t.Hour() < 10 {
  467. b = append(b, '0')
  468. }
  469. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  470. b = append(b, pt.timeSeparator...)
  471. if t.Minute() < 10 {
  472. b = append(b, '0')
  473. }
  474. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  475. b = append(b, pt.timeSeparator...)
  476. if t.Second() < 10 {
  477. b = append(b, '0')
  478. }
  479. b = strconv.AppendInt(b, int64(t.Second()), 10)
  480. b = append(b, []byte{0x20}...)
  481. tz, _ := t.Zone()
  482. if btz, ok := pt.timezones[tz]; ok {
  483. b = append(b, btz...)
  484. } else {
  485. b = append(b, tz...)
  486. }
  487. return string(b)
  488. }