hr.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. package hr
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type hr 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 'hr' locale
  41. func New() locales.Translator {
  42. return &hr{
  43. locale: "hr",
  44. pluralsCardinal: []locales.PluralRule{2, 4, 6},
  45. pluralsOrdinal: []locales.PluralRule{6},
  46. pluralsRange: []locales.PluralRule{2, 4, 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", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "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", "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", "XPF", "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{"", "sij", "velj", "ožu", "tra", "svi", "lip", "srp", "kol", "ruj", "lis", "stu", "pro"},
  58. monthsNarrow: []string{"", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12."},
  59. monthsWide: []string{"", "siječnja", "veljače", "ožujka", "travnja", "svibnja", "lipnja", "srpnja", "kolovoza", "rujna", "listopada", "studenoga", "prosinca"},
  60. daysAbbreviated: []string{"ned", "pon", "uto", "sri", "čet", "pet", "sub"},
  61. daysNarrow: []string{"N", "P", "U", "S", "Č", "P", "S"},
  62. daysShort: []string{"ned", "pon", "uto", "sri", "čet", "pet", "sub"},
  63. daysWide: []string{"nedjelja", "ponedjeljak", "utorak", "srijeda", "četvrtak", "petak", "subota"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"AM", "PM"},
  66. periodsWide: []string{"AM", "PM"},
  67. erasAbbreviated: []string{"pr. Kr.", "po. Kr."},
  68. erasNarrow: []string{"pr.n.e.", "AD"},
  69. erasWide: []string{"prije Krista", "poslije Krista"},
  70. timezones: map[string]string{"ADT": "atlantsko ljetno vrijeme", "SRT": "surinamsko vrijeme", "TMST": "turkmenistansko ljetno vrijeme", "PDT": "pacifičko ljetno vrijeme", "WIT": "istočnoindonezijsko vrijeme", "UYT": "urugvajsko standardno vrijeme", "PST": "pacifičko standardno vrijeme", "WEZ": "zapadnoeuropsko standardno vrijeme", "WARST": "zapadnoargentinsko ljetno vrijeme", "MST": "standardno makaosko vrijeme", "TMT": "turkmenistansko standardno vrijeme", "OEZ": "istočnoeuropsko standardno vrijeme", "GMT": "univerzalno vrijeme", "AWST": "zapadnoaustralsko standardno vrijeme", "JST": "japansko standardno vrijeme", "VET": "venezuelsko vrijeme", "EAT": "istočnoafričko vrijeme", "HNPMX": "meksičko pacifičko standardno vrijeme", "HNEG": "istočnogrenlandsko standardno vrijeme", "CAT": "srednjoafričko vrijeme", "GYT": "gvajansko vrijeme", "HEPM": "ljetno vrijeme za Sveti Petar i Mikelon", "HENOMX": "sjeverozapadno meksičko ljetno vrijeme", "CHAST": "standardno vrijeme Chathama", "CST": "središnje standardno vrijeme", "AEST": "istočnoaustralsko standardno vrijeme", "HEOG": "zapadnogrenlandsko ljetno vrijeme", "HKST": "hongkonško ljetno vrijeme", "LHST": "standardno vrijeme otoka Lord Howe", "GFT": "vrijeme Francuske Gvajane", "AKST": "aljaško standardno vrijeme", "EDT": "istočno ljetno vrijeme", "HNNOMX": "sjeverozapadno meksičko standardno vrijeme", "UYST": "urugvajsko ljetno vrijeme", "WAST": "zapadnoafričko ljetno vrijeme", "WIB": "zapadnoindonezijsko vrijeme", "BT": "butansko vrijeme", "CHADT": "ljetno vrijeme Chathama", "HNCU": "kubansko standardno vrijeme", "HKT": "hongkonško standardno vrijeme", "ARST": "argentinsko ljetno vrijeme", "WESZ": "zapadnoeuropsko ljetno vrijeme", "HEEG": "istočnogrenlandsko ljetno vrijeme", "MESZ": "srednjoeuropsko ljetno vrijeme", "CLST": "čileansko ljetno vrijeme", "HADT": "havajsko-aleutsko ljetno vrijeme", "CDT": "središnje ljetno vrijeme", "BOT": "bolivijsko vrijeme", "JDT": "japansko ljetno vrijeme", "ACWST": "australsko središnje zapadno standardno vrijeme", "HNPM": "standardno vrijeme za Sveti Petar i Mikelon", "ART": "argentinsko standardno vrijeme", "COST": "kolumbijsko ljetno vrijeme", "AEDT": "istočnoaustralsko ljetno vrijeme", "ACWDT": "australsko središnje zapadno ljetno vrijeme", "LHDT": "ljetno vrijeme otoka Lord Howe", "HAT": "newfoundlandsko ljetno vrijeme", "OESZ": "istočnoeuropsko ljetno vrijeme", "WAT": "zapadnoafričko standardno vrijeme", "SGT": "singapursko vrijeme", "WART": "zapadnoargentinsko standardno vrijeme", "IST": "indijsko vrijeme", "SAST": "južnoafričko vrijeme", "ACDT": "srednjoaustralsko ljetno vrijeme", "MEZ": "srednjoeuropsko standardno vrijeme", "HNOG": "zapadnogrenlandsko standardno vrijeme", "CLT": "čileansko standardno vrijeme", "HAST": "havajsko-aleutsko standardno vrijeme", "ChST": "standardno vrijeme Chamorra", "NZST": "novozelandsko standardno vrijeme", "MYT": "malezijsko vrijeme", "ECT": "ekvadorsko vrijeme", "WITA": "srednjoindonezijsko vrijeme", "MDT": "ljetno makaosko vrijeme", "AST": "atlantsko standardno vrijeme", "HECU": "kubansko ljetno vrijeme", "∅∅∅": "Acre ljetno vrijeme", "NZDT": "novozelandsko ljetno vrijeme", "COT": "kolumbijsko standardno vrijeme", "HNT": "newfoundlandsko standardno vrijeme", "AWDT": "zapadnoaustralsko ljetno vrijeme", "HEPMX": "meksičko pacifičko ljetno vrijeme", "AKDT": "aljaško ljetno vrijeme", "EST": "istočno standardno vrijeme", "ACST": "srednjoaustralsko standardno vrijeme"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (hr *hr) Locale() string {
  75. return hr.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'hr'
  78. func (hr *hr) PluralsCardinal() []locales.PluralRule {
  79. return hr.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'hr'
  82. func (hr *hr) PluralsOrdinal() []locales.PluralRule {
  83. return hr.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'hr'
  86. func (hr *hr) PluralsRange() []locales.PluralRule {
  87. return hr.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'hr'
  90. func (hr *hr) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. f := locales.F(n, v)
  94. iMod10 := i % 10
  95. iMod100 := i % 100
  96. fMod10 := f % 10
  97. fMod100 := f % 100
  98. if (v == 0 && iMod10 == 1 && iMod100 != 11) || (fMod10 == 1 && fMod100 != 11) {
  99. return locales.PluralRuleOne
  100. } else if (v == 0 && iMod10 >= 2 && iMod10 <= 4 && (iMod100 < 12 || iMod100 > 14)) || (fMod10 >= 2 && fMod10 <= 4 && (fMod100 < 12 || fMod100 > 14)) {
  101. return locales.PluralRuleFew
  102. }
  103. return locales.PluralRuleOther
  104. }
  105. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'hr'
  106. func (hr *hr) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  107. return locales.PluralRuleOther
  108. }
  109. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'hr'
  110. func (hr *hr) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  111. start := hr.CardinalPluralRule(num1, v1)
  112. end := hr.CardinalPluralRule(num2, v2)
  113. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  114. return locales.PluralRuleOne
  115. } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
  116. return locales.PluralRuleFew
  117. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  118. return locales.PluralRuleOther
  119. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOne {
  120. return locales.PluralRuleOne
  121. } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew {
  122. return locales.PluralRuleFew
  123. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
  124. return locales.PluralRuleOther
  125. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  126. return locales.PluralRuleOne
  127. } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew {
  128. return locales.PluralRuleFew
  129. }
  130. return locales.PluralRuleOther
  131. }
  132. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  133. func (hr *hr) MonthAbbreviated(month time.Month) string {
  134. return hr.monthsAbbreviated[month]
  135. }
  136. // MonthsAbbreviated returns the locales abbreviated months
  137. func (hr *hr) MonthsAbbreviated() []string {
  138. return hr.monthsAbbreviated[1:]
  139. }
  140. // MonthNarrow returns the locales narrow month given the 'month' provided
  141. func (hr *hr) MonthNarrow(month time.Month) string {
  142. return hr.monthsNarrow[month]
  143. }
  144. // MonthsNarrow returns the locales narrow months
  145. func (hr *hr) MonthsNarrow() []string {
  146. return hr.monthsNarrow[1:]
  147. }
  148. // MonthWide returns the locales wide month given the 'month' provided
  149. func (hr *hr) MonthWide(month time.Month) string {
  150. return hr.monthsWide[month]
  151. }
  152. // MonthsWide returns the locales wide months
  153. func (hr *hr) MonthsWide() []string {
  154. return hr.monthsWide[1:]
  155. }
  156. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  157. func (hr *hr) WeekdayAbbreviated(weekday time.Weekday) string {
  158. return hr.daysAbbreviated[weekday]
  159. }
  160. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  161. func (hr *hr) WeekdaysAbbreviated() []string {
  162. return hr.daysAbbreviated
  163. }
  164. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  165. func (hr *hr) WeekdayNarrow(weekday time.Weekday) string {
  166. return hr.daysNarrow[weekday]
  167. }
  168. // WeekdaysNarrow returns the locales narrow weekdays
  169. func (hr *hr) WeekdaysNarrow() []string {
  170. return hr.daysNarrow
  171. }
  172. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  173. func (hr *hr) WeekdayShort(weekday time.Weekday) string {
  174. return hr.daysShort[weekday]
  175. }
  176. // WeekdaysShort returns the locales short weekdays
  177. func (hr *hr) WeekdaysShort() []string {
  178. return hr.daysShort
  179. }
  180. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  181. func (hr *hr) WeekdayWide(weekday time.Weekday) string {
  182. return hr.daysWide[weekday]
  183. }
  184. // WeekdaysWide returns the locales wide weekdays
  185. func (hr *hr) WeekdaysWide() []string {
  186. return hr.daysWide
  187. }
  188. // Decimal returns the decimal point of number
  189. func (hr *hr) Decimal() string {
  190. return hr.decimal
  191. }
  192. // Group returns the group of number
  193. func (hr *hr) Group() string {
  194. return hr.group
  195. }
  196. // Group returns the minus sign of number
  197. func (hr *hr) Minus() string {
  198. return hr.minus
  199. }
  200. // FmtNumber returns 'num' with digits/precision of 'v' for 'hr' and handles both Whole and Real numbers based on 'v'
  201. func (hr *hr) FmtNumber(num float64, v uint64) string {
  202. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  203. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  204. count := 0
  205. inWhole := v == 0
  206. b := make([]byte, 0, l)
  207. for i := len(s) - 1; i >= 0; i-- {
  208. if s[i] == '.' {
  209. b = append(b, hr.decimal[0])
  210. inWhole = true
  211. continue
  212. }
  213. if inWhole {
  214. if count == 3 {
  215. b = append(b, hr.group[0])
  216. count = 1
  217. } else {
  218. count++
  219. }
  220. }
  221. b = append(b, s[i])
  222. }
  223. if num < 0 {
  224. b = append(b, hr.minus[0])
  225. }
  226. // reverse
  227. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  228. b[i], b[j] = b[j], b[i]
  229. }
  230. return string(b)
  231. }
  232. // FmtPercent returns 'num' with digits/precision of 'v' for 'hr' and handles both Whole and Real numbers based on 'v'
  233. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  234. func (hr *hr) FmtPercent(num float64, v uint64) string {
  235. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  236. l := len(s) + 3
  237. b := make([]byte, 0, l)
  238. for i := len(s) - 1; i >= 0; i-- {
  239. if s[i] == '.' {
  240. b = append(b, hr.decimal[0])
  241. continue
  242. }
  243. b = append(b, s[i])
  244. }
  245. if num < 0 {
  246. b = append(b, hr.minus[0])
  247. }
  248. // reverse
  249. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  250. b[i], b[j] = b[j], b[i]
  251. }
  252. b = append(b, hr.percent...)
  253. return string(b)
  254. }
  255. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'hr'
  256. func (hr *hr) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  257. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  258. symbol := hr.currencies[currency]
  259. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  260. count := 0
  261. inWhole := v == 0
  262. b := make([]byte, 0, l)
  263. for i := len(s) - 1; i >= 0; i-- {
  264. if s[i] == '.' {
  265. b = append(b, hr.decimal[0])
  266. inWhole = true
  267. continue
  268. }
  269. if inWhole {
  270. if count == 3 {
  271. b = append(b, hr.group[0])
  272. count = 1
  273. } else {
  274. count++
  275. }
  276. }
  277. b = append(b, s[i])
  278. }
  279. if num < 0 {
  280. b = append(b, hr.minus[0])
  281. }
  282. // reverse
  283. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  284. b[i], b[j] = b[j], b[i]
  285. }
  286. if int(v) < 2 {
  287. if v == 0 {
  288. b = append(b, hr.decimal...)
  289. }
  290. for i := 0; i < 2-int(v); i++ {
  291. b = append(b, '0')
  292. }
  293. }
  294. b = append(b, hr.currencyPositiveSuffix...)
  295. b = append(b, symbol...)
  296. return string(b)
  297. }
  298. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'hr'
  299. // in accounting notation.
  300. func (hr *hr) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  301. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  302. symbol := hr.currencies[currency]
  303. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  304. count := 0
  305. inWhole := v == 0
  306. b := make([]byte, 0, l)
  307. for i := len(s) - 1; i >= 0; i-- {
  308. if s[i] == '.' {
  309. b = append(b, hr.decimal[0])
  310. inWhole = true
  311. continue
  312. }
  313. if inWhole {
  314. if count == 3 {
  315. b = append(b, hr.group[0])
  316. count = 1
  317. } else {
  318. count++
  319. }
  320. }
  321. b = append(b, s[i])
  322. }
  323. if num < 0 {
  324. b = append(b, hr.minus[0])
  325. }
  326. // reverse
  327. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  328. b[i], b[j] = b[j], b[i]
  329. }
  330. if int(v) < 2 {
  331. if v == 0 {
  332. b = append(b, hr.decimal...)
  333. }
  334. for i := 0; i < 2-int(v); i++ {
  335. b = append(b, '0')
  336. }
  337. }
  338. if num < 0 {
  339. b = append(b, hr.currencyNegativeSuffix...)
  340. b = append(b, symbol...)
  341. } else {
  342. b = append(b, hr.currencyPositiveSuffix...)
  343. b = append(b, symbol...)
  344. }
  345. return string(b)
  346. }
  347. // FmtDateShort returns the short date representation of 't' for 'hr'
  348. func (hr *hr) FmtDateShort(t time.Time) string {
  349. b := make([]byte, 0, 32)
  350. if t.Day() < 10 {
  351. b = append(b, '0')
  352. }
  353. b = strconv.AppendInt(b, int64(t.Day()), 10)
  354. b = append(b, []byte{0x2e, 0x20}...)
  355. if t.Month() < 10 {
  356. b = append(b, '0')
  357. }
  358. b = strconv.AppendInt(b, int64(t.Month()), 10)
  359. b = append(b, []byte{0x2e, 0x20}...)
  360. if t.Year() > 0 {
  361. b = strconv.AppendInt(b, int64(t.Year()), 10)
  362. } else {
  363. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  364. }
  365. b = append(b, []byte{0x2e}...)
  366. return string(b)
  367. }
  368. // FmtDateMedium returns the medium date representation of 't' for 'hr'
  369. func (hr *hr) FmtDateMedium(t time.Time) string {
  370. b := make([]byte, 0, 32)
  371. b = strconv.AppendInt(b, int64(t.Day()), 10)
  372. b = append(b, []byte{0x2e, 0x20}...)
  373. b = append(b, hr.monthsAbbreviated[t.Month()]...)
  374. b = append(b, []byte{0x20}...)
  375. if t.Year() > 0 {
  376. b = strconv.AppendInt(b, int64(t.Year()), 10)
  377. } else {
  378. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  379. }
  380. b = append(b, []byte{0x2e}...)
  381. return string(b)
  382. }
  383. // FmtDateLong returns the long date representation of 't' for 'hr'
  384. func (hr *hr) FmtDateLong(t time.Time) string {
  385. b := make([]byte, 0, 32)
  386. b = strconv.AppendInt(b, int64(t.Day()), 10)
  387. b = append(b, []byte{0x2e, 0x20}...)
  388. b = append(b, hr.monthsWide[t.Month()]...)
  389. b = append(b, []byte{0x20}...)
  390. if t.Year() > 0 {
  391. b = strconv.AppendInt(b, int64(t.Year()), 10)
  392. } else {
  393. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  394. }
  395. b = append(b, []byte{0x2e}...)
  396. return string(b)
  397. }
  398. // FmtDateFull returns the full date representation of 't' for 'hr'
  399. func (hr *hr) FmtDateFull(t time.Time) string {
  400. b := make([]byte, 0, 32)
  401. b = append(b, hr.daysWide[t.Weekday()]...)
  402. b = append(b, []byte{0x2c, 0x20}...)
  403. b = strconv.AppendInt(b, int64(t.Day()), 10)
  404. b = append(b, []byte{0x2e, 0x20}...)
  405. b = append(b, hr.monthsWide[t.Month()]...)
  406. b = append(b, []byte{0x20}...)
  407. if t.Year() > 0 {
  408. b = strconv.AppendInt(b, int64(t.Year()), 10)
  409. } else {
  410. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  411. }
  412. b = append(b, []byte{0x2e}...)
  413. return string(b)
  414. }
  415. // FmtTimeShort returns the short time representation of 't' for 'hr'
  416. func (hr *hr) FmtTimeShort(t time.Time) string {
  417. b := make([]byte, 0, 32)
  418. if t.Hour() < 10 {
  419. b = append(b, '0')
  420. }
  421. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  422. b = append(b, hr.timeSeparator...)
  423. if t.Minute() < 10 {
  424. b = append(b, '0')
  425. }
  426. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  427. return string(b)
  428. }
  429. // FmtTimeMedium returns the medium time representation of 't' for 'hr'
  430. func (hr *hr) FmtTimeMedium(t time.Time) string {
  431. b := make([]byte, 0, 32)
  432. if t.Hour() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  436. b = append(b, hr.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, hr.timeSeparator...)
  442. if t.Second() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Second()), 10)
  446. return string(b)
  447. }
  448. // FmtTimeLong returns the long time representation of 't' for 'hr'
  449. func (hr *hr) FmtTimeLong(t time.Time) string {
  450. b := make([]byte, 0, 32)
  451. if t.Hour() < 10 {
  452. b = append(b, '0')
  453. }
  454. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  455. b = append(b, hr.timeSeparator...)
  456. if t.Minute() < 10 {
  457. b = append(b, '0')
  458. }
  459. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  460. b = append(b, hr.timeSeparator...)
  461. if t.Second() < 10 {
  462. b = append(b, '0')
  463. }
  464. b = strconv.AppendInt(b, int64(t.Second()), 10)
  465. b = append(b, []byte{0x20}...)
  466. tz, _ := t.Zone()
  467. b = append(b, tz...)
  468. return string(b)
  469. }
  470. // FmtTimeFull returns the full time representation of 't' for 'hr'
  471. func (hr *hr) FmtTimeFull(t time.Time) string {
  472. b := make([]byte, 0, 32)
  473. if t.Hour() < 10 {
  474. b = append(b, '0')
  475. }
  476. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  477. b = append(b, hr.timeSeparator...)
  478. if t.Minute() < 10 {
  479. b = append(b, '0')
  480. }
  481. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  482. b = append(b, hr.timeSeparator...)
  483. if t.Second() < 10 {
  484. b = append(b, '0')
  485. }
  486. b = strconv.AppendInt(b, int64(t.Second()), 10)
  487. b = append(b, []byte{0x20, 0x28}...)
  488. tz, _ := t.Zone()
  489. if btz, ok := hr.timezones[tz]; ok {
  490. b = append(b, btz...)
  491. } else {
  492. b = append(b, tz...)
  493. }
  494. b = append(b, []byte{0x29}...)
  495. return string(b)
  496. }