hu.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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{6, 2},
  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 ", "BYR", "BZD", "CAD", "CDF", "CHE ", "CHF", "CHW ", "CLE ", "CLF ", "CLP", "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", "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{"időszámításunk előtt", "időszámításunk szerint"},
  70. timezones: map[string]string{"WITA": "közép-indonéziai idő", "∅∅∅": "amazóniai nyári idő", "GYT": "guyanai téli idő", "TMT": "türkmenisztáni téli idő", "WESZ": "nyugat-európai nyári idő", "COST": "kolumbiai nyári idő", "SAST": "dél-afrikai téli idő", "ChST": "chamorrói téli idő", "OESZ": "kelet-európai nyári idő", "MYT": "malajziai idő", "AKST": "alaszkai zónaidő", "BOT": "bolíviai téli idő", "ART": "argentínai téli idő", "NZDT": "új-zélandi nyári idő", "CLST": "chilei nyári idő", "HKST": "hongkongi nyári idő", "CAT": "közép-afrikai téli idő", "HADT": "hawaii-aleuti nyári idő", "WAT": "nyugat-afrikai téli idő", "ACST": "közép-ausztráliai téli idő", "MST": "Macaui zónaidő", "AWDT": "nyugat-ausztráliai nyári idő", "AEST": "kelet-ausztráliai téli idő", "OEZ": "kelet-európai téli idő", "JST": "japán téli idő", "ACWST": "közép-nyugat-ausztráliai téli idő", "CLT": "chilei téli idő", "WEZ": "nyugat-európai téli idő", "LHDT": "Lord Howe-szigeti nyári idő", "JDT": "japán nyári idő", "PST": "csendes-óceáni zónaidő", "UYST": "uruguayi nyári idő", "ACDT": "közép-ausztráliai nyári idő", "CHADT": "chathami nyári idő", "EAT": "kelet-afrikai téli idő", "MDT": "Macaui nyári idő", "SGT": "szingapúri téli idő", "HAST": "hawaii-aleuti téli idő", "HKT": "hongkongi téli idő", "GMT": "greenwichi középidő, téli idő", "LHST": "Lord Howe-szigeti téli idő", "EST": "keleti államokbeli zónaidő", "BT": "butáni idő", "UYT": "uruguayi téli idő", "CDT": "középső államokbeli nyári idő", "EDT": "keleti államokbeli nyári idő", "WAST": "nyugat-afrikai nyári idő", "PDT": "csendes-óceáni nyári idő", "VET": "venezuelai idő", "AST": "atlanti-óceáni zónaidő", "WARST": "nyugat-argentínai nyári idő", "HAT": "új-fundlandi nyári idő", "WIT": "kelet-indonéziai idő", "MESZ": "közép-európai nyári idő", "WART": "nyugat-argentínai téli idő", "ARST": "Argentínai nyári idő", "TMST": "türkmenisztáni nyári idő", "COT": "kolumbiai téli idő", "ADT": "atlanti-óceáni nyári idő", "AEDT": "kelet-ausztráliai nyári idő", "ACWDT": "közép-nyugat-ausztráliai nyári idő", "ECT": "ecuadori téli idő", "HNT": "új-fundlandi zónaidő", "GFT": "francia-guianai idő", "AWST": "nyugat-ausztráliai téli idő", "NZST": "új-zélandi téli idő", "CST": "középső államokbeli zónaidő", "MEZ": "közép-európai téli idő", "CHAST": "chathami téli idő", "WIB": "nyugat-indonéziai téli idő", "IST": "indiai téli idő", "SRT": "szurinámi idő", "AKDT": "alaszkai nyári 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. // FmtNumber returns 'num' with digits/precision of 'v' for 'hu' and handles both Whole and Real numbers based on 'v'
  173. func (hu *hu) FmtNumber(num float64, v uint64) string {
  174. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  175. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  176. count := 0
  177. inWhole := v == 0
  178. b := make([]byte, 0, l)
  179. for i := len(s) - 1; i >= 0; i-- {
  180. if s[i] == '.' {
  181. b = append(b, hu.decimal[0])
  182. inWhole = true
  183. continue
  184. }
  185. if inWhole {
  186. if count == 3 {
  187. for j := len(hu.group) - 1; j >= 0; j-- {
  188. b = append(b, hu.group[j])
  189. }
  190. count = 1
  191. } else {
  192. count++
  193. }
  194. }
  195. b = append(b, s[i])
  196. }
  197. if num < 0 {
  198. b = append(b, hu.minus[0])
  199. }
  200. // reverse
  201. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  202. b[i], b[j] = b[j], b[i]
  203. }
  204. return string(b)
  205. }
  206. // FmtPercent returns 'num' with digits/precision of 'v' for 'hu' and handles both Whole and Real numbers based on 'v'
  207. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  208. func (hu *hu) FmtPercent(num float64, v uint64) string {
  209. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  210. l := len(s) + 3
  211. b := make([]byte, 0, l)
  212. for i := len(s) - 1; i >= 0; i-- {
  213. if s[i] == '.' {
  214. b = append(b, hu.decimal[0])
  215. continue
  216. }
  217. b = append(b, s[i])
  218. }
  219. if num < 0 {
  220. b = append(b, hu.minus[0])
  221. }
  222. // reverse
  223. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  224. b[i], b[j] = b[j], b[i]
  225. }
  226. b = append(b, hu.percent...)
  227. return string(b)
  228. }
  229. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'hu'
  230. func (hu *hu) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  231. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  232. symbol := hu.currencies[currency]
  233. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  234. count := 0
  235. inWhole := v == 0
  236. b := make([]byte, 0, l)
  237. for i := len(s) - 1; i >= 0; i-- {
  238. if s[i] == '.' {
  239. b = append(b, hu.decimal[0])
  240. inWhole = true
  241. continue
  242. }
  243. if inWhole {
  244. if count == 3 {
  245. for j := len(hu.group) - 1; j >= 0; j-- {
  246. b = append(b, hu.group[j])
  247. }
  248. count = 1
  249. } else {
  250. count++
  251. }
  252. }
  253. b = append(b, s[i])
  254. }
  255. if num < 0 {
  256. b = append(b, hu.minus[0])
  257. }
  258. // reverse
  259. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  260. b[i], b[j] = b[j], b[i]
  261. }
  262. if int(v) < 2 {
  263. if v == 0 {
  264. b = append(b, hu.decimal...)
  265. }
  266. for i := 0; i < 2-int(v); i++ {
  267. b = append(b, '0')
  268. }
  269. }
  270. b = append(b, hu.currencyPositiveSuffix...)
  271. b = append(b, symbol...)
  272. return string(b)
  273. }
  274. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'hu'
  275. // in accounting notation.
  276. func (hu *hu) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  277. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  278. symbol := hu.currencies[currency]
  279. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  280. count := 0
  281. inWhole := v == 0
  282. b := make([]byte, 0, l)
  283. for i := len(s) - 1; i >= 0; i-- {
  284. if s[i] == '.' {
  285. b = append(b, hu.decimal[0])
  286. inWhole = true
  287. continue
  288. }
  289. if inWhole {
  290. if count == 3 {
  291. for j := len(hu.group) - 1; j >= 0; j-- {
  292. b = append(b, hu.group[j])
  293. }
  294. count = 1
  295. } else {
  296. count++
  297. }
  298. }
  299. b = append(b, s[i])
  300. }
  301. if num < 0 {
  302. b = append(b, hu.minus[0])
  303. }
  304. // reverse
  305. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  306. b[i], b[j] = b[j], b[i]
  307. }
  308. if int(v) < 2 {
  309. if v == 0 {
  310. b = append(b, hu.decimal...)
  311. }
  312. for i := 0; i < 2-int(v); i++ {
  313. b = append(b, '0')
  314. }
  315. }
  316. if num < 0 {
  317. b = append(b, hu.currencyNegativeSuffix...)
  318. b = append(b, symbol...)
  319. } else {
  320. b = append(b, hu.currencyPositiveSuffix...)
  321. b = append(b, symbol...)
  322. }
  323. return string(b)
  324. }
  325. // FmtDateShort returns the short date representation of 't' for 'hu'
  326. func (hu *hu) FmtDateShort(t time.Time) string {
  327. b := make([]byte, 0, 32)
  328. b = strconv.AppendInt(b, int64(t.Year()), 10)
  329. b = append(b, []byte{0x2e, 0x20}...)
  330. if t.Month() < 10 {
  331. b = append(b, '0')
  332. }
  333. b = strconv.AppendInt(b, int64(t.Month()), 10)
  334. b = append(b, []byte{0x2e, 0x20}...)
  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{0x2e}...)
  340. return string(b)
  341. }
  342. // FmtDateMedium returns the medium date representation of 't' for 'hu'
  343. func (hu *hu) FmtDateMedium(t time.Time) string {
  344. b := make([]byte, 0, 32)
  345. b = strconv.AppendInt(b, int64(t.Year()), 10)
  346. b = append(b, []byte{0x2e, 0x20}...)
  347. b = append(b, hu.monthsAbbreviated[t.Month()]...)
  348. b = append(b, []byte{0x20}...)
  349. b = strconv.AppendInt(b, int64(t.Day()), 10)
  350. b = append(b, []byte{0x2e}...)
  351. return string(b)
  352. }
  353. // FmtDateLong returns the long date representation of 't' for 'hu'
  354. func (hu *hu) FmtDateLong(t time.Time) string {
  355. b := make([]byte, 0, 32)
  356. b = strconv.AppendInt(b, int64(t.Year()), 10)
  357. b = append(b, []byte{0x2e, 0x20}...)
  358. b = append(b, hu.monthsWide[t.Month()]...)
  359. b = append(b, []byte{0x20}...)
  360. b = strconv.AppendInt(b, int64(t.Day()), 10)
  361. b = append(b, []byte{0x2e}...)
  362. return string(b)
  363. }
  364. // FmtDateFull returns the full date representation of 't' for 'hu'
  365. func (hu *hu) FmtDateFull(t time.Time) string {
  366. b := make([]byte, 0, 32)
  367. b = strconv.AppendInt(b, int64(t.Year()), 10)
  368. b = append(b, []byte{0x2e, 0x20}...)
  369. b = append(b, hu.monthsWide[t.Month()]...)
  370. b = append(b, []byte{0x20}...)
  371. b = strconv.AppendInt(b, int64(t.Day()), 10)
  372. b = append(b, []byte{0x2e, 0x2c, 0x20}...)
  373. b = append(b, hu.daysWide[t.Weekday()]...)
  374. return string(b)
  375. }
  376. // FmtTimeShort returns the short time representation of 't' for 'hu'
  377. func (hu *hu) FmtTimeShort(t time.Time) string {
  378. b := make([]byte, 0, 32)
  379. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  380. b = append(b, hu.timeSeparator...)
  381. if t.Minute() < 10 {
  382. b = append(b, '0')
  383. }
  384. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  385. return string(b)
  386. }
  387. // FmtTimeMedium returns the medium time representation of 't' for 'hu'
  388. func (hu *hu) FmtTimeMedium(t time.Time) string {
  389. b := make([]byte, 0, 32)
  390. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  391. b = append(b, hu.timeSeparator...)
  392. if t.Minute() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  396. b = append(b, hu.timeSeparator...)
  397. if t.Second() < 10 {
  398. b = append(b, '0')
  399. }
  400. b = strconv.AppendInt(b, int64(t.Second()), 10)
  401. return string(b)
  402. }
  403. // FmtTimeLong returns the long time representation of 't' for 'hu'
  404. func (hu *hu) FmtTimeLong(t time.Time) string {
  405. b := make([]byte, 0, 32)
  406. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  407. b = append(b, hu.timeSeparator...)
  408. if t.Minute() < 10 {
  409. b = append(b, '0')
  410. }
  411. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  412. b = append(b, hu.timeSeparator...)
  413. if t.Second() < 10 {
  414. b = append(b, '0')
  415. }
  416. b = strconv.AppendInt(b, int64(t.Second()), 10)
  417. b = append(b, []byte{0x20}...)
  418. tz, _ := t.Zone()
  419. b = append(b, tz...)
  420. return string(b)
  421. }
  422. // FmtTimeFull returns the full time representation of 't' for 'hu'
  423. func (hu *hu) FmtTimeFull(t time.Time) string {
  424. b := make([]byte, 0, 32)
  425. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  426. b = append(b, hu.timeSeparator...)
  427. if t.Minute() < 10 {
  428. b = append(b, '0')
  429. }
  430. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  431. b = append(b, hu.timeSeparator...)
  432. if t.Second() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Second()), 10)
  436. b = append(b, []byte{0x20}...)
  437. tz, _ := t.Zone()
  438. if btz, ok := hu.timezones[tz]; ok {
  439. b = append(b, btz...)
  440. } else {
  441. b = append(b, tz...)
  442. }
  443. return string(b)
  444. }