mr.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. package mr
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type mr 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. monthsAbbreviated []string
  23. monthsNarrow []string
  24. monthsWide []string
  25. daysAbbreviated []string
  26. daysNarrow []string
  27. daysShort []string
  28. daysWide []string
  29. periodsAbbreviated []string
  30. periodsNarrow []string
  31. periodsShort []string
  32. periodsWide []string
  33. erasAbbreviated []string
  34. erasNarrow []string
  35. erasWide []string
  36. timezones map[string]string
  37. }
  38. // New returns a new instance of translator for the 'mr' locale
  39. func New() locales.Translator {
  40. return &mr{
  41. locale: "mr",
  42. pluralsCardinal: []locales.PluralRule{2, 6},
  43. pluralsOrdinal: []locales.PluralRule{2, 3, 4, 6},
  44. pluralsRange: []locales.PluralRule{2, 6},
  45. decimal: ".",
  46. group: ",",
  47. minus: "-",
  48. percent: "%",
  49. perMille: "‰",
  50. timeSeparator: ":",
  51. inifinity: "∞",
  52. 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 ", "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 "},
  53. monthsAbbreviated: []string{"", "जाने", "फेब्रु", "मार्च", "एप्रि", "मे", "जून", "जुलै", "ऑग", "सप्टें", "ऑक्टो", "नोव्हें", "डिसें"},
  54. monthsNarrow: []string{"", "जा", "फे", "मा", "ए", "मे", "जू", "जु", "ऑ", "स", "ऑ", "नो", "डि"},
  55. monthsWide: []string{"", "जानेवारी", "फेब्रुवारी", "मार्च", "एप्रिल", "मे", "जून", "जुलै", "ऑगस्ट", "सप्टेंबर", "ऑक्टोबर", "नोव्हेंबर", "डिसेंबर"},
  56. daysAbbreviated: []string{"रवि", "सोम", "मंगळ", "बुध", "गुरु", "शुक्र", "शनि"},
  57. daysNarrow: []string{"र", "सो", "मं", "बु", "गु", "शु", "श"},
  58. daysShort: []string{"र", "सो", "मं", "बु", "गु", "शु", "श"},
  59. daysWide: []string{"रविवार", "सोमवार", "मंगळवार", "बुधवार", "गुरुवार", "शुक्रवार", "शनिवार"},
  60. periodsAbbreviated: []string{"म.पू.", "म.उ."},
  61. periodsNarrow: []string{"स", "सं"},
  62. periodsWide: []string{"म.पू.", "म.उ."},
  63. erasAbbreviated: []string{"इ. स. पू.", "इ. स."},
  64. erasNarrow: []string{"", ""},
  65. erasWide: []string{"ईसवीसनपूर्व", "ईसवीसन"},
  66. timezones: map[string]string{"ACWST": "ऑस्ट्रेलियन मध्य-पश्चिम प्रमाण वेळ", "HKT": "हाँग काँग प्रमाण वेळ", "OEZ": "पूर्व युरोपियन प्रमाण वेळ", "LHDT": "लॉर्ड होवे सूर्यप्रकाश वेळ", "AST": "अटलांटिक प्रमाण वेळ", "WAST": "पश्चिम आफ्रिका उन्हाळी वेळ", "AWST": "ऑस्ट्रेलियन पश्चिम प्रमाण वेळ", "AEST": "ऑस्ट्रेलियन पूर्व प्रमाण वेळ", "SGT": "सिंगापूर प्रमाण वेळ", "WITA": "मध्\u200dय इंडोनेशिया वेळ", "IST": "भारतीय प्रमाण वेळ", "NZDT": "न्यूझीलंड सूर्यप्रकाश वेळ", "WESZ": "पश्चिम युरोपियन उन्हाळी वेळ", "WAT": "पश्चिम आफ्रिका प्रमाण वेळ", "WIT": "पौर्वात्य इंडोनेशिया वेळ", "OESZ": "पूर्व युरोपियन उन्हाळी वेळ", "WEZ": "पश्चिम युरोपियन प्रमाण वेळ", "AKST": "अलास्का प्रमाण वेळ", "PDT": "पॅसिफिक सूर्यप्रकाश वेळ", "NZST": "न्यूझीलंड प्रमाण वेळ", "UYT": "उरुग्वे प्रमाण वेळ", "ChST": "चामोरो प्रमाण वेळ", "VET": "व्हेनेझुएला वेळ", "ARST": "अर्जेंटिना उन्हाळी वेळ", "TMT": "तुर्कमेनिस्तान प्रमाण वेळ", "CST": "केंद्रीय प्रमाण वेळ", "CLST": "चिली उन्हाळी वेळ", "HKST": "हाँग काँग उन्हाळी वेळ", "WART": "पश्चिमी अर्जेंटिना प्रमाण वेळ", "HNT": "न्यू फाउंडलंड प्रमाण वेळ", "ACDT": "ऑस्ट्रेलियन मध्य सूर्यप्रकाश वेळ", "ART": "अर्जेंटिना प्रमाण वेळ", "CAT": "मध्\u200dय आफ्रिका वेळ", "GYT": "गयाना वेळ", "PST": "पॅसिफिक प्रमाण वेळ", "BOT": "बोलिव्हिया वेळ", "CLT": "चिली प्रमाण वेळ", "COT": "कोलंबिया प्रमाण वेळ", "EST": "पौर्वात्य प्रमाण वेळ", "BT": "भूतान वेळ", "MST": "मकाऊ प्रमाणवेळ", "HAT": "न्यू फाउंडलंड सूर्यप्रकाश वेळ", "AKDT": "अलास्का सूर्यप्रकाश वेळ", "COST": "कोलंबिया उन्हाळी वेळ", "SRT": "सुरिनाम वेळ", "LHST": "लॉर्ड होवे प्रमाण वेळ", "MESZ": "मध्\u200dय युरोपियन उन्हाळी वेळ", "CHAST": "चॅथम प्रमाण वेळ", "ADT": "अटलांटिक सूर्यप्रकाश वेळ", "HADT": "हवाई-अलूशन सूर्यप्रकाश वेळ", "WIB": "पश्चिमी इंडोनेशिया वेळ", "∅∅∅": "अ\u200dॅमेझॉन उन्हाळी वेळ", "UYST": "उरुग्वे उन्हाळी वेळ", "ECT": "इक्वेडोर वेळ", "SAST": "दक्षिण आफ्रिका प्रमाण वेळ", "GMT": "ग्रीनिच प्रमाण वेळ", "JDT": "जपान सूर्यप्रकाश वेळ", "MYT": "मलेशिया वेळ", "HAST": "हवाई-अलूशन प्रमाण वेळ", "ACST": "ऑस्ट्रेलियन मध्य प्रमाण वेळ", "GFT": "फ्रेंच गयाना वेळ", "CHADT": "चॅथम सूर्यप्रकाश वेळ", "CDT": "केंद्रीय सूर्यप्रकाश वेळ", "MEZ": "मध्\u200dय युरोपियन प्रमाण वेळ", "AEDT": "ऑस्ट्रेलियन पूर्व सूर्यप्रकाश वेळ", "AWDT": "ऑस्ट्रेलियन पश्चिम सूर्यप्रकाश वेळ", "EAT": "पूर्व आफ्रिका वेळ", "MDT": "मकाऊ ग्रीष्मकालीन वेळ", "JST": "जपान प्रमाण वेळ", "ACWDT": "ऑस्ट्रेलियन मध्य-पश्चिम सूर्यप्रकाश वेळ", "EDT": "पौर्वात्य सूर्यप्रकाश वेळ", "WARST": "पश्चिमी अर्जेंटिना उन्हाळी वेळ", "TMST": "तुर्कमेनिस्तान उन्हाळी वेळ"},
  67. }
  68. }
  69. // Locale returns the current translators string locale
  70. func (mr *mr) Locale() string {
  71. return mr.locale
  72. }
  73. // PluralsCardinal returns the list of cardinal plural rules associated with 'mr'
  74. func (mr *mr) PluralsCardinal() []locales.PluralRule {
  75. return mr.pluralsCardinal
  76. }
  77. // PluralsOrdinal returns the list of ordinal plural rules associated with 'mr'
  78. func (mr *mr) PluralsOrdinal() []locales.PluralRule {
  79. return mr.pluralsOrdinal
  80. }
  81. // PluralsRange returns the list of range plural rules associated with 'mr'
  82. func (mr *mr) PluralsRange() []locales.PluralRule {
  83. return mr.pluralsRange
  84. }
  85. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'mr'
  86. func (mr *mr) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  87. n := math.Abs(num)
  88. i := int64(n)
  89. if (i == 0) || (n == 1) {
  90. return locales.PluralRuleOne
  91. }
  92. return locales.PluralRuleOther
  93. }
  94. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'mr'
  95. func (mr *mr) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  96. n := math.Abs(num)
  97. if n == 1 {
  98. return locales.PluralRuleOne
  99. } else if n == 2 || n == 3 {
  100. return locales.PluralRuleTwo
  101. } else if n == 4 {
  102. return locales.PluralRuleFew
  103. }
  104. return locales.PluralRuleOther
  105. }
  106. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'mr'
  107. func (mr *mr) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  108. start := mr.CardinalPluralRule(num1, v1)
  109. end := mr.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 (mr *mr) MonthAbbreviated(month time.Month) string {
  119. return mr.monthsAbbreviated[month]
  120. }
  121. // MonthsAbbreviated returns the locales abbreviated months
  122. func (mr *mr) MonthsAbbreviated() []string {
  123. return mr.monthsAbbreviated[1:]
  124. }
  125. // MonthNarrow returns the locales narrow month given the 'month' provided
  126. func (mr *mr) MonthNarrow(month time.Month) string {
  127. return mr.monthsNarrow[month]
  128. }
  129. // MonthsNarrow returns the locales narrow months
  130. func (mr *mr) MonthsNarrow() []string {
  131. return mr.monthsNarrow[1:]
  132. }
  133. // MonthWide returns the locales wide month given the 'month' provided
  134. func (mr *mr) MonthWide(month time.Month) string {
  135. return mr.monthsWide[month]
  136. }
  137. // MonthsWide returns the locales wide months
  138. func (mr *mr) MonthsWide() []string {
  139. return mr.monthsWide[1:]
  140. }
  141. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  142. func (mr *mr) WeekdayAbbreviated(weekday time.Weekday) string {
  143. return mr.daysAbbreviated[weekday]
  144. }
  145. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  146. func (mr *mr) WeekdaysAbbreviated() []string {
  147. return mr.daysAbbreviated
  148. }
  149. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  150. func (mr *mr) WeekdayNarrow(weekday time.Weekday) string {
  151. return mr.daysNarrow[weekday]
  152. }
  153. // WeekdaysNarrow returns the locales narrow weekdays
  154. func (mr *mr) WeekdaysNarrow() []string {
  155. return mr.daysNarrow
  156. }
  157. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  158. func (mr *mr) WeekdayShort(weekday time.Weekday) string {
  159. return mr.daysShort[weekday]
  160. }
  161. // WeekdaysShort returns the locales short weekdays
  162. func (mr *mr) WeekdaysShort() []string {
  163. return mr.daysShort
  164. }
  165. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  166. func (mr *mr) WeekdayWide(weekday time.Weekday) string {
  167. return mr.daysWide[weekday]
  168. }
  169. // WeekdaysWide returns the locales wide weekdays
  170. func (mr *mr) WeekdaysWide() []string {
  171. return mr.daysWide
  172. }
  173. // FmtNumber returns 'num' with digits/precision of 'v' for 'mr' and handles both Whole and Real numbers based on 'v'
  174. func (mr *mr) FmtNumber(num float64, v uint64) string {
  175. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  176. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  177. count := 0
  178. inWhole := v == 0
  179. inSecondary := false
  180. groupThreshold := 3
  181. b := make([]byte, 0, l)
  182. for i := len(s) - 1; i >= 0; i-- {
  183. if s[i] == '.' {
  184. b = append(b, mr.decimal[0])
  185. inWhole = true
  186. continue
  187. }
  188. if inWhole {
  189. if count == groupThreshold {
  190. b = append(b, mr.group[0])
  191. count = 1
  192. if !inSecondary {
  193. inSecondary = true
  194. groupThreshold = 2
  195. }
  196. } else {
  197. count++
  198. }
  199. }
  200. b = append(b, s[i])
  201. }
  202. if num < 0 {
  203. b = append(b, mr.minus[0])
  204. }
  205. // reverse
  206. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  207. b[i], b[j] = b[j], b[i]
  208. }
  209. return string(b)
  210. }
  211. // FmtPercent returns 'num' with digits/precision of 'v' for 'mr' and handles both Whole and Real numbers based on 'v'
  212. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  213. func (mr *mr) FmtPercent(num float64, v uint64) string {
  214. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  215. l := len(s) + 3
  216. b := make([]byte, 0, l)
  217. for i := len(s) - 1; i >= 0; i-- {
  218. if s[i] == '.' {
  219. b = append(b, mr.decimal[0])
  220. continue
  221. }
  222. b = append(b, s[i])
  223. }
  224. if num < 0 {
  225. b = append(b, mr.minus[0])
  226. }
  227. // reverse
  228. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  229. b[i], b[j] = b[j], b[i]
  230. }
  231. b = append(b, mr.percent...)
  232. return string(b)
  233. }
  234. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mr'
  235. func (mr *mr) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  236. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  237. symbol := mr.currencies[currency]
  238. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  239. count := 0
  240. inWhole := v == 0
  241. b := make([]byte, 0, l)
  242. for i := len(s) - 1; i >= 0; i-- {
  243. if s[i] == '.' {
  244. b = append(b, mr.decimal[0])
  245. inWhole = true
  246. continue
  247. }
  248. if inWhole {
  249. if count == 3 {
  250. b = append(b, mr.group[0])
  251. count = 1
  252. } else {
  253. count++
  254. }
  255. }
  256. b = append(b, s[i])
  257. }
  258. for j := len(symbol) - 1; j >= 0; j-- {
  259. b = append(b, symbol[j])
  260. }
  261. if num < 0 {
  262. b = append(b, mr.minus[0])
  263. }
  264. // reverse
  265. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  266. b[i], b[j] = b[j], b[i]
  267. }
  268. if int(v) < 2 {
  269. if v == 0 {
  270. b = append(b, mr.decimal...)
  271. }
  272. for i := 0; i < 2-int(v); i++ {
  273. b = append(b, '0')
  274. }
  275. }
  276. return string(b)
  277. }
  278. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mr'
  279. // in accounting notation.
  280. func (mr *mr) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  281. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  282. symbol := mr.currencies[currency]
  283. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  284. count := 0
  285. inWhole := v == 0
  286. b := make([]byte, 0, l)
  287. for i := len(s) - 1; i >= 0; i-- {
  288. if s[i] == '.' {
  289. b = append(b, mr.decimal[0])
  290. inWhole = true
  291. continue
  292. }
  293. if inWhole {
  294. if count == 3 {
  295. b = append(b, mr.group[0])
  296. count = 1
  297. } else {
  298. count++
  299. }
  300. }
  301. b = append(b, s[i])
  302. }
  303. if num < 0 {
  304. for j := len(symbol) - 1; j >= 0; j-- {
  305. b = append(b, symbol[j])
  306. }
  307. b = append(b, mr.minus[0])
  308. } else {
  309. for j := len(symbol) - 1; j >= 0; j-- {
  310. b = append(b, symbol[j])
  311. }
  312. }
  313. // reverse
  314. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  315. b[i], b[j] = b[j], b[i]
  316. }
  317. if int(v) < 2 {
  318. if v == 0 {
  319. b = append(b, mr.decimal...)
  320. }
  321. for i := 0; i < 2-int(v); i++ {
  322. b = append(b, '0')
  323. }
  324. }
  325. return string(b)
  326. }
  327. // FmtDateShort returns the short date representation of 't' for 'mr'
  328. func (mr *mr) FmtDateShort(t time.Time) string {
  329. b := make([]byte, 0, 32)
  330. b = strconv.AppendInt(b, int64(t.Day()), 10)
  331. b = append(b, []byte{0x2f}...)
  332. b = strconv.AppendInt(b, int64(t.Month()), 10)
  333. b = append(b, []byte{0x2f}...)
  334. if t.Year() > 9 {
  335. b = append(b, strconv.Itoa(t.Year())[2:]...)
  336. } else {
  337. b = append(b, strconv.Itoa(t.Year())[1:]...)
  338. }
  339. return string(b)
  340. }
  341. // FmtDateMedium returns the medium date representation of 't' for 'mr'
  342. func (mr *mr) FmtDateMedium(t time.Time) string {
  343. b := make([]byte, 0, 32)
  344. b = strconv.AppendInt(b, int64(t.Day()), 10)
  345. b = append(b, []byte{0x20}...)
  346. b = append(b, mr.monthsAbbreviated[t.Month()]...)
  347. b = append(b, []byte{0x2c, 0x20}...)
  348. b = strconv.AppendInt(b, int64(t.Year()), 10)
  349. return string(b)
  350. }
  351. // FmtDateLong returns the long date representation of 't' for 'mr'
  352. func (mr *mr) FmtDateLong(t time.Time) string {
  353. b := make([]byte, 0, 32)
  354. b = strconv.AppendInt(b, int64(t.Day()), 10)
  355. b = append(b, []byte{0x20}...)
  356. b = append(b, mr.monthsWide[t.Month()]...)
  357. b = append(b, []byte{0x2c, 0x20}...)
  358. b = strconv.AppendInt(b, int64(t.Year()), 10)
  359. return string(b)
  360. }
  361. // FmtDateFull returns the full date representation of 't' for 'mr'
  362. func (mr *mr) FmtDateFull(t time.Time) string {
  363. b := make([]byte, 0, 32)
  364. b = append(b, mr.daysWide[t.Weekday()]...)
  365. b = append(b, []byte{0x2c, 0x20}...)
  366. b = strconv.AppendInt(b, int64(t.Day()), 10)
  367. b = append(b, []byte{0x20}...)
  368. b = append(b, mr.monthsWide[t.Month()]...)
  369. b = append(b, []byte{0x2c, 0x20}...)
  370. b = strconv.AppendInt(b, int64(t.Year()), 10)
  371. return string(b)
  372. }
  373. // FmtTimeShort returns the short time representation of 't' for 'mr'
  374. func (mr *mr) FmtTimeShort(t time.Time) string {
  375. b := make([]byte, 0, 32)
  376. h := t.Hour()
  377. if h > 12 {
  378. h -= 12
  379. }
  380. b = strconv.AppendInt(b, int64(h), 10)
  381. b = append(b, mr.timeSeparator...)
  382. if t.Minute() < 10 {
  383. b = append(b, '0')
  384. }
  385. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  386. b = append(b, []byte{0x20}...)
  387. if t.Hour() < 12 {
  388. b = append(b, mr.periodsAbbreviated[0]...)
  389. } else {
  390. b = append(b, mr.periodsAbbreviated[1]...)
  391. }
  392. return string(b)
  393. }
  394. // FmtTimeMedium returns the medium time representation of 't' for 'mr'
  395. func (mr *mr) FmtTimeMedium(t time.Time) string {
  396. b := make([]byte, 0, 32)
  397. h := t.Hour()
  398. if h > 12 {
  399. h -= 12
  400. }
  401. b = strconv.AppendInt(b, int64(h), 10)
  402. b = append(b, mr.timeSeparator...)
  403. if t.Minute() < 10 {
  404. b = append(b, '0')
  405. }
  406. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  407. b = append(b, mr.timeSeparator...)
  408. if t.Second() < 10 {
  409. b = append(b, '0')
  410. }
  411. b = strconv.AppendInt(b, int64(t.Second()), 10)
  412. b = append(b, []byte{0x20}...)
  413. if t.Hour() < 12 {
  414. b = append(b, mr.periodsAbbreviated[0]...)
  415. } else {
  416. b = append(b, mr.periodsAbbreviated[1]...)
  417. }
  418. return string(b)
  419. }
  420. // FmtTimeLong returns the long time representation of 't' for 'mr'
  421. func (mr *mr) FmtTimeLong(t time.Time) string {
  422. b := make([]byte, 0, 32)
  423. h := t.Hour()
  424. if h > 12 {
  425. h -= 12
  426. }
  427. b = strconv.AppendInt(b, int64(h), 10)
  428. b = append(b, mr.timeSeparator...)
  429. if t.Minute() < 10 {
  430. b = append(b, '0')
  431. }
  432. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  433. b = append(b, mr.timeSeparator...)
  434. if t.Second() < 10 {
  435. b = append(b, '0')
  436. }
  437. b = strconv.AppendInt(b, int64(t.Second()), 10)
  438. b = append(b, []byte{0x20}...)
  439. if t.Hour() < 12 {
  440. b = append(b, mr.periodsAbbreviated[0]...)
  441. } else {
  442. b = append(b, mr.periodsAbbreviated[1]...)
  443. }
  444. b = append(b, []byte{0x20}...)
  445. tz, _ := t.Zone()
  446. b = append(b, tz...)
  447. return string(b)
  448. }
  449. // FmtTimeFull returns the full time representation of 't' for 'mr'
  450. func (mr *mr) FmtTimeFull(t time.Time) string {
  451. b := make([]byte, 0, 32)
  452. h := t.Hour()
  453. if h > 12 {
  454. h -= 12
  455. }
  456. b = strconv.AppendInt(b, int64(h), 10)
  457. b = append(b, mr.timeSeparator...)
  458. if t.Minute() < 10 {
  459. b = append(b, '0')
  460. }
  461. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  462. b = append(b, mr.timeSeparator...)
  463. if t.Second() < 10 {
  464. b = append(b, '0')
  465. }
  466. b = strconv.AppendInt(b, int64(t.Second()), 10)
  467. b = append(b, []byte{0x20}...)
  468. if t.Hour() < 12 {
  469. b = append(b, mr.periodsAbbreviated[0]...)
  470. } else {
  471. b = append(b, mr.periodsAbbreviated[1]...)
  472. }
  473. b = append(b, []byte{0x20}...)
  474. tz, _ := t.Zone()
  475. if btz, ok := mr.timezones[tz]; ok {
  476. b = append(b, btz...)
  477. } else {
  478. b = append(b, tz...)
  479. }
  480. return string(b)
  481. }