ro.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. package ro
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ro 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. percentSuffix string
  19. perMille string
  20. timeSeparator string
  21. inifinity string
  22. currencies []string // idx = enum of currency code
  23. currencyPositiveSuffix string
  24. currencyNegativePrefix string
  25. currencyNegativeSuffix string
  26. monthsAbbreviated []string
  27. monthsNarrow []string
  28. monthsWide []string
  29. daysAbbreviated []string
  30. daysNarrow []string
  31. daysShort []string
  32. daysWide []string
  33. periodsAbbreviated []string
  34. periodsNarrow []string
  35. periodsShort []string
  36. periodsWide []string
  37. erasAbbreviated []string
  38. erasNarrow []string
  39. erasWide []string
  40. timezones map[string]string
  41. }
  42. // New returns a new instance of translator for the 'ro' locale
  43. func New() locales.Translator {
  44. return &ro{
  45. locale: "ro",
  46. pluralsCardinal: []locales.PluralRule{2, 4, 6},
  47. pluralsOrdinal: []locales.PluralRule{2, 6},
  48. pluralsRange: []locales.PluralRule{6, 4},
  49. decimal: ",",
  50. group: ".",
  51. minus: "-",
  52. percent: "%",
  53. perMille: "‰",
  54. timeSeparator: ":",
  55. inifinity: "∞",
  56. 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", "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", "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 "},
  57. percentSuffix: " ",
  58. currencyPositiveSuffix: " ",
  59. currencyNegativePrefix: "(",
  60. currencyNegativeSuffix: " )",
  61. monthsAbbreviated: []string{"", "ian.", "feb.", "mar.", "apr.", "mai", "iun.", "iul.", "aug.", "sept.", "oct.", "nov.", "dec."},
  62. monthsNarrow: []string{"", "I", "F", "M", "A", "M", "I", "I", "A", "S", "O", "N", "D"},
  63. monthsWide: []string{"", "ianuarie", "februarie", "martie", "aprilie", "mai", "iunie", "iulie", "august", "septembrie", "octombrie", "noiembrie", "decembrie"},
  64. daysAbbreviated: []string{"dum.", "lun.", "mar.", "mie.", "joi", "vin.", "sâm."},
  65. daysNarrow: []string{"D", "L", "M", "M", "J", "V", "S"},
  66. daysShort: []string{"du.", "lu.", "ma.", "mi.", "jo.", "vi.", "sâ."},
  67. daysWide: []string{"duminică", "luni", "marți", "miercuri", "joi", "vineri", "sâmbătă"},
  68. periodsAbbreviated: []string{"a.m.", "p.m."},
  69. periodsNarrow: []string{"a.m.", "p.m."},
  70. periodsWide: []string{"a.m.", "p.m."},
  71. erasAbbreviated: []string{"î.Hr.", "d.Hr."},
  72. erasNarrow: []string{"", ""},
  73. erasWide: []string{"înainte de Hristos", "după Hristos"},
  74. timezones: map[string]string{"WAST": "Ora de vară a Africii Occidentale", "∅∅∅": "Ora de vară a Amazonului", "AWDT": "Ora de vară a Australiei Occidentale", "MYT": "Ora din Malaysia", "MEZ": "Ora standard a Europei Centrale", "WESZ": "Ora de vară a Europei de Vest", "ECT": "Ora Ecuadorului", "ACDT": "Ora de vară a Australiei Centrale", "TMST": "Ora de vară din Turkmenistan", "CDT": "Ora de vară centrală nord-americană", "CLT": "Ora standard din Chile", "COT": "Ora standard a Columbiei", "MST": "MST", "PST": "Ora standard în zona Pacific nord-americană", "HADT": "Ora de vară din Hawaii-Aleutine", "WIT": "Ora Indoneziei de Est", "ART": "Ora standard a Argentinei", "UYST": "Ora de vară a Uruguayului", "EST": "Ora standard orientală nord-americană", "OESZ": "Ora de vară a Europei de Est", "JDT": "Ora de vară a Japoniei", "WARST": "Ora de vară a Argentinei Occidentale", "WAT": "Ora standard a Africii Occidentale", "OEZ": "Ora standard a Europei de Est", "MDT": "MDT", "ARST": "Ora de vară a Argentinei", "TMT": "Ora standard din Turkmenistan", "LHST": "Ora standard din Lord Howe", "NZST": "Ora standard a Noii Zeelande", "BOT": "Ora Boliviei", "ChST": "Ora din Chamorro", "EAT": "Ora Africii Orientale", "AKST": "Ora standard din Alaska", "VET": "Ora Venezuelei", "EDT": "Ora de vară orientală nord-americană", "WIB": "Ora Indoneziei de Vest", "WEZ": "Ora standard a Europei de Vest", "AEST": "Ora standard a Australiei Orientale", "CLST": "Ora de vară din Chile", "GFT": "Ora Guianei Franceze", "AKDT": "Ora de vară din Alaska", "LHDT": "Ora de vară din Lord Howe", "SRT": "Ora Surinamului", "ACWDT": "Ora de vară a Australiei Central Occidentale", "WART": "Ora standard a Argentinei Occidentale", "IST": "Ora Indiei", "AWST": "Ora standard a Australiei Occidentale", "CAT": "Ora Africii Centrale", "SGT": "Ora din Singapore", "HKT": "Ora standard din Hong Kong", "HKST": "Ora de vară din Hong Kong", "JST": "Ora standard a Japoniei", "ACWST": "Ora standard a Australiei Central Occidentale", "AEDT": "Ora de vară a Australiei Orientale", "HAT": "Ora de vară din Newfoundland", "MESZ": "Ora de vară a Europei Centrale", "CHAST": "Ora standard din Chatham", "COST": "Ora de vară a Columbiei", "ADT": "Ora de vară în zona Atlantic nord-americană", "BT": "Ora Bhutanului", "GMT": "Ora de Greenwhich", "WITA": "Ora Indoneziei Centrale", "ACST": "Ora standard a Australiei Centrale", "GYT": "Ora din Guyana", "CST": "Ora standard centrală nord-americană", "NZDT": "Ora de vară a Noii Zeelande", "AST": "Ora standard în zona Atlantic nord-americană", "HAST": "Ora standard din Hawaii-Aleutine", "UYT": "Ora standard a Uruguayului", "SAST": "Ora Africii Meridionale", "HNT": "Ora standard din Newfoundland", "PDT": "Ora de vară în zona Pacific nord-americană", "CHADT": "Ora de vară din Chatham"},
  75. }
  76. }
  77. // Locale returns the current translators string locale
  78. func (ro *ro) Locale() string {
  79. return ro.locale
  80. }
  81. // PluralsCardinal returns the list of cardinal plural rules associated with 'ro'
  82. func (ro *ro) PluralsCardinal() []locales.PluralRule {
  83. return ro.pluralsCardinal
  84. }
  85. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ro'
  86. func (ro *ro) PluralsOrdinal() []locales.PluralRule {
  87. return ro.pluralsOrdinal
  88. }
  89. // PluralsRange returns the list of range plural rules associated with 'ro'
  90. func (ro *ro) PluralsRange() []locales.PluralRule {
  91. return ro.pluralsRange
  92. }
  93. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ro'
  94. func (ro *ro) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  95. n := math.Abs(num)
  96. i := int64(n)
  97. nMod100 := math.Mod(n, 100)
  98. if i == 1 && v == 0 {
  99. return locales.PluralRuleOne
  100. } else if (v != 0) || (n == 0) || (n != 1 && nMod100 >= 1 && nMod100 <= 19) {
  101. return locales.PluralRuleFew
  102. }
  103. return locales.PluralRuleOther
  104. }
  105. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ro'
  106. func (ro *ro) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  107. n := math.Abs(num)
  108. if n == 1 {
  109. return locales.PluralRuleOne
  110. }
  111. return locales.PluralRuleOther
  112. }
  113. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ro'
  114. func (ro *ro) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  115. start := ro.CardinalPluralRule(num1, v1)
  116. end := ro.CardinalPluralRule(num2, v2)
  117. if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
  118. return locales.PluralRuleFew
  119. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  120. return locales.PluralRuleOther
  121. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOne {
  122. return locales.PluralRuleFew
  123. } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew {
  124. return locales.PluralRuleFew
  125. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
  126. return locales.PluralRuleOther
  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 (ro *ro) MonthAbbreviated(month time.Month) string {
  134. return ro.monthsAbbreviated[month]
  135. }
  136. // MonthsAbbreviated returns the locales abbreviated months
  137. func (ro *ro) MonthsAbbreviated() []string {
  138. return ro.monthsAbbreviated[1:]
  139. }
  140. // MonthNarrow returns the locales narrow month given the 'month' provided
  141. func (ro *ro) MonthNarrow(month time.Month) string {
  142. return ro.monthsNarrow[month]
  143. }
  144. // MonthsNarrow returns the locales narrow months
  145. func (ro *ro) MonthsNarrow() []string {
  146. return ro.monthsNarrow[1:]
  147. }
  148. // MonthWide returns the locales wide month given the 'month' provided
  149. func (ro *ro) MonthWide(month time.Month) string {
  150. return ro.monthsWide[month]
  151. }
  152. // MonthsWide returns the locales wide months
  153. func (ro *ro) MonthsWide() []string {
  154. return ro.monthsWide[1:]
  155. }
  156. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  157. func (ro *ro) WeekdayAbbreviated(weekday time.Weekday) string {
  158. return ro.daysAbbreviated[weekday]
  159. }
  160. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  161. func (ro *ro) WeekdaysAbbreviated() []string {
  162. return ro.daysAbbreviated
  163. }
  164. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  165. func (ro *ro) WeekdayNarrow(weekday time.Weekday) string {
  166. return ro.daysNarrow[weekday]
  167. }
  168. // WeekdaysNarrow returns the locales narrow weekdays
  169. func (ro *ro) WeekdaysNarrow() []string {
  170. return ro.daysNarrow
  171. }
  172. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  173. func (ro *ro) WeekdayShort(weekday time.Weekday) string {
  174. return ro.daysShort[weekday]
  175. }
  176. // WeekdaysShort returns the locales short weekdays
  177. func (ro *ro) WeekdaysShort() []string {
  178. return ro.daysShort
  179. }
  180. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  181. func (ro *ro) WeekdayWide(weekday time.Weekday) string {
  182. return ro.daysWide[weekday]
  183. }
  184. // WeekdaysWide returns the locales wide weekdays
  185. func (ro *ro) WeekdaysWide() []string {
  186. return ro.daysWide
  187. }
  188. // FmtNumber returns 'num' with digits/precision of 'v' for 'ro' and handles both Whole and Real numbers based on 'v'
  189. func (ro *ro) FmtNumber(num float64, v uint64) string {
  190. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  191. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  192. count := 0
  193. inWhole := v == 0
  194. b := make([]byte, 0, l)
  195. for i := len(s) - 1; i >= 0; i-- {
  196. if s[i] == '.' {
  197. b = append(b, ro.decimal[0])
  198. inWhole = true
  199. continue
  200. }
  201. if inWhole {
  202. if count == 3 {
  203. b = append(b, ro.group[0])
  204. count = 1
  205. } else {
  206. count++
  207. }
  208. }
  209. b = append(b, s[i])
  210. }
  211. if num < 0 {
  212. b = append(b, ro.minus[0])
  213. }
  214. // reverse
  215. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  216. b[i], b[j] = b[j], b[i]
  217. }
  218. return string(b)
  219. }
  220. // FmtPercent returns 'num' with digits/precision of 'v' for 'ro' and handles both Whole and Real numbers based on 'v'
  221. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  222. func (ro *ro) FmtPercent(num float64, v uint64) string {
  223. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  224. l := len(s) + 5
  225. b := make([]byte, 0, l)
  226. for i := len(s) - 1; i >= 0; i-- {
  227. if s[i] == '.' {
  228. b = append(b, ro.decimal[0])
  229. continue
  230. }
  231. b = append(b, s[i])
  232. }
  233. if num < 0 {
  234. b = append(b, ro.minus[0])
  235. }
  236. // reverse
  237. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  238. b[i], b[j] = b[j], b[i]
  239. }
  240. b = append(b, ro.percentSuffix...)
  241. b = append(b, ro.percent...)
  242. return string(b)
  243. }
  244. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ro'
  245. func (ro *ro) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  246. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  247. symbol := ro.currencies[currency]
  248. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  249. count := 0
  250. inWhole := v == 0
  251. b := make([]byte, 0, l)
  252. for i := len(s) - 1; i >= 0; i-- {
  253. if s[i] == '.' {
  254. b = append(b, ro.decimal[0])
  255. inWhole = true
  256. continue
  257. }
  258. if inWhole {
  259. if count == 3 {
  260. b = append(b, ro.group[0])
  261. count = 1
  262. } else {
  263. count++
  264. }
  265. }
  266. b = append(b, s[i])
  267. }
  268. if num < 0 {
  269. b = append(b, ro.minus[0])
  270. }
  271. // reverse
  272. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  273. b[i], b[j] = b[j], b[i]
  274. }
  275. if int(v) < 2 {
  276. if v == 0 {
  277. b = append(b, ro.decimal...)
  278. }
  279. for i := 0; i < 2-int(v); i++ {
  280. b = append(b, '0')
  281. }
  282. }
  283. b = append(b, ro.currencyPositiveSuffix...)
  284. b = append(b, symbol...)
  285. return string(b)
  286. }
  287. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ro'
  288. // in accounting notation.
  289. func (ro *ro) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  290. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  291. symbol := ro.currencies[currency]
  292. l := len(s) + len(symbol) + 6 + 1*len(s[:len(s)-int(v)-1])/3
  293. count := 0
  294. inWhole := v == 0
  295. b := make([]byte, 0, l)
  296. for i := len(s) - 1; i >= 0; i-- {
  297. if s[i] == '.' {
  298. b = append(b, ro.decimal[0])
  299. inWhole = true
  300. continue
  301. }
  302. if inWhole {
  303. if count == 3 {
  304. b = append(b, ro.group[0])
  305. count = 1
  306. } else {
  307. count++
  308. }
  309. }
  310. b = append(b, s[i])
  311. }
  312. if num < 0 {
  313. b = append(b, ro.currencyNegativePrefix[0])
  314. }
  315. // reverse
  316. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  317. b[i], b[j] = b[j], b[i]
  318. }
  319. if int(v) < 2 {
  320. if v == 0 {
  321. b = append(b, ro.decimal...)
  322. }
  323. for i := 0; i < 2-int(v); i++ {
  324. b = append(b, '0')
  325. }
  326. }
  327. if num < 0 {
  328. b = append(b, ro.currencyNegativeSuffix...)
  329. b = append(b, symbol...)
  330. } else {
  331. b = append(b, ro.currencyPositiveSuffix...)
  332. b = append(b, symbol...)
  333. }
  334. return string(b)
  335. }
  336. // FmtDateShort returns the short date representation of 't' for 'ro'
  337. func (ro *ro) FmtDateShort(t time.Time) string {
  338. b := make([]byte, 0, 32)
  339. if t.Day() < 10 {
  340. b = append(b, '0')
  341. }
  342. b = strconv.AppendInt(b, int64(t.Day()), 10)
  343. b = append(b, []byte{0x2e}...)
  344. if t.Month() < 10 {
  345. b = append(b, '0')
  346. }
  347. b = strconv.AppendInt(b, int64(t.Month()), 10)
  348. b = append(b, []byte{0x2e}...)
  349. b = strconv.AppendInt(b, int64(t.Year()), 10)
  350. return string(b)
  351. }
  352. // FmtDateMedium returns the medium date representation of 't' for 'ro'
  353. func (ro *ro) FmtDateMedium(t time.Time) string {
  354. b := make([]byte, 0, 32)
  355. b = strconv.AppendInt(b, int64(t.Day()), 10)
  356. b = append(b, []byte{0x20}...)
  357. b = append(b, ro.monthsAbbreviated[t.Month()]...)
  358. b = append(b, []byte{0x20}...)
  359. b = strconv.AppendInt(b, int64(t.Year()), 10)
  360. return string(b)
  361. }
  362. // FmtDateLong returns the long date representation of 't' for 'ro'
  363. func (ro *ro) FmtDateLong(t time.Time) string {
  364. b := make([]byte, 0, 32)
  365. b = strconv.AppendInt(b, int64(t.Day()), 10)
  366. b = append(b, []byte{0x20}...)
  367. b = append(b, ro.monthsWide[t.Month()]...)
  368. b = append(b, []byte{0x20}...)
  369. b = strconv.AppendInt(b, int64(t.Year()), 10)
  370. return string(b)
  371. }
  372. // FmtDateFull returns the full date representation of 't' for 'ro'
  373. func (ro *ro) FmtDateFull(t time.Time) string {
  374. b := make([]byte, 0, 32)
  375. b = append(b, ro.daysWide[t.Weekday()]...)
  376. b = append(b, []byte{0x2c, 0x20}...)
  377. b = strconv.AppendInt(b, int64(t.Day()), 10)
  378. b = append(b, []byte{0x20}...)
  379. b = append(b, ro.monthsWide[t.Month()]...)
  380. b = append(b, []byte{0x20}...)
  381. b = strconv.AppendInt(b, int64(t.Year()), 10)
  382. return string(b)
  383. }
  384. // FmtTimeShort returns the short time representation of 't' for 'ro'
  385. func (ro *ro) FmtTimeShort(t time.Time) string {
  386. b := make([]byte, 0, 32)
  387. if t.Hour() < 10 {
  388. b = append(b, '0')
  389. }
  390. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  391. b = append(b, ro.timeSeparator...)
  392. if t.Minute() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  396. return string(b)
  397. }
  398. // FmtTimeMedium returns the medium time representation of 't' for 'ro'
  399. func (ro *ro) FmtTimeMedium(t time.Time) string {
  400. b := make([]byte, 0, 32)
  401. if t.Hour() < 10 {
  402. b = append(b, '0')
  403. }
  404. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  405. b = append(b, ro.timeSeparator...)
  406. if t.Minute() < 10 {
  407. b = append(b, '0')
  408. }
  409. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  410. b = append(b, ro.timeSeparator...)
  411. if t.Second() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Second()), 10)
  415. return string(b)
  416. }
  417. // FmtTimeLong returns the long time representation of 't' for 'ro'
  418. func (ro *ro) FmtTimeLong(t time.Time) string {
  419. b := make([]byte, 0, 32)
  420. if t.Hour() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  424. b = append(b, ro.timeSeparator...)
  425. if t.Minute() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  429. b = append(b, ro.timeSeparator...)
  430. if t.Second() < 10 {
  431. b = append(b, '0')
  432. }
  433. b = strconv.AppendInt(b, int64(t.Second()), 10)
  434. b = append(b, []byte{0x20}...)
  435. tz, _ := t.Zone()
  436. b = append(b, tz...)
  437. return string(b)
  438. }
  439. // FmtTimeFull returns the full time representation of 't' for 'ro'
  440. func (ro *ro) FmtTimeFull(t time.Time) string {
  441. b := make([]byte, 0, 32)
  442. if t.Hour() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  446. b = append(b, ro.timeSeparator...)
  447. if t.Minute() < 10 {
  448. b = append(b, '0')
  449. }
  450. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  451. b = append(b, ro.timeSeparator...)
  452. if t.Second() < 10 {
  453. b = append(b, '0')
  454. }
  455. b = strconv.AppendInt(b, int64(t.Second()), 10)
  456. b = append(b, []byte{0x20}...)
  457. tz, _ := t.Zone()
  458. if btz, ok := ro.timezones[tz]; ok {
  459. b = append(b, btz...)
  460. } else {
  461. b = append(b, tz...)
  462. }
  463. return string(b)
  464. }