hu.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. package hu
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type hu 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 'hu' locale
  41. func New() locales.Translator {
  42. return &hu{
  43. locale: "hu",
  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", "AUD", "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", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CNY", "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", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "Ft", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "¥", "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", "NZD", "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", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "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{"", "jan.", "febr.", "márc.", "ápr.", "máj.", "jún.", "júl.", "aug.", "szept.", "okt.", "nov.", "dec."},
  58. monthsNarrow: []string{"", "J", "F", "M", "Á", "M", "J", "J", "A", "Sz", "O", "N", "D"},
  59. monthsWide: []string{"", "január", "február", "március", "április", "május", "június", "július", "augusztus", "szeptember", "október", "november", "december"},
  60. daysAbbreviated: []string{"V", "H", "K", "Sze", "Cs", "P", "Szo"},
  61. daysNarrow: []string{"V", "H", "K", "Sz", "Cs", "P", "Sz"},
  62. daysShort: []string{"V", "H", "K", "Sze", "Cs", "P", "Szo"},
  63. daysWide: []string{"vasárnap", "hétfő", "kedd", "szerda", "csütörtök", "péntek", "szombat"},
  64. periodsAbbreviated: []string{"de.", "du."},
  65. periodsNarrow: []string{"de.", "du."},
  66. periodsWide: []string{"de.", "du."},
  67. erasAbbreviated: []string{"i. e.", "i. sz."},
  68. erasNarrow: []string{"ie.", "isz."},
  69. erasWide: []string{"Krisztus előtt", "időszámításunk szerint"},
  70. timezones: map[string]string{"HKST": "hongkongi nyári idő", "WARST": "nyugat-argentínai nyári idő", "COST": "kolumbiai nyári idő", "OEZ": "kelet-európai téli idő", "HNPMX": "mexikói csendes-óceáni zónaidő", "CDT": "középső államokbeli nyári idő", "AWST": "nyugat-ausztráliai téli idő", "ECT": "ecuadori téli idő", "MEZ": "közép-európai téli idő", "∅∅∅": "azori nyári idő", "WESZ": "nyugat-európai nyári idő", "GFT": "francia-guyanai idő", "ACST": "közép-ausztráliai téli idő", "ACWST": "közép-nyugat-ausztráliai téli idő", "WITA": "közép-indonéziai idő", "HEPM": "Saint-Pierre és Miquelon-i nyári idő", "CLST": "chilei nyári idő", "PDT": "csendes-óceáni nyári idő", "BT": "butáni idő", "NZDT": "új-zélandi nyári idő", "HEEG": "kelet-grönlandi nyári idő", "HNT": "új-fundlandi zónaidő", "HAT": "új-fundlandi nyári idő", "TMT": "türkmenisztáni téli idő", "ChST": "chamorrói téli idő", "SAST": "dél-afrikai téli idő", "WAST": "nyugat-afrikai nyári idő", "BOT": "bolíviai téli idő", "AKST": "alaszkai zónaidő", "EDT": "keleti államokbeli nyári idő", "ACWDT": "közép-nyugat-ausztráliai nyári idő", "MESZ": "közép-európai nyári idő", "LHST": "Lord Howe-szigeti téli idő", "LHDT": "Lord Howe-szigeti nyári idő", "HADT": "hawaii-aleuti nyári idő", "EST": "keleti államokbeli zónaidő", "HENOMX": "északnyugat-mexikói nyári idő", "WIT": "kelet-indonéziai idő", "OESZ": "kelet-európai nyári idő", "HKT": "hongkongi téli idő", "WART": "nyugat-argentínai téli idő", "MST": "Macaui zónaidő", "HEPMX": "mexikói csendes-óceáni nyári idő", "AST": "atlanti-óceáni zónaidő", "AEDT": "kelet-ausztráliai nyári idő", "TMST": "türkmenisztáni nyári idő", "CAT": "közép-afrikai téli idő", "EAT": "kelet-afrikai téli idő", "NZST": "új-zélandi téli idő", "MYT": "malajziai idő", "HNEG": "kelet-grönlandi téli idő", "GMT": "greenwichi középidő, téli idő", "HNOG": "nyugat-grönlandi téli idő", "COT": "kolumbiai téli idő", "PST": "csendes-óceáni zónaidő", "ART": "argentínai téli idő", "CHAST": "chathami téli idő", "CHADT": "chathami nyári idő", "JDT": "japán nyári idő", "HEOG": "nyugat-grönlandi nyári idő", "CLT": "chilei téli idő", "UYT": "uruguayi téli idő", "HNCU": "kubai téli idő", "SGT": "szingapúri téli idő", "ACDT": "közép-ausztráliai nyári idő", "HNNOMX": "északnyugat-mexikói zónaidő", "GYT": "guyanai téli idő", "CST": "középső államokbeli zónaidő", "WAT": "nyugat-afrikai téli idő", "IST": "indiai téli idő", "VET": "venezuelai idő", "SRT": "szurinámi idő", "HAST": "hawaii-aleuti téli idő", "HECU": "kubai nyári idő", "AWDT": "nyugat-ausztráliai nyári idő", "WIB": "nyugat-indonéziai téli idő", "WEZ": "nyugat-európai téli idő", "JST": "japán téli idő", "AKDT": "alaszkai nyári idő", "HNPM": "Saint-Pierre és Miquelon-i zónaidő", "MDT": "Macaui nyári idő", "ARST": "argentínai nyári idő", "UYST": "uruguayi nyári idő", "ADT": "atlanti-óceáni nyári idő", "AEST": "kelet-ausztráliai téli idő"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (hu *hu) Locale() string {
  75. return hu.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'hu'
  78. func (hu *hu) PluralsCardinal() []locales.PluralRule {
  79. return hu.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'hu'
  82. func (hu *hu) PluralsOrdinal() []locales.PluralRule {
  83. return hu.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'hu'
  86. func (hu *hu) PluralsRange() []locales.PluralRule {
  87. return hu.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'hu'
  90. func (hu *hu) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. if n == 1 {
  93. return locales.PluralRuleOne
  94. }
  95. return locales.PluralRuleOther
  96. }
  97. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'hu'
  98. func (hu *hu) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  99. n := math.Abs(num)
  100. if n == 1 || n == 5 {
  101. return locales.PluralRuleOne
  102. }
  103. return locales.PluralRuleOther
  104. }
  105. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'hu'
  106. func (hu *hu) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  107. start := hu.CardinalPluralRule(num1, v1)
  108. end := hu.CardinalPluralRule(num2, v2)
  109. if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  110. return locales.PluralRuleOther
  111. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  112. return locales.PluralRuleOne
  113. }
  114. return locales.PluralRuleOther
  115. }
  116. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  117. func (hu *hu) MonthAbbreviated(month time.Month) string {
  118. return hu.monthsAbbreviated[month]
  119. }
  120. // MonthsAbbreviated returns the locales abbreviated months
  121. func (hu *hu) MonthsAbbreviated() []string {
  122. return hu.monthsAbbreviated[1:]
  123. }
  124. // MonthNarrow returns the locales narrow month given the 'month' provided
  125. func (hu *hu) MonthNarrow(month time.Month) string {
  126. return hu.monthsNarrow[month]
  127. }
  128. // MonthsNarrow returns the locales narrow months
  129. func (hu *hu) MonthsNarrow() []string {
  130. return hu.monthsNarrow[1:]
  131. }
  132. // MonthWide returns the locales wide month given the 'month' provided
  133. func (hu *hu) MonthWide(month time.Month) string {
  134. return hu.monthsWide[month]
  135. }
  136. // MonthsWide returns the locales wide months
  137. func (hu *hu) MonthsWide() []string {
  138. return hu.monthsWide[1:]
  139. }
  140. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  141. func (hu *hu) WeekdayAbbreviated(weekday time.Weekday) string {
  142. return hu.daysAbbreviated[weekday]
  143. }
  144. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  145. func (hu *hu) WeekdaysAbbreviated() []string {
  146. return hu.daysAbbreviated
  147. }
  148. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  149. func (hu *hu) WeekdayNarrow(weekday time.Weekday) string {
  150. return hu.daysNarrow[weekday]
  151. }
  152. // WeekdaysNarrow returns the locales narrow weekdays
  153. func (hu *hu) WeekdaysNarrow() []string {
  154. return hu.daysNarrow
  155. }
  156. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  157. func (hu *hu) WeekdayShort(weekday time.Weekday) string {
  158. return hu.daysShort[weekday]
  159. }
  160. // WeekdaysShort returns the locales short weekdays
  161. func (hu *hu) WeekdaysShort() []string {
  162. return hu.daysShort
  163. }
  164. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  165. func (hu *hu) WeekdayWide(weekday time.Weekday) string {
  166. return hu.daysWide[weekday]
  167. }
  168. // WeekdaysWide returns the locales wide weekdays
  169. func (hu *hu) WeekdaysWide() []string {
  170. return hu.daysWide
  171. }
  172. // Decimal returns the decimal point of number
  173. func (hu *hu) Decimal() string {
  174. return hu.decimal
  175. }
  176. // Group returns the group of number
  177. func (hu *hu) Group() string {
  178. return hu.group
  179. }
  180. // Group returns the minus sign of number
  181. func (hu *hu) Minus() string {
  182. return hu.minus
  183. }
  184. // FmtNumber returns 'num' with digits/precision of 'v' for 'hu' and handles both Whole and Real numbers based on 'v'
  185. func (hu *hu) FmtNumber(num float64, v uint64) string {
  186. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  187. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  188. count := 0
  189. inWhole := v == 0
  190. b := make([]byte, 0, l)
  191. for i := len(s) - 1; i >= 0; i-- {
  192. if s[i] == '.' {
  193. b = append(b, hu.decimal[0])
  194. inWhole = true
  195. continue
  196. }
  197. if inWhole {
  198. if count == 3 {
  199. for j := len(hu.group) - 1; j >= 0; j-- {
  200. b = append(b, hu.group[j])
  201. }
  202. count = 1
  203. } else {
  204. count++
  205. }
  206. }
  207. b = append(b, s[i])
  208. }
  209. if num < 0 {
  210. b = append(b, hu.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. return string(b)
  217. }
  218. // FmtPercent returns 'num' with digits/precision of 'v' for 'hu' and handles both Whole and Real numbers based on 'v'
  219. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  220. func (hu *hu) FmtPercent(num float64, v uint64) string {
  221. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  222. l := len(s) + 3
  223. b := make([]byte, 0, l)
  224. for i := len(s) - 1; i >= 0; i-- {
  225. if s[i] == '.' {
  226. b = append(b, hu.decimal[0])
  227. continue
  228. }
  229. b = append(b, s[i])
  230. }
  231. if num < 0 {
  232. b = append(b, hu.minus[0])
  233. }
  234. // reverse
  235. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  236. b[i], b[j] = b[j], b[i]
  237. }
  238. b = append(b, hu.percent...)
  239. return string(b)
  240. }
  241. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'hu'
  242. func (hu *hu) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  243. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  244. symbol := hu.currencies[currency]
  245. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  246. count := 0
  247. inWhole := v == 0
  248. b := make([]byte, 0, l)
  249. for i := len(s) - 1; i >= 0; i-- {
  250. if s[i] == '.' {
  251. b = append(b, hu.decimal[0])
  252. inWhole = true
  253. continue
  254. }
  255. if inWhole {
  256. if count == 3 {
  257. for j := len(hu.group) - 1; j >= 0; j-- {
  258. b = append(b, hu.group[j])
  259. }
  260. count = 1
  261. } else {
  262. count++
  263. }
  264. }
  265. b = append(b, s[i])
  266. }
  267. if num < 0 {
  268. b = append(b, hu.minus[0])
  269. }
  270. // reverse
  271. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  272. b[i], b[j] = b[j], b[i]
  273. }
  274. if int(v) < 2 {
  275. if v == 0 {
  276. b = append(b, hu.decimal...)
  277. }
  278. for i := 0; i < 2-int(v); i++ {
  279. b = append(b, '0')
  280. }
  281. }
  282. b = append(b, hu.currencyPositiveSuffix...)
  283. b = append(b, symbol...)
  284. return string(b)
  285. }
  286. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'hu'
  287. // in accounting notation.
  288. func (hu *hu) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  289. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  290. symbol := hu.currencies[currency]
  291. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  292. count := 0
  293. inWhole := v == 0
  294. b := make([]byte, 0, l)
  295. for i := len(s) - 1; i >= 0; i-- {
  296. if s[i] == '.' {
  297. b = append(b, hu.decimal[0])
  298. inWhole = true
  299. continue
  300. }
  301. if inWhole {
  302. if count == 3 {
  303. for j := len(hu.group) - 1; j >= 0; j-- {
  304. b = append(b, hu.group[j])
  305. }
  306. count = 1
  307. } else {
  308. count++
  309. }
  310. }
  311. b = append(b, s[i])
  312. }
  313. if num < 0 {
  314. b = append(b, hu.minus[0])
  315. }
  316. // reverse
  317. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  318. b[i], b[j] = b[j], b[i]
  319. }
  320. if int(v) < 2 {
  321. if v == 0 {
  322. b = append(b, hu.decimal...)
  323. }
  324. for i := 0; i < 2-int(v); i++ {
  325. b = append(b, '0')
  326. }
  327. }
  328. if num < 0 {
  329. b = append(b, hu.currencyNegativeSuffix...)
  330. b = append(b, symbol...)
  331. } else {
  332. b = append(b, hu.currencyPositiveSuffix...)
  333. b = append(b, symbol...)
  334. }
  335. return string(b)
  336. }
  337. // FmtDateShort returns the short date representation of 't' for 'hu'
  338. func (hu *hu) FmtDateShort(t time.Time) string {
  339. b := make([]byte, 0, 32)
  340. if t.Year() > 0 {
  341. b = strconv.AppendInt(b, int64(t.Year()), 10)
  342. } else {
  343. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  344. }
  345. b = append(b, []byte{0x2e, 0x20}...)
  346. if t.Month() < 10 {
  347. b = append(b, '0')
  348. }
  349. b = strconv.AppendInt(b, int64(t.Month()), 10)
  350. b = append(b, []byte{0x2e, 0x20}...)
  351. if t.Day() < 10 {
  352. b = append(b, '0')
  353. }
  354. b = strconv.AppendInt(b, int64(t.Day()), 10)
  355. b = append(b, []byte{0x2e}...)
  356. return string(b)
  357. }
  358. // FmtDateMedium returns the medium date representation of 't' for 'hu'
  359. func (hu *hu) FmtDateMedium(t time.Time) string {
  360. b := make([]byte, 0, 32)
  361. if t.Year() > 0 {
  362. b = strconv.AppendInt(b, int64(t.Year()), 10)
  363. } else {
  364. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  365. }
  366. b = append(b, []byte{0x2e, 0x20}...)
  367. b = append(b, hu.monthsAbbreviated[t.Month()]...)
  368. b = append(b, []byte{0x20}...)
  369. b = strconv.AppendInt(b, int64(t.Day()), 10)
  370. b = append(b, []byte{0x2e}...)
  371. return string(b)
  372. }
  373. // FmtDateLong returns the long date representation of 't' for 'hu'
  374. func (hu *hu) FmtDateLong(t time.Time) string {
  375. b := make([]byte, 0, 32)
  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. b = append(b, []byte{0x2e, 0x20}...)
  382. b = append(b, hu.monthsWide[t.Month()]...)
  383. b = append(b, []byte{0x20}...)
  384. b = strconv.AppendInt(b, int64(t.Day()), 10)
  385. b = append(b, []byte{0x2e}...)
  386. return string(b)
  387. }
  388. // FmtDateFull returns the full date representation of 't' for 'hu'
  389. func (hu *hu) FmtDateFull(t time.Time) string {
  390. b := make([]byte, 0, 32)
  391. if t.Year() > 0 {
  392. b = strconv.AppendInt(b, int64(t.Year()), 10)
  393. } else {
  394. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  395. }
  396. b = append(b, []byte{0x2e, 0x20}...)
  397. b = append(b, hu.monthsWide[t.Month()]...)
  398. b = append(b, []byte{0x20}...)
  399. b = strconv.AppendInt(b, int64(t.Day()), 10)
  400. b = append(b, []byte{0x2e, 0x2c, 0x20}...)
  401. b = append(b, hu.daysWide[t.Weekday()]...)
  402. return string(b)
  403. }
  404. // FmtTimeShort returns the short time representation of 't' for 'hu'
  405. func (hu *hu) FmtTimeShort(t time.Time) string {
  406. b := make([]byte, 0, 32)
  407. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  408. b = append(b, hu.timeSeparator...)
  409. if t.Minute() < 10 {
  410. b = append(b, '0')
  411. }
  412. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  413. return string(b)
  414. }
  415. // FmtTimeMedium returns the medium time representation of 't' for 'hu'
  416. func (hu *hu) FmtTimeMedium(t time.Time) string {
  417. b := make([]byte, 0, 32)
  418. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  419. b = append(b, hu.timeSeparator...)
  420. if t.Minute() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  424. b = append(b, hu.timeSeparator...)
  425. if t.Second() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Second()), 10)
  429. return string(b)
  430. }
  431. // FmtTimeLong returns the long time representation of 't' for 'hu'
  432. func (hu *hu) FmtTimeLong(t time.Time) string {
  433. b := make([]byte, 0, 32)
  434. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  435. b = append(b, hu.timeSeparator...)
  436. if t.Minute() < 10 {
  437. b = append(b, '0')
  438. }
  439. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  440. b = append(b, hu.timeSeparator...)
  441. if t.Second() < 10 {
  442. b = append(b, '0')
  443. }
  444. b = strconv.AppendInt(b, int64(t.Second()), 10)
  445. b = append(b, []byte{0x20}...)
  446. tz, _ := t.Zone()
  447. b = append(b, tz...)
  448. return string(b)
  449. }
  450. // FmtTimeFull returns the full time representation of 't' for 'hu'
  451. func (hu *hu) FmtTimeFull(t time.Time) string {
  452. b := make([]byte, 0, 32)
  453. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  454. b = append(b, hu.timeSeparator...)
  455. if t.Minute() < 10 {
  456. b = append(b, '0')
  457. }
  458. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  459. b = append(b, hu.timeSeparator...)
  460. if t.Second() < 10 {
  461. b = append(b, '0')
  462. }
  463. b = strconv.AppendInt(b, int64(t.Second()), 10)
  464. b = append(b, []byte{0x20}...)
  465. tz, _ := t.Zone()
  466. if btz, ok := hu.timezones[tz]; ok {
  467. b = append(b, btz...)
  468. } else {
  469. b = append(b, tz...)
  470. }
  471. return string(b)
  472. }