it.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. package it
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type it 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. currencyPositiveSuffix 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 'it' locale
  41. func New() locales.Translator {
  42. return &it{
  43. locale: "it",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: []locales.PluralRule{5, 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", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "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", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "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", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZ$", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "SUR", "SVC", "SYP", "SZL", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "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. currencyPositiveSuffix: " ",
  56. currencyNegativeSuffix: " ",
  57. monthsAbbreviated: []string{"", "gen", "feb", "mar", "apr", "mag", "giu", "lug", "ago", "set", "ott", "nov", "dic"},
  58. monthsNarrow: []string{"", "G", "F", "M", "A", "M", "G", "L", "A", "S", "O", "N", "D"},
  59. monthsWide: []string{"", "gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"},
  60. daysAbbreviated: []string{"dom", "lun", "mar", "mer", "gio", "ven", "sab"},
  61. daysNarrow: []string{"D", "L", "M", "M", "G", "V", "S"},
  62. daysShort: []string{"dom", "lun", "mar", "mer", "gio", "ven", "sab"},
  63. daysWide: []string{"domenica", "lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"m.", "p."},
  66. periodsWide: []string{"AM", "PM"},
  67. erasAbbreviated: []string{"a.C.", "d.C."},
  68. erasNarrow: []string{"aC", "dC"},
  69. erasWide: []string{"avanti Cristo", "dopo Cristo"},
  70. timezones: map[string]string{"∅∅∅": "∅∅∅", "ACWDT": "Ora legale dell’Australia centroccidentale", "WAT": "Ora standard dell’Africa occidentale", "CHAST": "Ora standard delle Chatham", "PST": "Ora standard del Pacifico USA", "WAST": "Ora legale dell’Africa occidentale", "WIB": "Ora dell’Indonesia occidentale", "MDT": "MDT", "MYT": "Ora della Malesia", "UYT": "Ora standard dell’Uruguay", "NZDT": "Ora legale della Nuova Zelanda", "AST": "Ora standard dell’Atlantico", "HAST": "Ora standard delle Isole Hawaii-Aleutine", "MEZ": "Ora standard dell’Europa centrale", "VET": "Ora del Venezuela", "OESZ": "Ora legale dell’Europa orientale", "EAT": "Ora dell’Africa orientale", "HNPMX": "Ora standard del Pacifico (Messico)", "ACWST": "Ora standard dell’Australia centroccidentale", "WITA": "Ora dell’Indonesia centrale", "ARST": "Ora legale dell’Argentina", "HEEG": "Ora legale della Groenlandia orientale", "EST": "Ora standard orientale USA", "WARST": "Ora legale dell’Argentina occidentale", "HENOMX": "Ora legale del Messico nord-occidentale", "AKST": "Ora standard dell’Alaska", "HEPM": "Ora legale di Saint-Pierre e Miquelon", "MST": "MST", "SRT": "Ora del Suriname", "TMT": "Ora standard del Turkmenistan", "MESZ": "Ora legale dell’Europa centrale", "ACDT": "Ora legale dell’Australia centrale", "WEZ": "Ora standard dell’Europa occidentale", "TMST": "Ora legale del Turkmenistan", "HNNOMX": "Ora standard del Messico nord-occidentale", "HNOG": "Ora standard della Groenlandia occidentale", "HKST": "Ora legale di Hong Kong", "ECT": "Ora dell’Ecuador", "WART": "Ora standard dell’Argentina occidentale", "ADT": "Ora legale dell’Atlantico", "HKT": "Ora standard di Hong Kong", "HAT": "Ora legale di Terranova", "HADT": "Ora legale delle Isole Hawaii-Aleutine", "CAT": "Ora dell’Africa centrale", "ChST": "Ora di Chamorro", "AWST": "Ora standard dell’Australia occidentale", "CST": "Ora standard centrale USA", "LHST": "Ora standard di Lord Howe", "WESZ": "Ora legale dell’Europa occidentale", "SGT": "Ora di Singapore", "EDT": "Ora legale orientale USA", "HNCU": "Ora standard di Cuba", "CDT": "Ora legale centrale USA", "JDT": "Ora legale del Giappone", "IST": "Ora standard dell’India", "ART": "Ora standard dell’Argentina", "CLT": "Ora standard del Cile", "BOT": "Ora della Bolivia", "BT": "Ora del Bhutan", "UYST": "Ora legale dell’Uruguay", "AEDT": "Ora legale dell’Australia orientale", "HNPM": "Ora standard di Saint-Pierre e Miquelon", "CHADT": "Ora legale delle Chatham", "HECU": "Ora legale di Cuba", "WIT": "Ora dell’Indonesia orientale", "AEST": "Ora standard dell’Australia orientale", "SAST": "Ora dell’Africa meridionale", "HNEG": "Ora standard della Groenlandia orientale", "ACST": "Ora standard dell’Australia centrale", "GYT": "Ora della Guyana", "HEPMX": "Ora legale del Pacifico (Messico)", "PDT": "Ora legale del Pacifico USA", "AWDT": "Ora legale dell’Australia occidentale", "NZST": "Ora standard della Nuova Zelanda", "HEOG": "Ora legale della Groenlandia occidentale", "GFT": "Ora della Guiana francese", "HNT": "Ora standard di Terranova", "COT": "Ora standard della Colombia", "GMT": "Ora del meridiano di Greenwich", "AKDT": "Ora legale dell’Alaska", "LHDT": "Ora legale di Lord Howe", "JST": "Ora standard del Giappone", "OEZ": "Ora standard dell’Europa orientale", "CLST": "Ora legale del Cile", "COST": "Ora legale della Colombia"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (it *it) Locale() string {
  75. return it.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'it'
  78. func (it *it) PluralsCardinal() []locales.PluralRule {
  79. return it.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'it'
  82. func (it *it) PluralsOrdinal() []locales.PluralRule {
  83. return it.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'it'
  86. func (it *it) PluralsRange() []locales.PluralRule {
  87. return it.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'it'
  90. func (it *it) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. if i == 1 && v == 0 {
  94. return locales.PluralRuleOne
  95. }
  96. return locales.PluralRuleOther
  97. }
  98. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'it'
  99. func (it *it) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  100. n := math.Abs(num)
  101. if n == 11 || n == 8 || n == 80 || n == 800 {
  102. return locales.PluralRuleMany
  103. }
  104. return locales.PluralRuleOther
  105. }
  106. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'it'
  107. func (it *it) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  108. start := it.CardinalPluralRule(num1, v1)
  109. end := it.CardinalPluralRule(num2, v2)
  110. if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  111. return locales.PluralRuleOther
  112. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  113. return locales.PluralRuleOne
  114. }
  115. return locales.PluralRuleOther
  116. }
  117. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  118. func (it *it) MonthAbbreviated(month time.Month) string {
  119. return it.monthsAbbreviated[month]
  120. }
  121. // MonthsAbbreviated returns the locales abbreviated months
  122. func (it *it) MonthsAbbreviated() []string {
  123. return it.monthsAbbreviated[1:]
  124. }
  125. // MonthNarrow returns the locales narrow month given the 'month' provided
  126. func (it *it) MonthNarrow(month time.Month) string {
  127. return it.monthsNarrow[month]
  128. }
  129. // MonthsNarrow returns the locales narrow months
  130. func (it *it) MonthsNarrow() []string {
  131. return it.monthsNarrow[1:]
  132. }
  133. // MonthWide returns the locales wide month given the 'month' provided
  134. func (it *it) MonthWide(month time.Month) string {
  135. return it.monthsWide[month]
  136. }
  137. // MonthsWide returns the locales wide months
  138. func (it *it) MonthsWide() []string {
  139. return it.monthsWide[1:]
  140. }
  141. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  142. func (it *it) WeekdayAbbreviated(weekday time.Weekday) string {
  143. return it.daysAbbreviated[weekday]
  144. }
  145. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  146. func (it *it) WeekdaysAbbreviated() []string {
  147. return it.daysAbbreviated
  148. }
  149. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  150. func (it *it) WeekdayNarrow(weekday time.Weekday) string {
  151. return it.daysNarrow[weekday]
  152. }
  153. // WeekdaysNarrow returns the locales narrow weekdays
  154. func (it *it) WeekdaysNarrow() []string {
  155. return it.daysNarrow
  156. }
  157. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  158. func (it *it) WeekdayShort(weekday time.Weekday) string {
  159. return it.daysShort[weekday]
  160. }
  161. // WeekdaysShort returns the locales short weekdays
  162. func (it *it) WeekdaysShort() []string {
  163. return it.daysShort
  164. }
  165. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  166. func (it *it) WeekdayWide(weekday time.Weekday) string {
  167. return it.daysWide[weekday]
  168. }
  169. // WeekdaysWide returns the locales wide weekdays
  170. func (it *it) WeekdaysWide() []string {
  171. return it.daysWide
  172. }
  173. // Decimal returns the decimal point of number
  174. func (it *it) Decimal() string {
  175. return it.decimal
  176. }
  177. // Group returns the group of number
  178. func (it *it) Group() string {
  179. return it.group
  180. }
  181. // Group returns the minus sign of number
  182. func (it *it) Minus() string {
  183. return it.minus
  184. }
  185. // FmtNumber returns 'num' with digits/precision of 'v' for 'it' and handles both Whole and Real numbers based on 'v'
  186. func (it *it) FmtNumber(num float64, v uint64) string {
  187. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  188. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  189. count := 0
  190. inWhole := v == 0
  191. b := make([]byte, 0, l)
  192. for i := len(s) - 1; i >= 0; i-- {
  193. if s[i] == '.' {
  194. b = append(b, it.decimal[0])
  195. inWhole = true
  196. continue
  197. }
  198. if inWhole {
  199. if count == 3 {
  200. b = append(b, it.group[0])
  201. count = 1
  202. } else {
  203. count++
  204. }
  205. }
  206. b = append(b, s[i])
  207. }
  208. if num < 0 {
  209. b = append(b, it.minus[0])
  210. }
  211. // reverse
  212. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  213. b[i], b[j] = b[j], b[i]
  214. }
  215. return string(b)
  216. }
  217. // FmtPercent returns 'num' with digits/precision of 'v' for 'it' and handles both Whole and Real numbers based on 'v'
  218. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  219. func (it *it) FmtPercent(num float64, v uint64) string {
  220. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  221. l := len(s) + 3
  222. b := make([]byte, 0, l)
  223. for i := len(s) - 1; i >= 0; i-- {
  224. if s[i] == '.' {
  225. b = append(b, it.decimal[0])
  226. continue
  227. }
  228. b = append(b, s[i])
  229. }
  230. if num < 0 {
  231. b = append(b, it.minus[0])
  232. }
  233. // reverse
  234. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  235. b[i], b[j] = b[j], b[i]
  236. }
  237. b = append(b, it.percent...)
  238. return string(b)
  239. }
  240. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'it'
  241. func (it *it) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  242. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  243. symbol := it.currencies[currency]
  244. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  245. count := 0
  246. inWhole := v == 0
  247. b := make([]byte, 0, l)
  248. for i := len(s) - 1; i >= 0; i-- {
  249. if s[i] == '.' {
  250. b = append(b, it.decimal[0])
  251. inWhole = true
  252. continue
  253. }
  254. if inWhole {
  255. if count == 3 {
  256. b = append(b, it.group[0])
  257. count = 1
  258. } else {
  259. count++
  260. }
  261. }
  262. b = append(b, s[i])
  263. }
  264. if num < 0 {
  265. b = append(b, it.minus[0])
  266. }
  267. // reverse
  268. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  269. b[i], b[j] = b[j], b[i]
  270. }
  271. if int(v) < 2 {
  272. if v == 0 {
  273. b = append(b, it.decimal...)
  274. }
  275. for i := 0; i < 2-int(v); i++ {
  276. b = append(b, '0')
  277. }
  278. }
  279. b = append(b, it.currencyPositiveSuffix...)
  280. b = append(b, symbol...)
  281. return string(b)
  282. }
  283. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'it'
  284. // in accounting notation.
  285. func (it *it) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  286. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  287. symbol := it.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, it.decimal[0])
  295. inWhole = true
  296. continue
  297. }
  298. if inWhole {
  299. if count == 3 {
  300. b = append(b, it.group[0])
  301. count = 1
  302. } else {
  303. count++
  304. }
  305. }
  306. b = append(b, s[i])
  307. }
  308. if num < 0 {
  309. b = append(b, it.minus[0])
  310. }
  311. // reverse
  312. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  313. b[i], b[j] = b[j], b[i]
  314. }
  315. if int(v) < 2 {
  316. if v == 0 {
  317. b = append(b, it.decimal...)
  318. }
  319. for i := 0; i < 2-int(v); i++ {
  320. b = append(b, '0')
  321. }
  322. }
  323. if num < 0 {
  324. b = append(b, it.currencyNegativeSuffix...)
  325. b = append(b, symbol...)
  326. } else {
  327. b = append(b, it.currencyPositiveSuffix...)
  328. b = append(b, symbol...)
  329. }
  330. return string(b)
  331. }
  332. // FmtDateShort returns the short date representation of 't' for 'it'
  333. func (it *it) FmtDateShort(t time.Time) string {
  334. b := make([]byte, 0, 32)
  335. if t.Day() < 10 {
  336. b = append(b, '0')
  337. }
  338. b = strconv.AppendInt(b, int64(t.Day()), 10)
  339. b = append(b, []byte{0x2f}...)
  340. if t.Month() < 10 {
  341. b = append(b, '0')
  342. }
  343. b = strconv.AppendInt(b, int64(t.Month()), 10)
  344. b = append(b, []byte{0x2f}...)
  345. if t.Year() > 9 {
  346. b = append(b, strconv.Itoa(t.Year())[2:]...)
  347. } else {
  348. b = append(b, strconv.Itoa(t.Year())[1:]...)
  349. }
  350. return string(b)
  351. }
  352. // FmtDateMedium returns the medium date representation of 't' for 'it'
  353. func (it *it) FmtDateMedium(t time.Time) string {
  354. b := make([]byte, 0, 32)
  355. if t.Day() < 10 {
  356. b = append(b, '0')
  357. }
  358. b = strconv.AppendInt(b, int64(t.Day()), 10)
  359. b = append(b, []byte{0x20}...)
  360. b = append(b, it.monthsAbbreviated[t.Month()]...)
  361. b = append(b, []byte{0x20}...)
  362. if t.Year() > 0 {
  363. b = strconv.AppendInt(b, int64(t.Year()), 10)
  364. } else {
  365. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  366. }
  367. return string(b)
  368. }
  369. // FmtDateLong returns the long date representation of 't' for 'it'
  370. func (it *it) FmtDateLong(t time.Time) string {
  371. b := make([]byte, 0, 32)
  372. b = strconv.AppendInt(b, int64(t.Day()), 10)
  373. b = append(b, []byte{0x20}...)
  374. b = append(b, it.monthsWide[t.Month()]...)
  375. b = append(b, []byte{0x20}...)
  376. if t.Year() > 0 {
  377. b = strconv.AppendInt(b, int64(t.Year()), 10)
  378. } else {
  379. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  380. }
  381. return string(b)
  382. }
  383. // FmtDateFull returns the full date representation of 't' for 'it'
  384. func (it *it) FmtDateFull(t time.Time) string {
  385. b := make([]byte, 0, 32)
  386. b = append(b, it.daysWide[t.Weekday()]...)
  387. b = append(b, []byte{0x20}...)
  388. b = strconv.AppendInt(b, int64(t.Day()), 10)
  389. b = append(b, []byte{0x20}...)
  390. b = append(b, it.monthsWide[t.Month()]...)
  391. b = append(b, []byte{0x20}...)
  392. if t.Year() > 0 {
  393. b = strconv.AppendInt(b, int64(t.Year()), 10)
  394. } else {
  395. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  396. }
  397. return string(b)
  398. }
  399. // FmtTimeShort returns the short time representation of 't' for 'it'
  400. func (it *it) FmtTimeShort(t time.Time) string {
  401. b := make([]byte, 0, 32)
  402. if t.Hour() < 10 {
  403. b = append(b, '0')
  404. }
  405. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  406. b = append(b, it.timeSeparator...)
  407. if t.Minute() < 10 {
  408. b = append(b, '0')
  409. }
  410. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  411. return string(b)
  412. }
  413. // FmtTimeMedium returns the medium time representation of 't' for 'it'
  414. func (it *it) FmtTimeMedium(t time.Time) string {
  415. b := make([]byte, 0, 32)
  416. if t.Hour() < 10 {
  417. b = append(b, '0')
  418. }
  419. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  420. b = append(b, it.timeSeparator...)
  421. if t.Minute() < 10 {
  422. b = append(b, '0')
  423. }
  424. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  425. b = append(b, it.timeSeparator...)
  426. if t.Second() < 10 {
  427. b = append(b, '0')
  428. }
  429. b = strconv.AppendInt(b, int64(t.Second()), 10)
  430. return string(b)
  431. }
  432. // FmtTimeLong returns the long time representation of 't' for 'it'
  433. func (it *it) FmtTimeLong(t time.Time) string {
  434. b := make([]byte, 0, 32)
  435. if t.Hour() < 10 {
  436. b = append(b, '0')
  437. }
  438. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  439. b = append(b, it.timeSeparator...)
  440. if t.Minute() < 10 {
  441. b = append(b, '0')
  442. }
  443. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  444. b = append(b, it.timeSeparator...)
  445. if t.Second() < 10 {
  446. b = append(b, '0')
  447. }
  448. b = strconv.AppendInt(b, int64(t.Second()), 10)
  449. b = append(b, []byte{0x20}...)
  450. tz, _ := t.Zone()
  451. b = append(b, tz...)
  452. return string(b)
  453. }
  454. // FmtTimeFull returns the full time representation of 't' for 'it'
  455. func (it *it) FmtTimeFull(t time.Time) string {
  456. b := make([]byte, 0, 32)
  457. if t.Hour() < 10 {
  458. b = append(b, '0')
  459. }
  460. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  461. b = append(b, it.timeSeparator...)
  462. if t.Minute() < 10 {
  463. b = append(b, '0')
  464. }
  465. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  466. b = append(b, it.timeSeparator...)
  467. if t.Second() < 10 {
  468. b = append(b, '0')
  469. }
  470. b = strconv.AppendInt(b, int64(t.Second()), 10)
  471. b = append(b, []byte{0x20}...)
  472. tz, _ := t.Zone()
  473. if btz, ok := it.timezones[tz]; ok {
  474. b = append(b, btz...)
  475. } else {
  476. b = append(b, tz...)
  477. }
  478. return string(b)
  479. }