fa.go 21 KB

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