fy.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. package fy
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type fy 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. currencyNegativeSuffix string
  25. monthsAbbreviated []string
  26. monthsNarrow []string
  27. monthsWide []string
  28. daysAbbreviated []string
  29. daysNarrow []string
  30. daysShort []string
  31. daysWide []string
  32. periodsAbbreviated []string
  33. periodsNarrow []string
  34. periodsShort []string
  35. periodsWide []string
  36. erasAbbreviated []string
  37. erasNarrow []string
  38. erasWide []string
  39. timezones map[string]string
  40. }
  41. // New returns a new instance of translator for the 'fy' locale
  42. func New() locales.Translator {
  43. return &fy{
  44. locale: "fy",
  45. pluralsCardinal: []locales.PluralRule{2, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: nil,
  48. decimal: ",",
  49. group: ".",
  50. minus: "-",
  51. percent: "%",
  52. perMille: "‰",
  53. timeSeparator: ":",
  54. inifinity: "∞",
  55. 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 ", "BYR ", "BZD ", "C$", "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 ", "FJ$", "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 ", "SI$", "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 ", "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 ", "XPF", "XPT ", "XRE", "XSU ", "XTS", "XUA", "XXX", "YDD ", "YER ", "YUD ", "YUM ", "YUN ", "YUR ", "ZAL ", "ZAR ", "ZMK ", "ZMW ", "ZRN ", "ZRZ ", "ZWD ", "ZWL ", "ZWR "},
  56. currencyPositivePrefix: " ",
  57. currencyNegativePrefix: "( ",
  58. currencyNegativeSuffix: ")",
  59. monthsAbbreviated: []string{"", "jan.", "feb.", "mrt.", "apr.", "mai.", "jun.", "jul.", "aug.", "sep.", "okt.", "nov.", "des."},
  60. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  61. monthsWide: []string{"", "jannewaris", "febrewaris", "maart", "april", "maaie", "juny", "july", "augustus", "septimber", "oktober", "novimber", "desimber"},
  62. daysAbbreviated: []string{"si", "mo", "ti", "wo", "to", "fr", "so"},
  63. daysNarrow: []string{"Z", "M", "D", "W", "D", "V", "Z"},
  64. daysShort: []string{"si", "mo", "ti", "wo", "to", "fr", "so"},
  65. daysWide: []string{"snein", "moandei", "tiisdei", "woansdei", "tongersdei", "freed", "sneon"},
  66. periodsAbbreviated: []string{"AM", "PM"},
  67. periodsNarrow: []string{"AM", "PM"},
  68. periodsWide: []string{"AM", "PM"},
  69. erasAbbreviated: []string{"f.Kr.", "n.Kr."},
  70. erasNarrow: []string{"f.K.", "n.K."},
  71. erasWide: []string{"Foar Kristus", "nei Kristus"},
  72. timezones: map[string]string{"ARST": "Argentynske simmertiid", "NZDT": "Nij-Seelânske simmertiid", "LHDT": "Lord Howe-eilânske simmertiid", "GYT": "Guyaanske tiid", "AKST": "Alaska-standerttiid", "AST": "Atlantic-standerttiid", "HNT": "Newfoundlânske-standerttiid", "IST": "Yndiaaske tiid", "AWST": "West-Australyske standerttiid", "ADT": "Atlantic-simmertiid", "HAT": "Newfoundlânske-simmertiid", "AEST": "East-Australyske standerttiid", "JDT": "Japanske simmertiid", "PDT": "Pasifik-simmertiid", "COT": "Kolombiaanske standerttiid", "HAST": "Hawaii-Aleoetyske standerttiid", "ACDT": "Midden-Australyske simmertiid", "AWDT": "West-Australyske simmertiid", "WAST": "West-Afrikaanske simmertiid", "NZST": "Nij-Seelânske standerttiid", "CST": "Central-standerttiid", "HADT": "Hawaii-Aleoetyske simmertiid", "OEZ": "East-Europeeske standerttiid", "SRT": "Surinaamske tiid", "CHAST": "Chatham standerttiid", "MYT": "Maleisyske tiid", "BOT": "Boliviaanske tiid", "UYT": "Uruguayaanske standerttiid", "HKT": "Hongkongse standerttiid", "WART": "West-Argentynske standerttiid", "WIT": "East-Yndonezyske tiid", "TMST": "Turkmeense simmertiid", "UYST": "Uruguayaanske simmertiid", "SGT": "Singaporese standerttiid", "TMT": "Turkmeense standerttiid", "WARST": "West-Argentynske simmertiid", "MST": "Macause standerttiid", "MEZ": "Midden-Europeeske standerttiid", "VET": "Fenezolaanske tiid", "EAT": "East-Afrikaanske tiid", "ACWDT": "Midden-Australyske westelijke simmertiid", "CAT": "Sintraal-Afrikaanske tiid", "SAST": "Sûd-Afrikaanske tiid", "GFT": "Frâns-Guyaanske tiid", "ACST": "Midden-Australyske standerttiid", "ChST": "Chamorro-tiid", "CLST": "Sileenske simmertiid", "∅∅∅": "Brazyljaanske simmertiid", "LHST": "Lord Howe-eilânske standerttiid", "CDT": "Central-simmertiid", "AEDT": "East-Australyske simmertiid", "AKDT": "Alaska-simmertiid", "CHADT": "Chatham simmertiid", "EST": "Eastern-standerttiid", "BT": "Bhutaanske tiid", "WAT": "West-Afrikaanske standerttiid", "GMT": "Greenwich Mean Time", "OESZ": "East-Europeeske simmertiid", "MDT": "Macause simmertiid", "WEZ": "West-Europeeske standerttiid", "WITA": "Sintraal-Yndonezyske tiid", "ART": "Argentynske standerttiid", "CLT": "Sileenske standerttiid", "WESZ": "West-Europeeske simmertiid", "COST": "Kolombiaanske simmertiid", "ECT": "Ecuadoraanske tiid", "EDT": "Eastern-simmertiid", "HKST": "Hongkongse simmertiid", "ACWST": "Midden-Australyske westelijke standerttiid", "WIB": "West-Yndonezyske tiid", "JST": "Japanske standerttiid", "PST": "Pasifik-standerttiid", "MESZ": "Midden-Europeeske simmertiid"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (fy *fy) Locale() string {
  77. return fy.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'fy'
  80. func (fy *fy) PluralsCardinal() []locales.PluralRule {
  81. return fy.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'fy'
  84. func (fy *fy) PluralsOrdinal() []locales.PluralRule {
  85. return fy.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'fy'
  88. func (fy *fy) PluralsRange() []locales.PluralRule {
  89. return fy.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'fy'
  92. func (fy *fy) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. i := int64(n)
  95. if i == 1 && v == 0 {
  96. return locales.PluralRuleOne
  97. }
  98. return locales.PluralRuleOther
  99. }
  100. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'fy'
  101. func (fy *fy) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  102. return locales.PluralRuleOther
  103. }
  104. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'fy'
  105. func (fy *fy) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  106. return locales.PluralRuleUnknown
  107. }
  108. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  109. func (fy *fy) MonthAbbreviated(month time.Month) string {
  110. return fy.monthsAbbreviated[month]
  111. }
  112. // MonthsAbbreviated returns the locales abbreviated months
  113. func (fy *fy) MonthsAbbreviated() []string {
  114. return fy.monthsAbbreviated[1:]
  115. }
  116. // MonthNarrow returns the locales narrow month given the 'month' provided
  117. func (fy *fy) MonthNarrow(month time.Month) string {
  118. return fy.monthsNarrow[month]
  119. }
  120. // MonthsNarrow returns the locales narrow months
  121. func (fy *fy) MonthsNarrow() []string {
  122. return fy.monthsNarrow[1:]
  123. }
  124. // MonthWide returns the locales wide month given the 'month' provided
  125. func (fy *fy) MonthWide(month time.Month) string {
  126. return fy.monthsWide[month]
  127. }
  128. // MonthsWide returns the locales wide months
  129. func (fy *fy) MonthsWide() []string {
  130. return fy.monthsWide[1:]
  131. }
  132. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  133. func (fy *fy) WeekdayAbbreviated(weekday time.Weekday) string {
  134. return fy.daysAbbreviated[weekday]
  135. }
  136. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  137. func (fy *fy) WeekdaysAbbreviated() []string {
  138. return fy.daysAbbreviated
  139. }
  140. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  141. func (fy *fy) WeekdayNarrow(weekday time.Weekday) string {
  142. return fy.daysNarrow[weekday]
  143. }
  144. // WeekdaysNarrow returns the locales narrow weekdays
  145. func (fy *fy) WeekdaysNarrow() []string {
  146. return fy.daysNarrow
  147. }
  148. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  149. func (fy *fy) WeekdayShort(weekday time.Weekday) string {
  150. return fy.daysShort[weekday]
  151. }
  152. // WeekdaysShort returns the locales short weekdays
  153. func (fy *fy) WeekdaysShort() []string {
  154. return fy.daysShort
  155. }
  156. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  157. func (fy *fy) WeekdayWide(weekday time.Weekday) string {
  158. return fy.daysWide[weekday]
  159. }
  160. // WeekdaysWide returns the locales wide weekdays
  161. func (fy *fy) WeekdaysWide() []string {
  162. return fy.daysWide
  163. }
  164. // FmtNumber returns 'num' with digits/precision of 'v' for 'fy' and handles both Whole and Real numbers based on 'v'
  165. func (fy *fy) FmtNumber(num float64, v uint64) string {
  166. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  167. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  168. count := 0
  169. inWhole := v == 0
  170. b := make([]byte, 0, l)
  171. for i := len(s) - 1; i >= 0; i-- {
  172. if s[i] == '.' {
  173. b = append(b, fy.decimal[0])
  174. inWhole = true
  175. continue
  176. }
  177. if inWhole {
  178. if count == 3 {
  179. b = append(b, fy.group[0])
  180. count = 1
  181. } else {
  182. count++
  183. }
  184. }
  185. b = append(b, s[i])
  186. }
  187. if num < 0 {
  188. b = append(b, fy.minus[0])
  189. }
  190. // reverse
  191. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  192. b[i], b[j] = b[j], b[i]
  193. }
  194. return string(b)
  195. }
  196. // FmtPercent returns 'num' with digits/precision of 'v' for 'fy' and handles both Whole and Real numbers based on 'v'
  197. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  198. func (fy *fy) FmtPercent(num float64, v uint64) string {
  199. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  200. l := len(s) + 3
  201. b := make([]byte, 0, l)
  202. for i := len(s) - 1; i >= 0; i-- {
  203. if s[i] == '.' {
  204. b = append(b, fy.decimal[0])
  205. continue
  206. }
  207. b = append(b, s[i])
  208. }
  209. if num < 0 {
  210. b = append(b, fy.minus[0])
  211. }
  212. // reverse
  213. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  214. b[i], b[j] = b[j], b[i]
  215. }
  216. b = append(b, fy.percent...)
  217. return string(b)
  218. }
  219. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'fy'
  220. func (fy *fy) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  221. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  222. symbol := fy.currencies[currency]
  223. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  224. count := 0
  225. inWhole := v == 0
  226. b := make([]byte, 0, l)
  227. for i := len(s) - 1; i >= 0; i-- {
  228. if s[i] == '.' {
  229. b = append(b, fy.decimal[0])
  230. inWhole = true
  231. continue
  232. }
  233. if inWhole {
  234. if count == 3 {
  235. b = append(b, fy.group[0])
  236. count = 1
  237. } else {
  238. count++
  239. }
  240. }
  241. b = append(b, s[i])
  242. }
  243. for j := len(symbol) - 1; j >= 0; j-- {
  244. b = append(b, symbol[j])
  245. }
  246. for j := len(fy.currencyPositivePrefix) - 1; j >= 0; j-- {
  247. b = append(b, fy.currencyPositivePrefix[j])
  248. }
  249. if num < 0 {
  250. b = append(b, fy.minus[0])
  251. }
  252. // reverse
  253. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  254. b[i], b[j] = b[j], b[i]
  255. }
  256. if int(v) < 2 {
  257. if v == 0 {
  258. b = append(b, fy.decimal...)
  259. }
  260. for i := 0; i < 2-int(v); i++ {
  261. b = append(b, '0')
  262. }
  263. }
  264. return string(b)
  265. }
  266. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'fy'
  267. // in accounting notation.
  268. func (fy *fy) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  269. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  270. symbol := fy.currencies[currency]
  271. l := len(s) + len(symbol) + 6 + 1*len(s[:len(s)-int(v)-1])/3
  272. count := 0
  273. inWhole := v == 0
  274. b := make([]byte, 0, l)
  275. for i := len(s) - 1; i >= 0; i-- {
  276. if s[i] == '.' {
  277. b = append(b, fy.decimal[0])
  278. inWhole = true
  279. continue
  280. }
  281. if inWhole {
  282. if count == 3 {
  283. b = append(b, fy.group[0])
  284. count = 1
  285. } else {
  286. count++
  287. }
  288. }
  289. b = append(b, s[i])
  290. }
  291. if num < 0 {
  292. for j := len(symbol) - 1; j >= 0; j-- {
  293. b = append(b, symbol[j])
  294. }
  295. for j := len(fy.currencyNegativePrefix) - 1; j >= 0; j-- {
  296. b = append(b, fy.currencyNegativePrefix[j])
  297. }
  298. } else {
  299. for j := len(symbol) - 1; j >= 0; j-- {
  300. b = append(b, symbol[j])
  301. }
  302. for j := len(fy.currencyPositivePrefix) - 1; j >= 0; j-- {
  303. b = append(b, fy.currencyPositivePrefix[j])
  304. }
  305. }
  306. // reverse
  307. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  308. b[i], b[j] = b[j], b[i]
  309. }
  310. if int(v) < 2 {
  311. if v == 0 {
  312. b = append(b, fy.decimal...)
  313. }
  314. for i := 0; i < 2-int(v); i++ {
  315. b = append(b, '0')
  316. }
  317. }
  318. if num < 0 {
  319. b = append(b, fy.currencyNegativeSuffix...)
  320. }
  321. return string(b)
  322. }
  323. // FmtDateShort returns the short date representation of 't' for 'fy'
  324. func (fy *fy) FmtDateShort(t time.Time) string {
  325. b := make([]byte, 0, 32)
  326. if t.Day() < 10 {
  327. b = append(b, '0')
  328. }
  329. b = strconv.AppendInt(b, int64(t.Day()), 10)
  330. b = append(b, []byte{0x2d}...)
  331. if t.Month() < 10 {
  332. b = append(b, '0')
  333. }
  334. b = strconv.AppendInt(b, int64(t.Month()), 10)
  335. b = append(b, []byte{0x2d}...)
  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 'fy'
  344. func (fy *fy) FmtDateMedium(t time.Time) string {
  345. b := make([]byte, 0, 32)
  346. b = strconv.AppendInt(b, int64(t.Day()), 10)
  347. b = append(b, []byte{0x20}...)
  348. b = append(b, fy.monthsAbbreviated[t.Month()]...)
  349. b = append(b, []byte{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 'fy'
  354. func (fy *fy) FmtDateLong(t time.Time) string {
  355. b := make([]byte, 0, 32)
  356. b = strconv.AppendInt(b, int64(t.Day()), 10)
  357. b = append(b, []byte{0x20}...)
  358. b = append(b, fy.monthsWide[t.Month()]...)
  359. b = append(b, []byte{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 'fy'
  364. func (fy *fy) FmtDateFull(t time.Time) string {
  365. b := make([]byte, 0, 32)
  366. b = append(b, fy.daysWide[t.Weekday()]...)
  367. b = append(b, []byte{0x20}...)
  368. b = strconv.AppendInt(b, int64(t.Day()), 10)
  369. b = append(b, []byte{0x20}...)
  370. b = append(b, fy.monthsWide[t.Month()]...)
  371. b = append(b, []byte{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 'fy'
  376. func (fy *fy) FmtTimeShort(t time.Time) string {
  377. b := make([]byte, 0, 32)
  378. if t.Hour() < 10 {
  379. b = append(b, '0')
  380. }
  381. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  382. b = append(b, fy.timeSeparator...)
  383. if t.Minute() < 10 {
  384. b = append(b, '0')
  385. }
  386. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  387. return string(b)
  388. }
  389. // FmtTimeMedium returns the medium time representation of 't' for 'fy'
  390. func (fy *fy) FmtTimeMedium(t time.Time) string {
  391. b := make([]byte, 0, 32)
  392. if t.Hour() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  396. b = append(b, fy.timeSeparator...)
  397. if t.Minute() < 10 {
  398. b = append(b, '0')
  399. }
  400. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  401. b = append(b, fy.timeSeparator...)
  402. if t.Second() < 10 {
  403. b = append(b, '0')
  404. }
  405. b = strconv.AppendInt(b, int64(t.Second()), 10)
  406. return string(b)
  407. }
  408. // FmtTimeLong returns the long time representation of 't' for 'fy'
  409. func (fy *fy) FmtTimeLong(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, fy.timeSeparator...)
  416. if t.Minute() < 10 {
  417. b = append(b, '0')
  418. }
  419. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  420. b = append(b, fy.timeSeparator...)
  421. if t.Second() < 10 {
  422. b = append(b, '0')
  423. }
  424. b = strconv.AppendInt(b, int64(t.Second()), 10)
  425. b = append(b, []byte{0x20}...)
  426. tz, _ := t.Zone()
  427. b = append(b, tz...)
  428. return string(b)
  429. }
  430. // FmtTimeFull returns the full time representation of 't' for 'fy'
  431. func (fy *fy) FmtTimeFull(t time.Time) string {
  432. b := make([]byte, 0, 32)
  433. if t.Hour() < 10 {
  434. b = append(b, '0')
  435. }
  436. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  437. b = append(b, fy.timeSeparator...)
  438. if t.Minute() < 10 {
  439. b = append(b, '0')
  440. }
  441. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  442. b = append(b, fy.timeSeparator...)
  443. if t.Second() < 10 {
  444. b = append(b, '0')
  445. }
  446. b = strconv.AppendInt(b, int64(t.Second()), 10)
  447. b = append(b, []byte{0x20}...)
  448. tz, _ := t.Zone()
  449. if btz, ok := fy.timezones[tz]; ok {
  450. b = append(b, btz...)
  451. } else {
  452. b = append(b, tz...)
  453. }
  454. return string(b)
  455. }