hy.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. package hy
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type hy 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. 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 'hy' locale
  41. func New() locales.Translator {
  42. return &hy{
  43. locale: "hy",
  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", "֏", "ANG", "AOA", "AOK ", "AON ", "AOR ", "ARA ", "ARL ", "ARM ", "ARP ", "ARS", "ATS ", "A$", "AWG", "AZM ", "AZN", "BAD ", "BAM", "BAN ", "BBD", "BDT", "BEC ", "BEF ", "BEL ", "BGL ", "BGM ", "BGN", "BGO ", "BHD", "BIF", "BMD", "BND", "BOB", "BOL ", "BOP ", "BOV ", "BRB ", "BRC ", "BRE ", "R$", "BRN ", "BRR ", "BRZ ", "BSD", "BTN", "BUK ", "BWP", "BYB ", "BYR", "BZD", "CA$", "CDF", "CHE ", "CHF", "CHW ", "CLE ", "CLF ", "CLP", "CNX ", "CN¥", "COP", "COU ", "CRC", "CSD ", "CSK ", "CUC", "CUP", "CVE", "CYP ", "CZK", "DDM ", "DEM ", "DJF", "DKK", "DOP", "DZD", "ECS ", "ECV ", "EEK ", "EGP", "ERN", "ESA ", "ESB ", "ESP ", "ETB", "€", "FIM ", "FJD", "FKP", "FRF ", "£", "GEK ", "GEL", "GHC ", "GHS", "GIP", "GMD", "GNF", "GNS ", "GQE ", "GRD ", "GTQ", "GWE ", "GWP ", "GYD", "HK$", "HNL", "HRD ", "HRK", "HTG", "HUF", "IDR", "IEP ", "ILP ", "ILR ", "₪", "₹", "IQD", "IRR", "ISJ ", "ISK", "ITL ", "JMD", "JOD", "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", "SBD", "SCR", "SDD ", "SDG", "SDP ", "SEK", "SGD", "SHP", "SIT ", "SKK ", "SLL", "SOS", "SRD", "SRG ", "SSP", "STD", "SUR ", "SVC ", "SYP", "SZL", "฿", "TJR ", "TJS", "TMM ", "TMT", "TND", "TOP", "TPE ", "TRL ", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK ", "UGS ", "UGX", "$", "USN ", "USS ", "UYI ", "UYP ", "UYU", "UZS", "VEB ", "VEF", "₫", "VNN ", "VUV", "WST", "FCFA", "XAG ", "XAU ", "XBA ", "XBB ", "XBC ", "XBD ", "EC$", "XDR ", "XEU ", "XFO ", "XFU ", "CFA", "XPD ", "CFPF", "XPT ", "XRE ", "XSU ", "XTS ", "XUA ", "XXX ", "YDD ", "YER", "YUD ", "YUM ", "YUN ", "YUR ", "ZAL ", "ZAR", "ZMK ", "ZMW", "ZRN ", "ZRZ ", "ZWD ", "ZWL ", "ZWR "},
  55. currencyPositivePrefix: " ",
  56. currencyNegativePrefix: " ",
  57. monthsAbbreviated: []string{"", "հնվ", "փտվ", "մրտ", "ապր", "մյս", "հնս", "հլս", "օգս", "սեպ", "հոկ", "նոյ", "դեկ"},
  58. monthsNarrow: []string{"", "Հ", "Փ", "Մ", "Ա", "Մ", "Հ", "Հ", "Օ", "Ս", "Հ", "Ն", "Դ"},
  59. monthsWide: []string{"", "հունվարի", "փետրվարի", "մարտի", "ապրիլի", "մայիսի", "հունիսի", "հուլիսի", "օգոստոսի", "սեպտեմբերի", "հոկտեմբերի", "նոյեմբերի", "դեկտեմբերի"},
  60. daysAbbreviated: []string{"կիր", "երկ", "երք", "չրք", "հնգ", "ուր", "շբթ"},
  61. daysNarrow: []string{"Կ", "Ե", "Ե", "Չ", "Հ", "Ու", "Շ"},
  62. daysShort: []string{"կիր", "երկ", "երք", "չրք", "հնգ", "ուր", "շբթ"},
  63. daysWide: []string{"կիրակի", "երկուշաբթի", "երեքշաբթի", "չորեքշաբթի", "հինգշաբթի", "ուրբաթ", "շաբաթ"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"a", "p"},
  66. periodsWide: []string{"AM", "PM"},
  67. erasAbbreviated: []string{"", ""},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"մ.թ.ա.", "մ.թ."},
  70. timezones: map[string]string{"BT": "Բութանի ժամանակ", "IST": "Հնդկաստանի ստանդարտ ժամանակ", "MDT": "MDT", "SAST": "Հարավաֆրիկյան ժամանակ", "ARST": "Արգենտինայի ամառային ժամանակ", "WEZ": "Արևմտյան Եվրոպայի ստանդարտ ժամանակ", "WAST": "Արևմտաաֆրիկյան ամառային ժամանակ", "JDT": "Ճապոնիայի ամառային ժամանակ", "SGT": "Սինգապուրի ժամանակ", "HKST": "Հոնկոնգի ամառային ժամանակ", "WAT": "Արևմտաաֆրիկյան ստանդարտ ժամանակ", "GYT": "Գայանայի ժամանակ", "CDT": "Կենտրոնական Ամերիկայի ամառային ժամանակ", "WIB": "Արևմտյան Ինդոնեզիայի ժամանակ", "AWST": "Արևմտաավստրալիական ստանդարտ ժամանակ", "CST": "Կենտրոնական Ամերիկայի ստանդարտ ժամանակ", "AKST": "Ալյասկայի ստանդարտ ժամանակ", "AEDT": "Արևելաավստրալիական ամառային ժամանակ", "CHAST": "Չաթեմ կղզու ստանդարտ ժամանակ", "HAST": "Հավայան-ալեուտյան ստանդարտ ժամանակ", "ACST": "Կենտրոնաավստրալիական ստանդարտ ժամանակ", "MST": "MST", "LHST": "Լորդ Հաուի ստանդարտ ժամանակ", "JST": "Ճապոնիայի ստանդարտ ժամանակ", "HKT": "Հոնկոնգի ստանդարտ ժամանակ", "GMT": "Գրինվիչի ժամանակ", "HAT": "Նյուֆաունդլենդի ամառային ժամանակ", "ADT": "Ատլանտյան ամառային ժամանակ", "CAT": "Կենտրոնաաֆրիկյան ժամանակ", "AST": "Ատլանտյան ստանդարտ ժամանակ", "OEZ": "Արևելյան Եվրոպայի ստանդարտ ժամանակ", "MYT": "Մալայզիայի ժամանակ", "PST": "Խաղաղօվկիանոսային ստանդարտ ժամանակ (Հյուսիսային Ամերիկա)", "PDT": "Խաղաղօվկիանոսային ամառային ժամանակ (Հյուսիսային Ամերիկա)", "SRT": "Սուրինամի ժամանակ", "BOT": "Բոլիվիայի ժամանակ", "ChST": "Չամորոյի ժամանակ", "ACWDT": "Կենտրոնաավստրալիական արևմտյան ամառային ժամանակ", "ACWST": "Կենտրոնաավստրալիական արևմտյան ստանդարտ ժամանակ", "HNT": "Նյուֆաունդլենդի ստանդարտ ժամանակ", "ART": "Արգենտինայի ստնադարտ ժամանակ", "MESZ": "Կենտրոնական Եվրոպայի ամառային ժամանակ", "CLT": "Չիլիի ստանդարտ ժամանակ", "COT": "Կոլումբիայի ստանդարտ ժամանակ", "GFT": "Ֆրանսիական Գվիանայի ժամանակ", "∅∅∅": "Ամազոնյան ամառային ժամանակ", "CHADT": "Չաթեմ կղզու ամառային ժամանակ", "WESZ": "Արևմտյան Եվրոպայի ամառային ժամանակ", "EAT": "Արևելաաֆրիկյան ժամանակ", "EST": "Արևելյան Ամերիկայի ստանդարտ ժամանակ", "EDT": "Արևելյան Ամերիկայի ամառային ժամանակ", "AEST": "Արևելաավստրալիական ստանդարտ ժամանակ", "CLST": "Չիլիի ամառային ժամանակ", "WARST": "Արևմտյան Արգենտինայի ամառային ժամանակ", "OESZ": "Արևելյան Եվրոպայի ամառային ժամանակ", "ACDT": "Կենտրոնաավստրալիական ամառային ժամանակ", "TMT": "Թուրքմենստանի ստանդարտ ժամանակ", "ECT": "Էկվադորի ժամանակ", "HADT": "Հավայան-ալեուտյան ամառային ժամանակ", "WITA": "Կենտրոնական Ինդոնեզիայի ժամանակ", "LHDT": "Լորդ Հաուի ամառային ժամանակ", "UYT": "Ուրուգվայի ստանդարտ ժամանակ", "MEZ": "Կենտրոնական Եվրոպայի ստանդարտ ժամանակ", "UYST": "Ուրուգվայի ամառային ժամանակ", "VET": "Վենեսուելայի ժամանակ", "WART": "Արևմտյան Արգենտինայի ստնադարտ ժամանակ", "WIT": "Արևելյան Ինդոնեզիայի ժամանակ", "AWDT": "Արևմտաավստրալիական ամառային ժամանակ", "AKDT": "Ալյասկայի ամառային ժամանակ", "TMST": "Թուրքմենստանի ամառային ժամանակ", "NZST": "Նոր Զելանդիայի ստանդարտ ժամանակ", "NZDT": "Նոր Զելանդիայի ամառային ժամանակ", "COST": "Կոլումբիայի ամառային ժամանակ"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (hy *hy) Locale() string {
  75. return hy.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'hy'
  78. func (hy *hy) PluralsCardinal() []locales.PluralRule {
  79. return hy.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'hy'
  82. func (hy *hy) PluralsOrdinal() []locales.PluralRule {
  83. return hy.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'hy'
  86. func (hy *hy) PluralsRange() []locales.PluralRule {
  87. return hy.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'hy'
  90. func (hy *hy) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. if i == 0 || i == 1 {
  94. return locales.PluralRuleOne
  95. }
  96. return locales.PluralRuleOther
  97. }
  98. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'hy'
  99. func (hy *hy) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  100. n := math.Abs(num)
  101. if n == 1 {
  102. return locales.PluralRuleOne
  103. }
  104. return locales.PluralRuleOther
  105. }
  106. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'hy'
  107. func (hy *hy) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  108. start := hy.CardinalPluralRule(num1, v1)
  109. end := hy.CardinalPluralRule(num2, v2)
  110. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  111. return locales.PluralRuleOne
  112. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  113. return locales.PluralRuleOther
  114. }
  115. return locales.PluralRuleOther
  116. }
  117. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  118. func (hy *hy) MonthAbbreviated(month time.Month) string {
  119. return hy.monthsAbbreviated[month]
  120. }
  121. // MonthsAbbreviated returns the locales abbreviated months
  122. func (hy *hy) MonthsAbbreviated() []string {
  123. return hy.monthsAbbreviated[1:]
  124. }
  125. // MonthNarrow returns the locales narrow month given the 'month' provided
  126. func (hy *hy) MonthNarrow(month time.Month) string {
  127. return hy.monthsNarrow[month]
  128. }
  129. // MonthsNarrow returns the locales narrow months
  130. func (hy *hy) MonthsNarrow() []string {
  131. return hy.monthsNarrow[1:]
  132. }
  133. // MonthWide returns the locales wide month given the 'month' provided
  134. func (hy *hy) MonthWide(month time.Month) string {
  135. return hy.monthsWide[month]
  136. }
  137. // MonthsWide returns the locales wide months
  138. func (hy *hy) MonthsWide() []string {
  139. return hy.monthsWide[1:]
  140. }
  141. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  142. func (hy *hy) WeekdayAbbreviated(weekday time.Weekday) string {
  143. return hy.daysAbbreviated[weekday]
  144. }
  145. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  146. func (hy *hy) WeekdaysAbbreviated() []string {
  147. return hy.daysAbbreviated
  148. }
  149. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  150. func (hy *hy) WeekdayNarrow(weekday time.Weekday) string {
  151. return hy.daysNarrow[weekday]
  152. }
  153. // WeekdaysNarrow returns the locales narrow weekdays
  154. func (hy *hy) WeekdaysNarrow() []string {
  155. return hy.daysNarrow
  156. }
  157. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  158. func (hy *hy) WeekdayShort(weekday time.Weekday) string {
  159. return hy.daysShort[weekday]
  160. }
  161. // WeekdaysShort returns the locales short weekdays
  162. func (hy *hy) WeekdaysShort() []string {
  163. return hy.daysShort
  164. }
  165. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  166. func (hy *hy) WeekdayWide(weekday time.Weekday) string {
  167. return hy.daysWide[weekday]
  168. }
  169. // WeekdaysWide returns the locales wide weekdays
  170. func (hy *hy) WeekdaysWide() []string {
  171. return hy.daysWide
  172. }
  173. // FmtNumber returns 'num' with digits/precision of 'v' for 'hy' and handles both Whole and Real numbers based on 'v'
  174. func (hy *hy) FmtNumber(num float64, v uint64) string {
  175. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  176. l := len(s) + 2
  177. b := make([]byte, 0, l)
  178. for i := len(s) - 1; i >= 0; i-- {
  179. if s[i] == '.' {
  180. b = append(b, hy.decimal[0])
  181. continue
  182. }
  183. b = append(b, s[i])
  184. }
  185. if num < 0 {
  186. b = append(b, hy.minus[0])
  187. }
  188. // reverse
  189. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  190. b[i], b[j] = b[j], b[i]
  191. }
  192. return string(b)
  193. }
  194. // FmtPercent returns 'num' with digits/precision of 'v' for 'hy' and handles both Whole and Real numbers based on 'v'
  195. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  196. func (hy *hy) FmtPercent(num float64, v uint64) string {
  197. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  198. l := len(s) + 3
  199. b := make([]byte, 0, l)
  200. for i := len(s) - 1; i >= 0; i-- {
  201. if s[i] == '.' {
  202. b = append(b, hy.decimal[0])
  203. continue
  204. }
  205. b = append(b, s[i])
  206. }
  207. if num < 0 {
  208. b = append(b, hy.minus[0])
  209. }
  210. // reverse
  211. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  212. b[i], b[j] = b[j], b[i]
  213. }
  214. b = append(b, hy.percent...)
  215. return string(b)
  216. }
  217. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'hy'
  218. func (hy *hy) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  219. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  220. symbol := hy.currencies[currency]
  221. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  222. count := 0
  223. inWhole := v == 0
  224. b := make([]byte, 0, l)
  225. for i := len(s) - 1; i >= 0; i-- {
  226. if s[i] == '.' {
  227. b = append(b, hy.decimal[0])
  228. inWhole = true
  229. continue
  230. }
  231. if inWhole {
  232. if count == 3 {
  233. b = append(b, hy.group[0])
  234. count = 1
  235. } else {
  236. count++
  237. }
  238. }
  239. b = append(b, s[i])
  240. }
  241. for j := len(symbol) - 1; j >= 0; j-- {
  242. b = append(b, symbol[j])
  243. }
  244. for j := len(hy.currencyPositivePrefix) - 1; j >= 0; j-- {
  245. b = append(b, hy.currencyPositivePrefix[j])
  246. }
  247. if num < 0 {
  248. b = append(b, hy.minus[0])
  249. }
  250. // reverse
  251. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  252. b[i], b[j] = b[j], b[i]
  253. }
  254. if int(v) < 2 {
  255. if v == 0 {
  256. b = append(b, hy.decimal...)
  257. }
  258. for i := 0; i < 2-int(v); i++ {
  259. b = append(b, '0')
  260. }
  261. }
  262. return string(b)
  263. }
  264. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'hy'
  265. // in accounting notation.
  266. func (hy *hy) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  267. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  268. symbol := hy.currencies[currency]
  269. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  270. count := 0
  271. inWhole := v == 0
  272. b := make([]byte, 0, l)
  273. for i := len(s) - 1; i >= 0; i-- {
  274. if s[i] == '.' {
  275. b = append(b, hy.decimal[0])
  276. inWhole = true
  277. continue
  278. }
  279. if inWhole {
  280. if count == 3 {
  281. b = append(b, hy.group[0])
  282. count = 1
  283. } else {
  284. count++
  285. }
  286. }
  287. b = append(b, s[i])
  288. }
  289. if num < 0 {
  290. for j := len(symbol) - 1; j >= 0; j-- {
  291. b = append(b, symbol[j])
  292. }
  293. for j := len(hy.currencyNegativePrefix) - 1; j >= 0; j-- {
  294. b = append(b, hy.currencyNegativePrefix[j])
  295. }
  296. b = append(b, hy.minus[0])
  297. } else {
  298. for j := len(symbol) - 1; j >= 0; j-- {
  299. b = append(b, symbol[j])
  300. }
  301. for j := len(hy.currencyPositivePrefix) - 1; j >= 0; j-- {
  302. b = append(b, hy.currencyPositivePrefix[j])
  303. }
  304. }
  305. // reverse
  306. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  307. b[i], b[j] = b[j], b[i]
  308. }
  309. if int(v) < 2 {
  310. if v == 0 {
  311. b = append(b, hy.decimal...)
  312. }
  313. for i := 0; i < 2-int(v); i++ {
  314. b = append(b, '0')
  315. }
  316. }
  317. return string(b)
  318. }
  319. // FmtDateShort returns the short date representation of 't' for 'hy'
  320. func (hy *hy) FmtDateShort(t time.Time) string {
  321. b := make([]byte, 0, 32)
  322. if t.Day() < 10 {
  323. b = append(b, '0')
  324. }
  325. b = strconv.AppendInt(b, int64(t.Day()), 10)
  326. b = append(b, []byte{0x2e}...)
  327. if t.Month() < 10 {
  328. b = append(b, '0')
  329. }
  330. b = strconv.AppendInt(b, int64(t.Month()), 10)
  331. b = append(b, []byte{0x2e}...)
  332. if t.Year() > 9 {
  333. b = append(b, strconv.Itoa(t.Year())[2:]...)
  334. } else {
  335. b = append(b, strconv.Itoa(t.Year())[1:]...)
  336. }
  337. return string(b)
  338. }
  339. // FmtDateMedium returns the medium date representation of 't' for 'hy'
  340. func (hy *hy) FmtDateMedium(t time.Time) string {
  341. b := make([]byte, 0, 32)
  342. if t.Day() < 10 {
  343. b = append(b, '0')
  344. }
  345. b = strconv.AppendInt(b, int64(t.Day()), 10)
  346. b = append(b, []byte{0x20}...)
  347. b = append(b, hy.monthsAbbreviated[t.Month()]...)
  348. b = append(b, []byte{0x2c, 0x20}...)
  349. b = strconv.AppendInt(b, int64(t.Year()), 10)
  350. b = append(b, []byte{0xd5, 0xa9, 0x2e}...)
  351. return string(b)
  352. }
  353. // FmtDateLong returns the long date representation of 't' for 'hy'
  354. func (hy *hy) FmtDateLong(t time.Time) string {
  355. b := make([]byte, 0, 32)
  356. if t.Day() < 10 {
  357. b = append(b, '0')
  358. }
  359. b = strconv.AppendInt(b, int64(t.Day()), 10)
  360. b = append(b, []byte{0x20}...)
  361. b = append(b, hy.monthsWide[t.Month()]...)
  362. b = append(b, []byte{0x2c, 0x20}...)
  363. b = strconv.AppendInt(b, int64(t.Year()), 10)
  364. b = append(b, []byte{0xd5, 0xa9, 0x2e}...)
  365. return string(b)
  366. }
  367. // FmtDateFull returns the full date representation of 't' for 'hy'
  368. func (hy *hy) FmtDateFull(t time.Time) string {
  369. b := make([]byte, 0, 32)
  370. b = strconv.AppendInt(b, int64(t.Year()), 10)
  371. b = append(b, []byte{0xd5, 0xa9, 0x2e, 0x20}...)
  372. b = append(b, hy.monthsWide[t.Month()]...)
  373. b = append(b, []byte{0x20}...)
  374. b = strconv.AppendInt(b, int64(t.Day()), 10)
  375. b = append(b, []byte{0x2c, 0x20}...)
  376. b = append(b, hy.daysWide[t.Weekday()]...)
  377. return string(b)
  378. }
  379. // FmtTimeShort returns the short time representation of 't' for 'hy'
  380. func (hy *hy) FmtTimeShort(t time.Time) string {
  381. b := make([]byte, 0, 32)
  382. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  383. b = append(b, hy.timeSeparator...)
  384. if t.Minute() < 10 {
  385. b = append(b, '0')
  386. }
  387. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  388. return string(b)
  389. }
  390. // FmtTimeMedium returns the medium time representation of 't' for 'hy'
  391. func (hy *hy) FmtTimeMedium(t time.Time) string {
  392. b := make([]byte, 0, 32)
  393. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  394. b = append(b, hy.timeSeparator...)
  395. if t.Minute() < 10 {
  396. b = append(b, '0')
  397. }
  398. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  399. b = append(b, hy.timeSeparator...)
  400. if t.Second() < 10 {
  401. b = append(b, '0')
  402. }
  403. b = strconv.AppendInt(b, int64(t.Second()), 10)
  404. return string(b)
  405. }
  406. // FmtTimeLong returns the long time representation of 't' for 'hy'
  407. func (hy *hy) FmtTimeLong(t time.Time) string {
  408. b := make([]byte, 0, 32)
  409. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  410. b = append(b, hy.timeSeparator...)
  411. if t.Minute() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  415. b = append(b, hy.timeSeparator...)
  416. if t.Second() < 10 {
  417. b = append(b, '0')
  418. }
  419. b = strconv.AppendInt(b, int64(t.Second()), 10)
  420. b = append(b, []byte{0x2c, 0x20}...)
  421. tz, _ := t.Zone()
  422. b = append(b, tz...)
  423. return string(b)
  424. }
  425. // FmtTimeFull returns the full time representation of 't' for 'hy'
  426. func (hy *hy) FmtTimeFull(t time.Time) string {
  427. b := make([]byte, 0, 32)
  428. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  429. b = append(b, hy.timeSeparator...)
  430. if t.Minute() < 10 {
  431. b = append(b, '0')
  432. }
  433. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  434. b = append(b, hy.timeSeparator...)
  435. if t.Second() < 10 {
  436. b = append(b, '0')
  437. }
  438. b = strconv.AppendInt(b, int64(t.Second()), 10)
  439. b = append(b, []byte{0x2c, 0x20}...)
  440. tz, _ := t.Zone()
  441. if btz, ok := hy.timezones[tz]; ok {
  442. b = append(b, btz...)
  443. } else {
  444. b = append(b, tz...)
  445. }
  446. return string(b)
  447. }