fil.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. package fil
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type fil 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 'fil' locale
  41. func New() locales.Translator {
  42. return &fil{
  43. locale: "fil",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: []locales.PluralRule{2, 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 ", "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", "₱", "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{"", "Ene", "Peb", "Mar", "Abr", "May", "Hun", "Hul", "Ago", "Set", "Okt", "Nob", "Dis"},
  58. monthsNarrow: []string{"", "Ene", "Peb", "Mar", "Abr", "May", "Hun", "Hul", "Ago", "Set", "Okt", "Nob", "Dis"},
  59. monthsWide: []string{"", "Enero", "Pebrero", "Marso", "Abril", "Mayo", "Hunyo", "Hulyo", "Agosto", "Setyembre", "Oktubre", "Nobyembre", "Disyembre"},
  60. daysAbbreviated: []string{"Lin", "Lun", "Mar", "Miy", "Huw", "Biy", "Sab"},
  61. daysNarrow: []string{"Lin", "Lun", "Mar", "Miy", "Huw", "Biy", "Sab"},
  62. daysShort: []string{"Li", "Lu", "Ma", "Mi", "Hu", "Bi", "Sa"},
  63. daysWide: []string{"Linggo", "Lunes", "Martes", "Miyerkules", "Huwebes", "Biyernes", "Sabado"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"am", "pm"},
  66. periodsWide: []string{"AM", "PM"},
  67. erasAbbreviated: []string{"BC", "AD"},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"BC", "AD"},
  70. timezones: map[string]string{"WIT": "Oras ng Silangang Indonesiya", "VET": "Oras sa Venezuela", "COST": "Oras sa Tag-init ng Colombia", "WARST": "Oras sa Tag-init ng Kanlurang Argentina", "MYT": "Oras ng Malaysia", "NZDT": "Daylight Time sa New Zealand", "CLT": "Standard na Oras sa Chile", "AST": "Standard na Oras sa Atlantiko", "SGT": "Standard na Oras sa Singapore", "ACWST": "Standard Time ng Gitnang Kanluran ng Australya", "IST": "Standard na Oras sa Bhutan", "ACST": "Standard Time ng Gitnang Australya", "LHDT": "Daylight Time sa Lorde Howe", "UYST": "Oras sa Tag-init ng Uruguay", "CHADT": "Daylight Time sa Chatham", "HKT": "Standard na Oras sa Hong Kong", "BT": "Oras sa Bhutan", "TMST": "Oras sa Tag-init ng Turkmenistan", "∅∅∅": "Oras sa Tag-init ng Amazon", "AWDT": "Daylight Time sa Kanlurang Australya", "CST": "Sentral na Standard na Oras", "CAT": "Oras sa Gitnang Africa", "ACDT": "Daylight Time ng Gitnang Australya", "GYT": "Oras sa Guyana", "NZST": "Standard na Oras sa New Zealand", "HADT": "Oras sa Tag-init ng Hawaii-Aleutian", "WAT": "Standard na Oras sa Kanlurang Africa", "OESZ": "Oras sa Tag-init ng Silangang Europe", "WESZ": "Oras sa Tag-init ng Kanlurang Europe", "SAST": "Oras sa Timog Africa", "HAT": "Daylight Time sa Newfoundland", "JST": "Standard na Oras sa Japan", "MEZ": "Standard na Oras sa Gitnang Europe", "GFT": "Oras sa French Guiana", "EAT": "Oras sa Silangang Africa", "AEST": "Standard Time ng Silangang Australya", "HAST": "Standard na Oras sa Hawaii-Aleutian", "WAST": "Oras sa Tag-init ng Kanlurang Africa", "MESZ": "Oras sa Tag-init ng Gitnang Europe", "CLST": "Oras sa Tag-init ng Chile", "HKST": "Oras sa Tag-init ng Hong Kong", "WITA": "Oras ng Gitnang Indonesiya", "OEZ": "Standard na Oras sa Silangang Europe", "JDT": "Daylight Time sa Japan", "SRT": "Oras sa Suriname", "CDT": "Sentral na Daylight Time", "AKDT": "Daylight Time sa Alaska", "PST": "Standard na Oras sa Pasipiko", "CHAST": "Standard na Oras sa Chatham", "ACWDT": "Daylight Time ng Gitnang Kanluran ng Australya", "COT": "Standard na Oras sa Colombia", "EST": "Eastern na Standard na Oras", "EDT": "Eastern Daylight Time", "ADT": "Daylight Time sa Atlantiko", "WIB": "Oras ng Kanlurang Indonesiya", "TMT": "Standard na Oras sa Turkmenistan", "ARST": "Oras sa Tag-init ng Argentina", "AKST": "Standard na Oras sa Alaska", "UYT": "Standard na Oras sa Uruguay", "WART": "Standard na Oras sa Kanlurang Argentina", "AEDT": "Daylight Time ng Silangang Australya", "ChST": "Standard na Oras sa Chamorro", "GMT": "Greenwich Mean Time", "AWST": "Standard Time ng Kanlurang Australya", "BOT": "Oras sa Bolivia", "WEZ": "Standard na Oras sa Kanlurang Europe", "HNT": "Standard na Oras sa Newfoundland", "MST": "MST", "PDT": "Daylight Time sa Pasipiko", "LHST": "Standard na Oras sa Lord Howe", "ECT": "Oras sa Ecuador", "MDT": "MDT", "ART": "Standard na Oras sa Argentina"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (fil *fil) Locale() string {
  75. return fil.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'fil'
  78. func (fil *fil) PluralsCardinal() []locales.PluralRule {
  79. return fil.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'fil'
  82. func (fil *fil) PluralsOrdinal() []locales.PluralRule {
  83. return fil.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'fil'
  86. func (fil *fil) PluralsRange() []locales.PluralRule {
  87. return fil.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'fil'
  90. func (fil *fil) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. f := locales.F(n, v)
  94. iMod10 := i % 10
  95. fMod10 := f % 10
  96. if (v == 0 && (i == 1 || i == 2 || i == 3)) || (v == 0 && (iMod10 != 4 && iMod10 != 6 && iMod10 != 9)) || (v != 0 && (fMod10 != 4 && fMod10 != 6 && fMod10 != 9)) {
  97. return locales.PluralRuleOne
  98. }
  99. return locales.PluralRuleOther
  100. }
  101. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'fil'
  102. func (fil *fil) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  103. n := math.Abs(num)
  104. if n == 1 {
  105. return locales.PluralRuleOne
  106. }
  107. return locales.PluralRuleOther
  108. }
  109. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'fil'
  110. func (fil *fil) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  111. start := fil.CardinalPluralRule(num1, v1)
  112. end := fil.CardinalPluralRule(num2, v2)
  113. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  114. return locales.PluralRuleOne
  115. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  116. return locales.PluralRuleOther
  117. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  118. return locales.PluralRuleOne
  119. }
  120. return locales.PluralRuleOther
  121. }
  122. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  123. func (fil *fil) MonthAbbreviated(month time.Month) string {
  124. return fil.monthsAbbreviated[month]
  125. }
  126. // MonthsAbbreviated returns the locales abbreviated months
  127. func (fil *fil) MonthsAbbreviated() []string {
  128. return fil.monthsAbbreviated[1:]
  129. }
  130. // MonthNarrow returns the locales narrow month given the 'month' provided
  131. func (fil *fil) MonthNarrow(month time.Month) string {
  132. return fil.monthsNarrow[month]
  133. }
  134. // MonthsNarrow returns the locales narrow months
  135. func (fil *fil) MonthsNarrow() []string {
  136. return fil.monthsNarrow[1:]
  137. }
  138. // MonthWide returns the locales wide month given the 'month' provided
  139. func (fil *fil) MonthWide(month time.Month) string {
  140. return fil.monthsWide[month]
  141. }
  142. // MonthsWide returns the locales wide months
  143. func (fil *fil) MonthsWide() []string {
  144. return fil.monthsWide[1:]
  145. }
  146. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  147. func (fil *fil) WeekdayAbbreviated(weekday time.Weekday) string {
  148. return fil.daysAbbreviated[weekday]
  149. }
  150. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  151. func (fil *fil) WeekdaysAbbreviated() []string {
  152. return fil.daysAbbreviated
  153. }
  154. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  155. func (fil *fil) WeekdayNarrow(weekday time.Weekday) string {
  156. return fil.daysNarrow[weekday]
  157. }
  158. // WeekdaysNarrow returns the locales narrow weekdays
  159. func (fil *fil) WeekdaysNarrow() []string {
  160. return fil.daysNarrow
  161. }
  162. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  163. func (fil *fil) WeekdayShort(weekday time.Weekday) string {
  164. return fil.daysShort[weekday]
  165. }
  166. // WeekdaysShort returns the locales short weekdays
  167. func (fil *fil) WeekdaysShort() []string {
  168. return fil.daysShort
  169. }
  170. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  171. func (fil *fil) WeekdayWide(weekday time.Weekday) string {
  172. return fil.daysWide[weekday]
  173. }
  174. // WeekdaysWide returns the locales wide weekdays
  175. func (fil *fil) WeekdaysWide() []string {
  176. return fil.daysWide
  177. }
  178. // FmtNumber returns 'num' with digits/precision of 'v' for 'fil' and handles both Whole and Real numbers based on 'v'
  179. func (fil *fil) FmtNumber(num float64, v uint64) string {
  180. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  181. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  182. count := 0
  183. inWhole := v == 0
  184. b := make([]byte, 0, l)
  185. for i := len(s) - 1; i >= 0; i-- {
  186. if s[i] == '.' {
  187. b = append(b, fil.decimal[0])
  188. inWhole = true
  189. continue
  190. }
  191. if inWhole {
  192. if count == 3 {
  193. b = append(b, fil.group[0])
  194. count = 1
  195. } else {
  196. count++
  197. }
  198. }
  199. b = append(b, s[i])
  200. }
  201. if num < 0 {
  202. b = append(b, fil.minus[0])
  203. }
  204. // reverse
  205. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  206. b[i], b[j] = b[j], b[i]
  207. }
  208. return string(b)
  209. }
  210. // FmtPercent returns 'num' with digits/precision of 'v' for 'fil' and handles both Whole and Real numbers based on 'v'
  211. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  212. func (fil *fil) FmtPercent(num float64, v uint64) string {
  213. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  214. l := len(s) + 3
  215. b := make([]byte, 0, l)
  216. for i := len(s) - 1; i >= 0; i-- {
  217. if s[i] == '.' {
  218. b = append(b, fil.decimal[0])
  219. continue
  220. }
  221. b = append(b, s[i])
  222. }
  223. if num < 0 {
  224. b = append(b, fil.minus[0])
  225. }
  226. // reverse
  227. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  228. b[i], b[j] = b[j], b[i]
  229. }
  230. b = append(b, fil.percent...)
  231. return string(b)
  232. }
  233. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'fil'
  234. func (fil *fil) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  235. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  236. symbol := fil.currencies[currency]
  237. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  238. count := 0
  239. inWhole := v == 0
  240. b := make([]byte, 0, l)
  241. for i := len(s) - 1; i >= 0; i-- {
  242. if s[i] == '.' {
  243. b = append(b, fil.decimal[0])
  244. inWhole = true
  245. continue
  246. }
  247. if inWhole {
  248. if count == 3 {
  249. b = append(b, fil.group[0])
  250. count = 1
  251. } else {
  252. count++
  253. }
  254. }
  255. b = append(b, s[i])
  256. }
  257. for j := len(symbol) - 1; j >= 0; j-- {
  258. b = append(b, symbol[j])
  259. }
  260. if num < 0 {
  261. b = append(b, fil.minus[0])
  262. }
  263. // reverse
  264. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  265. b[i], b[j] = b[j], b[i]
  266. }
  267. if int(v) < 2 {
  268. if v == 0 {
  269. b = append(b, fil.decimal...)
  270. }
  271. for i := 0; i < 2-int(v); i++ {
  272. b = append(b, '0')
  273. }
  274. }
  275. return string(b)
  276. }
  277. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'fil'
  278. // in accounting notation.
  279. func (fil *fil) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  280. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  281. symbol := fil.currencies[currency]
  282. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  283. count := 0
  284. inWhole := v == 0
  285. b := make([]byte, 0, l)
  286. for i := len(s) - 1; i >= 0; i-- {
  287. if s[i] == '.' {
  288. b = append(b, fil.decimal[0])
  289. inWhole = true
  290. continue
  291. }
  292. if inWhole {
  293. if count == 3 {
  294. b = append(b, fil.group[0])
  295. count = 1
  296. } else {
  297. count++
  298. }
  299. }
  300. b = append(b, s[i])
  301. }
  302. if num < 0 {
  303. for j := len(symbol) - 1; j >= 0; j-- {
  304. b = append(b, symbol[j])
  305. }
  306. b = append(b, fil.currencyNegativePrefix[0])
  307. } else {
  308. for j := len(symbol) - 1; j >= 0; j-- {
  309. b = append(b, symbol[j])
  310. }
  311. }
  312. // reverse
  313. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  314. b[i], b[j] = b[j], b[i]
  315. }
  316. if int(v) < 2 {
  317. if v == 0 {
  318. b = append(b, fil.decimal...)
  319. }
  320. for i := 0; i < 2-int(v); i++ {
  321. b = append(b, '0')
  322. }
  323. }
  324. if num < 0 {
  325. b = append(b, fil.currencyNegativeSuffix...)
  326. }
  327. return string(b)
  328. }
  329. // FmtDateShort returns the short date representation of 't' for 'fil'
  330. func (fil *fil) FmtDateShort(t time.Time) string {
  331. b := make([]byte, 0, 32)
  332. b = strconv.AppendInt(b, int64(t.Month()), 10)
  333. b = append(b, []byte{0x2f}...)
  334. b = strconv.AppendInt(b, int64(t.Day()), 10)
  335. b = append(b, []byte{0x2f}...)
  336. if t.Year() > 9 {
  337. b = append(b, strconv.Itoa(t.Year())[2:]...)
  338. } else {
  339. b = append(b, strconv.Itoa(t.Year())[1:]...)
  340. }
  341. return string(b)
  342. }
  343. // FmtDateMedium returns the medium date representation of 't' for 'fil'
  344. func (fil *fil) FmtDateMedium(t time.Time) string {
  345. b := make([]byte, 0, 32)
  346. b = append(b, fil.monthsAbbreviated[t.Month()]...)
  347. b = append(b, []byte{0x20}...)
  348. b = strconv.AppendInt(b, int64(t.Day()), 10)
  349. b = append(b, []byte{0x2c, 0x20}...)
  350. b = strconv.AppendInt(b, int64(t.Year()), 10)
  351. return string(b)
  352. }
  353. // FmtDateLong returns the long date representation of 't' for 'fil'
  354. func (fil *fil) FmtDateLong(t time.Time) string {
  355. b := make([]byte, 0, 32)
  356. b = append(b, fil.monthsWide[t.Month()]...)
  357. b = append(b, []byte{0x20}...)
  358. b = strconv.AppendInt(b, int64(t.Day()), 10)
  359. b = append(b, []byte{0x2c, 0x20}...)
  360. b = strconv.AppendInt(b, int64(t.Year()), 10)
  361. return string(b)
  362. }
  363. // FmtDateFull returns the full date representation of 't' for 'fil'
  364. func (fil *fil) FmtDateFull(t time.Time) string {
  365. b := make([]byte, 0, 32)
  366. b = append(b, fil.daysWide[t.Weekday()]...)
  367. b = append(b, []byte{0x2c, 0x20}...)
  368. b = append(b, fil.monthsWide[t.Month()]...)
  369. b = append(b, []byte{0x20}...)
  370. b = strconv.AppendInt(b, int64(t.Day()), 10)
  371. b = append(b, []byte{0x2c, 0x20}...)
  372. b = strconv.AppendInt(b, int64(t.Year()), 10)
  373. return string(b)
  374. }
  375. // FmtTimeShort returns the short time representation of 't' for 'fil'
  376. func (fil *fil) FmtTimeShort(t time.Time) string {
  377. b := make([]byte, 0, 32)
  378. h := t.Hour()
  379. if h > 12 {
  380. h -= 12
  381. }
  382. b = strconv.AppendInt(b, int64(h), 10)
  383. b = append(b, fil.timeSeparator...)
  384. if t.Minute() < 10 {
  385. b = append(b, '0')
  386. }
  387. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  388. b = append(b, []byte{0x20}...)
  389. if t.Hour() < 12 {
  390. b = append(b, fil.periodsAbbreviated[0]...)
  391. } else {
  392. b = append(b, fil.periodsAbbreviated[1]...)
  393. }
  394. return string(b)
  395. }
  396. // FmtTimeMedium returns the medium time representation of 't' for 'fil'
  397. func (fil *fil) FmtTimeMedium(t time.Time) string {
  398. b := make([]byte, 0, 32)
  399. h := t.Hour()
  400. if h > 12 {
  401. h -= 12
  402. }
  403. b = strconv.AppendInt(b, int64(h), 10)
  404. b = append(b, fil.timeSeparator...)
  405. if t.Minute() < 10 {
  406. b = append(b, '0')
  407. }
  408. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  409. b = append(b, fil.timeSeparator...)
  410. if t.Second() < 10 {
  411. b = append(b, '0')
  412. }
  413. b = strconv.AppendInt(b, int64(t.Second()), 10)
  414. b = append(b, []byte{0x20}...)
  415. if t.Hour() < 12 {
  416. b = append(b, fil.periodsAbbreviated[0]...)
  417. } else {
  418. b = append(b, fil.periodsAbbreviated[1]...)
  419. }
  420. return string(b)
  421. }
  422. // FmtTimeLong returns the long time representation of 't' for 'fil'
  423. func (fil *fil) FmtTimeLong(t time.Time) string {
  424. b := make([]byte, 0, 32)
  425. h := t.Hour()
  426. if h > 12 {
  427. h -= 12
  428. }
  429. b = strconv.AppendInt(b, int64(h), 10)
  430. b = append(b, fil.timeSeparator...)
  431. if t.Minute() < 10 {
  432. b = append(b, '0')
  433. }
  434. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  435. b = append(b, fil.timeSeparator...)
  436. if t.Second() < 10 {
  437. b = append(b, '0')
  438. }
  439. b = strconv.AppendInt(b, int64(t.Second()), 10)
  440. b = append(b, []byte{0x20}...)
  441. if t.Hour() < 12 {
  442. b = append(b, fil.periodsAbbreviated[0]...)
  443. } else {
  444. b = append(b, fil.periodsAbbreviated[1]...)
  445. }
  446. b = append(b, []byte{0x20}...)
  447. tz, _ := t.Zone()
  448. b = append(b, tz...)
  449. return string(b)
  450. }
  451. // FmtTimeFull returns the full time representation of 't' for 'fil'
  452. func (fil *fil) FmtTimeFull(t time.Time) string {
  453. b := make([]byte, 0, 32)
  454. h := t.Hour()
  455. if h > 12 {
  456. h -= 12
  457. }
  458. b = strconv.AppendInt(b, int64(h), 10)
  459. b = append(b, fil.timeSeparator...)
  460. if t.Minute() < 10 {
  461. b = append(b, '0')
  462. }
  463. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  464. b = append(b, fil.timeSeparator...)
  465. if t.Second() < 10 {
  466. b = append(b, '0')
  467. }
  468. b = strconv.AppendInt(b, int64(t.Second()), 10)
  469. b = append(b, []byte{0x20}...)
  470. if t.Hour() < 12 {
  471. b = append(b, fil.periodsAbbreviated[0]...)
  472. } else {
  473. b = append(b, fil.periodsAbbreviated[1]...)
  474. }
  475. b = append(b, []byte{0x20}...)
  476. tz, _ := t.Zone()
  477. if btz, ok := fil.timezones[tz]; ok {
  478. b = append(b, btz...)
  479. } else {
  480. b = append(b, tz...)
  481. }
  482. return string(b)
  483. }