he.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. package he
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type he 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 'he' locale
  41. func New() locales.Translator {
  42. return &he{
  43. locale: "he",
  44. pluralsCardinal: []locales.PluralRule{2, 3, 5, 6},
  45. pluralsOrdinal: []locales.PluralRule{6},
  46. pluralsRange: []locales.PluralRule{6, 5},
  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 ", "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 ", "ל״י", "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. currencyPositiveSuffix: " ",
  56. currencyNegativeSuffix: " ",
  57. monthsAbbreviated: []string{"", "ינו׳", "פבר׳", "מרץ", "אפר׳", "מאי", "יוני", "יולי", "אוג׳", "ספט׳", "אוק׳", "נוב׳", "דצמ׳"},
  58. monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  59. monthsWide: []string{"", "ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני", "יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר"},
  60. daysAbbreviated: []string{"יום א׳", "יום ב׳", "יום ג׳", "יום ד׳", "יום ה׳", "יום ו׳", "שבת"},
  61. daysNarrow: []string{"א׳", "ב׳", "ג׳", "ד׳", "ה׳", "ו׳", "ש׳"},
  62. daysShort: []string{"א׳", "ב׳", "ג׳", "ד׳", "ה׳", "ו׳", "ש׳"},
  63. daysWide: []string{"יום ראשון", "יום שני", "יום שלישי", "יום רביעי", "יום חמישי", "יום שישי", "יום שבת"},
  64. periodsAbbreviated: []string{"לפנה״צ", "אחה״צ"},
  65. periodsWide: []string{"לפנה״צ", "אחה״צ"},
  66. erasAbbreviated: []string{"לפנה״ס", "לספירה"},
  67. erasNarrow: []string{"", ""},
  68. erasWide: []string{"", ""},
  69. timezones: map[string]string{"COT": "שעון קולומביה (חורף)", "COST": "שעון קולומביה (קיץ)", "WARST": "שעון מערב ארגנטינה (קיץ)", "GYT": "שעון גויאנה", "UYST": "שעון אורוגוואי (קיץ)", "AEDT": "שעון מזרח אוסטרליה (קיץ)", "∅∅∅": "שעון ברזיליה (קיץ)", "EST": "שעון החוף המזרחי (חורף)", "ADT": "שעון האוקיינוס האטלנטי (קיץ)", "WITA": "שעון מרכז אינדונזיה", "NZST": "שעון ניו זילנד (חורף)", "NZDT": "שעון ניו זילנד (קיץ)", "AKST": "שעון אלסקה (חורף)", "ChST": "שעון צ׳אמורו", "CLT": "שעון צ׳ילה (חורף)", "WAT": "שעון מערב אפריקה (חורף)", "WAST": "שעון מערב אפריקה (קיץ)", "TMT": "שעון טורקמניסטן (חורף)", "SRT": "שעון סורינאם", "WESZ": "שעון מערב אירופה (קיץ)", "CAT": "שעון מרכז אפריקה", "LHDT": "שעון אי הלורד האו (קיץ)", "EDT": "שעון החוף המזרחי (קיץ)", "IST": "שעון הודו", "HKT": "שעון הונג קונג (חורף)", "OEZ": "שעון מזרח אירופה (חורף)", "PST": "שעון רגיל האוקיינוס השקט", "MESZ": "שעון מרכז אירופה (קיץ)", "SGT": "שעון סינגפור", "EAT": "שעון מזרח אפריקה", "JDT": "שעון יפן (קיץ)", "WEZ": "שעון מערב אירופה (חורף)", "HKST": "שעון הונג קונג (קיץ)", "CLST": "שעון צ׳ילה (קיץ)", "AST": "שעון האוקיינוס האטלנטי (חורף)", "HAST": "שעון רגיל האיים האלאוטיים הוואי", "ARST": "שעון ארגנטינה (קיץ)", "UYT": "שעון אורוגוואי (חורף)", "CHAST": "שעון צ׳טהאם (חורף)", "ACST": "שעון מרכז אוסטרליה (חורף)", "JST": "שעון יפן (חורף)", "ACWST": "שעון מרכז-מערב אוסטרליה (חורף)", "LHST": "שעון אי הלורד האו (חורף)", "HAT": "שעון ניופאונדלנד (קיץ)", "TMST": "שעון טורקמניסטן (קיץ)", "MYT": "שעון מלזיה", "MEZ": "שעון מרכז אירופה (חורף)", "CHADT": "שעון צ׳טהאם (קיץ)", "ART": "שעון ארגנטינה (חורף)", "VET": "שעון ונצואלה", "BT": "שעון בהוטן", "WART": "שעון מערב ארגנטינה (חורף)", "SAST": "שעון דרום אפריקה", "GMT": "שעון גריניץ׳\u200f", "WIB": "שעון מערב אינדונזיה", "CDT": "שעון מרכז ארה״ב (קיץ)", "AEST": "שעון מזרח אוסטרליה (חורף)", "WIT": "שעון מזרח אינדונזיה", "AWDT": "שעון מערב אוסטרליה (קיץ)", "AKDT": "שעון אלסקה (קיץ)", "ECT": "שעון אקוודור", "GFT": "שעון גיאנה הצרפתית", "MST": "שעון אזור ההרים בארה״ב (חורף)", "MDT": "שעון אזור ההרים בארה״ב (קיץ)", "HNT": "שעון ניופאונדלנד (חורף)", "OESZ": "שעון מזרח אירופה (קיץ)", "AWST": "שעון מערב אוסטרליה (חורף)", "PDT": "שעון קיץ, מערב ארה״ב (לוס אנג׳לס)", "BOT": "שעון בוליביה", "CST": "שעון מרכז ארה״ב (חורף)", "ACDT": "שעון מרכז אוסטרליה (קיץ)", "ACWDT": "שעון מרכז-מערב אוסטרליה (קיץ)", "HADT": "שעון קיץ האיים האלאוטיים הוואי"},
  70. }
  71. }
  72. // Locale returns the current translators string locale
  73. func (he *he) Locale() string {
  74. return he.locale
  75. }
  76. // PluralsCardinal returns the list of cardinal plural rules associated with 'he'
  77. func (he *he) PluralsCardinal() []locales.PluralRule {
  78. return he.pluralsCardinal
  79. }
  80. // PluralsOrdinal returns the list of ordinal plural rules associated with 'he'
  81. func (he *he) PluralsOrdinal() []locales.PluralRule {
  82. return he.pluralsOrdinal
  83. }
  84. // PluralsRange returns the list of range plural rules associated with 'he'
  85. func (he *he) PluralsRange() []locales.PluralRule {
  86. return he.pluralsRange
  87. }
  88. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'he'
  89. func (he *he) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  90. n := math.Abs(num)
  91. i := int64(n)
  92. nMod10 := math.Mod(n, 10)
  93. if i == 1 && v == 0 {
  94. return locales.PluralRuleOne
  95. } else if i == 2 && v == 0 {
  96. return locales.PluralRuleTwo
  97. } else if v == 0 && n < 0 && n > 10 && nMod10 == 0 {
  98. return locales.PluralRuleMany
  99. }
  100. return locales.PluralRuleOther
  101. }
  102. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'he'
  103. func (he *he) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  104. return locales.PluralRuleOther
  105. }
  106. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'he'
  107. func (he *he) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  108. start := he.CardinalPluralRule(num1, v1)
  109. end := he.CardinalPluralRule(num2, v2)
  110. if start == locales.PluralRuleOne && end == locales.PluralRuleTwo {
  111. return locales.PluralRuleOther
  112. } else if start == locales.PluralRuleOne && end == locales.PluralRuleMany {
  113. return locales.PluralRuleMany
  114. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  115. return locales.PluralRuleOther
  116. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleMany {
  117. return locales.PluralRuleOther
  118. } else if start == locales.PluralRuleTwo && end == locales.PluralRuleOther {
  119. return locales.PluralRuleOther
  120. } else if start == locales.PluralRuleMany && end == locales.PluralRuleMany {
  121. return locales.PluralRuleMany
  122. } else if start == locales.PluralRuleMany && end == locales.PluralRuleOther {
  123. return locales.PluralRuleMany
  124. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  125. return locales.PluralRuleOther
  126. } else if start == locales.PluralRuleOther && end == locales.PluralRuleTwo {
  127. return locales.PluralRuleOther
  128. } else if start == locales.PluralRuleOther && end == locales.PluralRuleMany {
  129. return locales.PluralRuleMany
  130. }
  131. return locales.PluralRuleOther
  132. }
  133. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  134. func (he *he) MonthAbbreviated(month time.Month) string {
  135. return he.monthsAbbreviated[month]
  136. }
  137. // MonthsAbbreviated returns the locales abbreviated months
  138. func (he *he) MonthsAbbreviated() []string {
  139. return he.monthsAbbreviated[1:]
  140. }
  141. // MonthNarrow returns the locales narrow month given the 'month' provided
  142. func (he *he) MonthNarrow(month time.Month) string {
  143. return he.monthsNarrow[month]
  144. }
  145. // MonthsNarrow returns the locales narrow months
  146. func (he *he) MonthsNarrow() []string {
  147. return he.monthsNarrow[1:]
  148. }
  149. // MonthWide returns the locales wide month given the 'month' provided
  150. func (he *he) MonthWide(month time.Month) string {
  151. return he.monthsWide[month]
  152. }
  153. // MonthsWide returns the locales wide months
  154. func (he *he) MonthsWide() []string {
  155. return he.monthsWide[1:]
  156. }
  157. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  158. func (he *he) WeekdayAbbreviated(weekday time.Weekday) string {
  159. return he.daysAbbreviated[weekday]
  160. }
  161. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  162. func (he *he) WeekdaysAbbreviated() []string {
  163. return he.daysAbbreviated
  164. }
  165. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  166. func (he *he) WeekdayNarrow(weekday time.Weekday) string {
  167. return he.daysNarrow[weekday]
  168. }
  169. // WeekdaysNarrow returns the locales narrow weekdays
  170. func (he *he) WeekdaysNarrow() []string {
  171. return he.daysNarrow
  172. }
  173. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  174. func (he *he) WeekdayShort(weekday time.Weekday) string {
  175. return he.daysShort[weekday]
  176. }
  177. // WeekdaysShort returns the locales short weekdays
  178. func (he *he) WeekdaysShort() []string {
  179. return he.daysShort
  180. }
  181. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  182. func (he *he) WeekdayWide(weekday time.Weekday) string {
  183. return he.daysWide[weekday]
  184. }
  185. // WeekdaysWide returns the locales wide weekdays
  186. func (he *he) WeekdaysWide() []string {
  187. return he.daysWide
  188. }
  189. // FmtNumber returns 'num' with digits/precision of 'v' for 'he' and handles both Whole and Real numbers based on 'v'
  190. func (he *he) FmtNumber(num float64, v uint64) string {
  191. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  192. l := len(s) + 5 + 1*len(s[:len(s)-int(v)-1])/3
  193. count := 0
  194. inWhole := v == 0
  195. b := make([]byte, 0, l)
  196. for i := len(s) - 1; i >= 0; i-- {
  197. if s[i] == '.' {
  198. b = append(b, he.decimal[0])
  199. inWhole = true
  200. continue
  201. }
  202. if inWhole {
  203. if count == 3 {
  204. b = append(b, he.group[0])
  205. count = 1
  206. } else {
  207. count++
  208. }
  209. }
  210. b = append(b, s[i])
  211. }
  212. if num < 0 {
  213. for j := len(he.minus) - 1; j >= 0; j-- {
  214. b = append(b, he.minus[j])
  215. }
  216. }
  217. // reverse
  218. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  219. b[i], b[j] = b[j], b[i]
  220. }
  221. return string(b)
  222. }
  223. // FmtPercent returns 'num' with digits/precision of 'v' for 'he' and handles both Whole and Real numbers based on 'v'
  224. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  225. func (he *he) FmtPercent(num float64, v uint64) string {
  226. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  227. l := len(s) + 6
  228. b := make([]byte, 0, l)
  229. for i := len(s) - 1; i >= 0; i-- {
  230. if s[i] == '.' {
  231. b = append(b, he.decimal[0])
  232. continue
  233. }
  234. b = append(b, s[i])
  235. }
  236. if num < 0 {
  237. for j := len(he.minus) - 1; j >= 0; j-- {
  238. b = append(b, he.minus[j])
  239. }
  240. }
  241. // reverse
  242. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  243. b[i], b[j] = b[j], b[i]
  244. }
  245. b = append(b, he.percent...)
  246. return string(b)
  247. }
  248. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'he'
  249. func (he *he) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  250. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  251. symbol := he.currencies[currency]
  252. l := len(s) + len(symbol) + 7 + 1*len(s[:len(s)-int(v)-1])/3
  253. count := 0
  254. inWhole := v == 0
  255. b := make([]byte, 0, l)
  256. for i := len(s) - 1; i >= 0; i-- {
  257. if s[i] == '.' {
  258. b = append(b, he.decimal[0])
  259. inWhole = true
  260. continue
  261. }
  262. if inWhole {
  263. if count == 3 {
  264. b = append(b, he.group[0])
  265. count = 1
  266. } else {
  267. count++
  268. }
  269. }
  270. b = append(b, s[i])
  271. }
  272. if num < 0 {
  273. for j := len(he.minus) - 1; j >= 0; j-- {
  274. b = append(b, he.minus[j])
  275. }
  276. }
  277. // reverse
  278. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  279. b[i], b[j] = b[j], b[i]
  280. }
  281. if int(v) < 2 {
  282. if v == 0 {
  283. b = append(b, he.decimal...)
  284. }
  285. for i := 0; i < 2-int(v); i++ {
  286. b = append(b, '0')
  287. }
  288. }
  289. b = append(b, he.currencyPositiveSuffix...)
  290. b = append(b, symbol...)
  291. return string(b)
  292. }
  293. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'he'
  294. // in accounting notation.
  295. func (he *he) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  296. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  297. symbol := he.currencies[currency]
  298. l := len(s) + len(symbol) + 7 + 1*len(s[:len(s)-int(v)-1])/3
  299. count := 0
  300. inWhole := v == 0
  301. b := make([]byte, 0, l)
  302. for i := len(s) - 1; i >= 0; i-- {
  303. if s[i] == '.' {
  304. b = append(b, he.decimal[0])
  305. inWhole = true
  306. continue
  307. }
  308. if inWhole {
  309. if count == 3 {
  310. b = append(b, he.group[0])
  311. count = 1
  312. } else {
  313. count++
  314. }
  315. }
  316. b = append(b, s[i])
  317. }
  318. if num < 0 {
  319. for j := len(he.minus) - 1; j >= 0; j-- {
  320. b = append(b, he.minus[j])
  321. }
  322. }
  323. // reverse
  324. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  325. b[i], b[j] = b[j], b[i]
  326. }
  327. if int(v) < 2 {
  328. if v == 0 {
  329. b = append(b, he.decimal...)
  330. }
  331. for i := 0; i < 2-int(v); i++ {
  332. b = append(b, '0')
  333. }
  334. }
  335. if num < 0 {
  336. b = append(b, he.currencyNegativeSuffix...)
  337. b = append(b, symbol...)
  338. } else {
  339. b = append(b, he.currencyPositiveSuffix...)
  340. b = append(b, symbol...)
  341. }
  342. return string(b)
  343. }
  344. // FmtDateShort returns the short date representation of 't' for 'he'
  345. func (he *he) FmtDateShort(t time.Time) string {
  346. b := make([]byte, 0, 32)
  347. b = strconv.AppendInt(b, int64(t.Day()), 10)
  348. b = append(b, []byte{0x2e}...)
  349. b = strconv.AppendInt(b, int64(t.Month()), 10)
  350. b = append(b, []byte{0x2e}...)
  351. b = strconv.AppendInt(b, int64(t.Year()), 10)
  352. return string(b)
  353. }
  354. // FmtDateMedium returns the medium date representation of 't' for 'he'
  355. func (he *he) FmtDateMedium(t time.Time) string {
  356. b := make([]byte, 0, 32)
  357. b = strconv.AppendInt(b, int64(t.Day()), 10)
  358. b = append(b, []byte{0x20, 0xd7, 0x91}...)
  359. b = append(b, he.monthsAbbreviated[t.Month()]...)
  360. b = append(b, []byte{0x20}...)
  361. b = strconv.AppendInt(b, int64(t.Year()), 10)
  362. return string(b)
  363. }
  364. // FmtDateLong returns the long date representation of 't' for 'he'
  365. func (he *he) FmtDateLong(t time.Time) string {
  366. b := make([]byte, 0, 32)
  367. b = strconv.AppendInt(b, int64(t.Day()), 10)
  368. b = append(b, []byte{0x20, 0xd7, 0x91}...)
  369. b = append(b, he.monthsWide[t.Month()]...)
  370. b = append(b, []byte{0x20}...)
  371. b = strconv.AppendInt(b, int64(t.Year()), 10)
  372. return string(b)
  373. }
  374. // FmtDateFull returns the full date representation of 't' for 'he'
  375. func (he *he) FmtDateFull(t time.Time) string {
  376. b := make([]byte, 0, 32)
  377. b = append(b, he.daysWide[t.Weekday()]...)
  378. b = append(b, []byte{0x2c, 0x20}...)
  379. b = strconv.AppendInt(b, int64(t.Day()), 10)
  380. b = append(b, []byte{0x20, 0xd7, 0x91}...)
  381. b = append(b, he.monthsWide[t.Month()]...)
  382. b = append(b, []byte{0x20}...)
  383. b = strconv.AppendInt(b, int64(t.Year()), 10)
  384. return string(b)
  385. }
  386. // FmtTimeShort returns the short time representation of 't' for 'he'
  387. func (he *he) FmtTimeShort(t time.Time) string {
  388. b := make([]byte, 0, 32)
  389. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  390. b = append(b, he.timeSeparator...)
  391. if t.Minute() < 10 {
  392. b = append(b, '0')
  393. }
  394. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  395. return string(b)
  396. }
  397. // FmtTimeMedium returns the medium time representation of 't' for 'he'
  398. func (he *he) FmtTimeMedium(t time.Time) string {
  399. b := make([]byte, 0, 32)
  400. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  401. b = append(b, he.timeSeparator...)
  402. if t.Minute() < 10 {
  403. b = append(b, '0')
  404. }
  405. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  406. b = append(b, he.timeSeparator...)
  407. if t.Second() < 10 {
  408. b = append(b, '0')
  409. }
  410. b = strconv.AppendInt(b, int64(t.Second()), 10)
  411. return string(b)
  412. }
  413. // FmtTimeLong returns the long time representation of 't' for 'he'
  414. func (he *he) FmtTimeLong(t time.Time) string {
  415. b := make([]byte, 0, 32)
  416. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  417. b = append(b, he.timeSeparator...)
  418. if t.Minute() < 10 {
  419. b = append(b, '0')
  420. }
  421. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  422. b = append(b, he.timeSeparator...)
  423. if t.Second() < 10 {
  424. b = append(b, '0')
  425. }
  426. b = strconv.AppendInt(b, int64(t.Second()), 10)
  427. b = append(b, []byte{0x20}...)
  428. tz, _ := t.Zone()
  429. b = append(b, tz...)
  430. return string(b)
  431. }
  432. // FmtTimeFull returns the full time representation of 't' for 'he'
  433. func (he *he) FmtTimeFull(t time.Time) string {
  434. b := make([]byte, 0, 32)
  435. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  436. b = append(b, he.timeSeparator...)
  437. if t.Minute() < 10 {
  438. b = append(b, '0')
  439. }
  440. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  441. b = append(b, he.timeSeparator...)
  442. if t.Second() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Second()), 10)
  446. b = append(b, []byte{0x20}...)
  447. tz, _ := t.Zone()
  448. if btz, ok := he.timezones[tz]; ok {
  449. b = append(b, btz...)
  450. } else {
  451. b = append(b, tz...)
  452. }
  453. return string(b)
  454. }