mr.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "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", "STN", "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{"AEST": "ऑस्ट्रेलियन पूर्व प्रमाण वेळ", "AEDT": "ऑस्ट्रेलियन पूर्व सूर्यप्रकाश वेळ", "SGT": "सिंगापूर प्रमाण वेळ", "WART": "पश्चिमी अर्जेंटिना प्रमाण वेळ", "VET": "व्हेनेझुएला वेळ", "HENOMX": "वायव्य मेक्सिको सूर्यप्रकाश वेळ", "SRT": "सुरिनाम वेळ", "COST": "कोलंबिया उन्हाळी वेळ", "HKT": "हाँग काँग प्रमाण वेळ", "CLST": "चिली उन्हाळी वेळ", "PDT": "पॅसिफिक सूर्यप्रकाश वेळ", "GFT": "फ्रेंच गयाना वेळ", "HNOG": "पश्चिम ग्रीनलँड प्रमाण वेळ", "HEOG": "पश्चिम ग्रीनलँड उन्हाळी वेळ", "MESZ": "मध्\u200dय युरोपियन उन्हाळी वेळ", "TMT": "तुर्कमेनिस्तान प्रमाण वेळ", "UYT": "उरुग्वे प्रमाण वेळ", "ECT": "इक्वेडोर वेळ", "WARST": "पश्चिमी अर्जेंटिना उन्हाळी वेळ", "CLT": "चिली प्रमाण वेळ", "AWDT": "ऑस्ट्रेलियन पश्चिम सूर्यप्रकाश वेळ", "HEPM": "सेंट पियरे आणि मिक्वेलोन सूर्यप्रकाश वेळ", "WITA": "मध्\u200dय इंडोनेशिया वेळ", "MDT": "मकाऊ ग्रीष्मकालीन वेळ", "EAT": "पूर्व आफ्रिका वेळ", "HNCU": "क्यूबा प्रमाण वेळ", "AST": "अटलांटिक प्रमाण वेळ", "AKST": "अलास्का प्रमाण वेळ", "LHST": "लॉर्ड होवे प्रमाण वेळ", "HAT": "न्यू फाउंडलंड सूर्यप्रकाश वेळ", "PST": "पॅसिफिक प्रमाण वेळ", "WIB": "पश्चिमी इंडोनेशिया वेळ", "MST": "मकाऊ प्रमाणवेळ", "WIT": "पौर्वात्य इंडोनेशिया वेळ", "HADT": "हवाई-अलूशन सूर्यप्रकाश वेळ", "GMT": "ग्रीनिच प्रमाण वेळ", "CHAST": "चॅथम प्रमाण वेळ", "CHADT": "चॅथम सूर्यप्रकाश वेळ", "JDT": "जपान सूर्यप्रकाश वेळ", "ACST": "ऑस्ट्रेलियन मध्य प्रमाण वेळ", "ACDT": "ऑस्ट्रेलियन मध्य सूर्यप्रकाश वेळ", "TMST": "तुर्कमेनिस्तान उन्हाळी वेळ", "ART": "अर्जेंटिना प्रमाण वेळ", "HNPM": "सेंट पियरे आणि मिक्वेलोन प्रमाण वेळ", "HECU": "क्यूबा सूर्यप्रकाश वेळ", "CDT": "केंद्रीय सूर्यप्रकाश वेळ", "HNPMX": "मेक्सिको पॅसिफिक प्रमाण वेळ", "WESZ": "पश्चिम युरोपियन उन्हाळी वेळ", "MYT": "मलेशिया वेळ", "AKDT": "अलास्का सूर्यप्रकाश वेळ", "ACWST": "ऑस्ट्रेलियन मध्य-पश्चिम प्रमाण वेळ", "MEZ": "मध्\u200dय युरोपियन प्रमाण वेळ", "SAST": "दक्षिण आफ्रिका प्रमाण वेळ", "WAT": "पश्चिम आफ्रिका प्रमाण वेळ", "NZDT": "न्यूझीलंड सूर्यप्रकाश वेळ", "EST": "पौर्वात्य प्रमाण वेळ", "HEEG": "पूर्व ग्रीनलँड उन्हाळी वेळ", "GYT": "गयाना वेळ", "ChST": "चामोरो प्रमाण वेळ", "AWST": "ऑस्ट्रेलियन पश्चिम प्रमाण वेळ", "HKST": "हाँग काँग उन्हाळी वेळ", "LHDT": "लॉर्ड होवे सूर्यप्रकाश वेळ", "OEZ": "पूर्व युरोपियन प्रमाण वेळ", "HAST": "हवाई-अलूशन प्रमाण वेळ", "UYST": "उरुग्वे उन्हाळी वेळ", "BOT": "बोलिव्हिया वेळ", "HNEG": "पूर्व ग्रीनलँड प्रमाण वेळ", "HNT": "न्यू फाउंडलंड प्रमाण वेळ", "OESZ": "पूर्व युरोपियन उन्हाळी वेळ", "WAST": "पश्चिम आफ्रिका उन्हाळी वेळ", "WEZ": "पश्चिम युरोपियन प्रमाण वेळ", "HNNOMX": "वायव्य मेक्सिको प्रमाण वेळ", "HEPMX": "मेक्सिको पॅसिफिक सूर्यप्रकाश वेळ", "JST": "जपान प्रमाण वेळ", "EDT": "पौर्वात्य सूर्यप्रकाश वेळ", "IST": "भारतीय प्रमाण वेळ", "ARST": "अर्जेंटिना उन्हाळी वेळ", "CST": "केंद्रीय प्रमाण वेळ", "ADT": "अटलांटिक सूर्यप्रकाश वेळ", "BT": "भूतान वेळ", "NZST": "न्यूझीलंड प्रमाण वेळ", "ACWDT": "ऑस्ट्रेलियन मध्य-पश्चिम सूर्यप्रकाश वेळ", "∅∅∅": "अ\u200dॅझोरेस उन्हाळी वेळ", "CAT": "मध्\u200dय आफ्रिका वेळ", "COT": "कोलंबिया प्रमाण वेळ"},
  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. // Decimal returns the decimal point of number
  174. func (mr *mr) Decimal() string {
  175. return mr.decimal
  176. }
  177. // Group returns the group of number
  178. func (mr *mr) Group() string {
  179. return mr.group
  180. }
  181. // Group returns the minus sign of number
  182. func (mr *mr) Minus() string {
  183. return mr.minus
  184. }
  185. // FmtNumber returns 'num' with digits/precision of 'v' for 'mr' and handles both Whole and Real numbers based on 'v'
  186. func (mr *mr) FmtNumber(num float64, v uint64) string {
  187. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  188. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  189. count := 0
  190. inWhole := v == 0
  191. inSecondary := false
  192. groupThreshold := 3
  193. b := make([]byte, 0, l)
  194. for i := len(s) - 1; i >= 0; i-- {
  195. if s[i] == '.' {
  196. b = append(b, mr.decimal[0])
  197. inWhole = true
  198. continue
  199. }
  200. if inWhole {
  201. if count == groupThreshold {
  202. b = append(b, mr.group[0])
  203. count = 1
  204. if !inSecondary {
  205. inSecondary = true
  206. groupThreshold = 2
  207. }
  208. } else {
  209. count++
  210. }
  211. }
  212. b = append(b, s[i])
  213. }
  214. if num < 0 {
  215. b = append(b, mr.minus[0])
  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 'mr' 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 (mr *mr) FmtPercent(num float64, v uint64) string {
  226. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  227. l := len(s) + 3
  228. b := make([]byte, 0, l)
  229. for i := len(s) - 1; i >= 0; i-- {
  230. if s[i] == '.' {
  231. b = append(b, mr.decimal[0])
  232. continue
  233. }
  234. b = append(b, s[i])
  235. }
  236. if num < 0 {
  237. b = append(b, mr.minus[0])
  238. }
  239. // reverse
  240. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  241. b[i], b[j] = b[j], b[i]
  242. }
  243. b = append(b, mr.percent...)
  244. return string(b)
  245. }
  246. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mr'
  247. func (mr *mr) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  248. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  249. symbol := mr.currencies[currency]
  250. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  251. count := 0
  252. inWhole := v == 0
  253. b := make([]byte, 0, l)
  254. for i := len(s) - 1; i >= 0; i-- {
  255. if s[i] == '.' {
  256. b = append(b, mr.decimal[0])
  257. inWhole = true
  258. continue
  259. }
  260. if inWhole {
  261. if count == 3 {
  262. b = append(b, mr.group[0])
  263. count = 1
  264. } else {
  265. count++
  266. }
  267. }
  268. b = append(b, s[i])
  269. }
  270. for j := len(symbol) - 1; j >= 0; j-- {
  271. b = append(b, symbol[j])
  272. }
  273. if num < 0 {
  274. b = append(b, mr.minus[0])
  275. }
  276. // reverse
  277. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  278. b[i], b[j] = b[j], b[i]
  279. }
  280. if int(v) < 2 {
  281. if v == 0 {
  282. b = append(b, mr.decimal...)
  283. }
  284. for i := 0; i < 2-int(v); i++ {
  285. b = append(b, '0')
  286. }
  287. }
  288. return string(b)
  289. }
  290. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mr'
  291. // in accounting notation.
  292. func (mr *mr) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  293. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  294. symbol := mr.currencies[currency]
  295. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  296. count := 0
  297. inWhole := v == 0
  298. b := make([]byte, 0, l)
  299. for i := len(s) - 1; i >= 0; i-- {
  300. if s[i] == '.' {
  301. b = append(b, mr.decimal[0])
  302. inWhole = true
  303. continue
  304. }
  305. if inWhole {
  306. if count == 3 {
  307. b = append(b, mr.group[0])
  308. count = 1
  309. } else {
  310. count++
  311. }
  312. }
  313. b = append(b, s[i])
  314. }
  315. if num < 0 {
  316. for j := len(symbol) - 1; j >= 0; j-- {
  317. b = append(b, symbol[j])
  318. }
  319. b = append(b, mr.minus[0])
  320. } else {
  321. for j := len(symbol) - 1; j >= 0; j-- {
  322. b = append(b, symbol[j])
  323. }
  324. }
  325. // reverse
  326. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  327. b[i], b[j] = b[j], b[i]
  328. }
  329. if int(v) < 2 {
  330. if v == 0 {
  331. b = append(b, mr.decimal...)
  332. }
  333. for i := 0; i < 2-int(v); i++ {
  334. b = append(b, '0')
  335. }
  336. }
  337. return string(b)
  338. }
  339. // FmtDateShort returns the short date representation of 't' for 'mr'
  340. func (mr *mr) FmtDateShort(t time.Time) string {
  341. b := make([]byte, 0, 32)
  342. b = strconv.AppendInt(b, int64(t.Day()), 10)
  343. b = append(b, []byte{0x2f}...)
  344. b = strconv.AppendInt(b, int64(t.Month()), 10)
  345. b = append(b, []byte{0x2f}...)
  346. if t.Year() > 9 {
  347. b = append(b, strconv.Itoa(t.Year())[2:]...)
  348. } else {
  349. b = append(b, strconv.Itoa(t.Year())[1:]...)
  350. }
  351. return string(b)
  352. }
  353. // FmtDateMedium returns the medium date representation of 't' for 'mr'
  354. func (mr *mr) FmtDateMedium(t time.Time) string {
  355. b := make([]byte, 0, 32)
  356. b = strconv.AppendInt(b, int64(t.Day()), 10)
  357. b = append(b, []byte{0x20}...)
  358. b = append(b, mr.monthsAbbreviated[t.Month()]...)
  359. b = append(b, []byte{0x2c, 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. return string(b)
  366. }
  367. // FmtDateLong returns the long date representation of 't' for 'mr'
  368. func (mr *mr) FmtDateLong(t time.Time) string {
  369. b := make([]byte, 0, 32)
  370. b = strconv.AppendInt(b, int64(t.Day()), 10)
  371. b = append(b, []byte{0x20}...)
  372. b = append(b, mr.monthsWide[t.Month()]...)
  373. b = append(b, []byte{0x2c, 0x20}...)
  374. if t.Year() > 0 {
  375. b = strconv.AppendInt(b, int64(t.Year()), 10)
  376. } else {
  377. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  378. }
  379. return string(b)
  380. }
  381. // FmtDateFull returns the full date representation of 't' for 'mr'
  382. func (mr *mr) FmtDateFull(t time.Time) string {
  383. b := make([]byte, 0, 32)
  384. b = append(b, mr.daysWide[t.Weekday()]...)
  385. b = append(b, []byte{0x2c, 0x20}...)
  386. b = strconv.AppendInt(b, int64(t.Day()), 10)
  387. b = append(b, []byte{0x20}...)
  388. b = append(b, mr.monthsWide[t.Month()]...)
  389. b = append(b, []byte{0x2c, 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. return string(b)
  396. }
  397. // FmtTimeShort returns the short time representation of 't' for 'mr'
  398. func (mr *mr) FmtTimeShort(t time.Time) string {
  399. b := make([]byte, 0, 32)
  400. h := t.Hour()
  401. if h > 12 {
  402. h -= 12
  403. }
  404. b = strconv.AppendInt(b, int64(h), 10)
  405. b = append(b, mr.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, []byte{0x20}...)
  411. if t.Hour() < 12 {
  412. b = append(b, mr.periodsAbbreviated[0]...)
  413. } else {
  414. b = append(b, mr.periodsAbbreviated[1]...)
  415. }
  416. return string(b)
  417. }
  418. // FmtTimeMedium returns the medium time representation of 't' for 'mr'
  419. func (mr *mr) FmtTimeMedium(t time.Time) string {
  420. b := make([]byte, 0, 32)
  421. h := t.Hour()
  422. if h > 12 {
  423. h -= 12
  424. }
  425. b = strconv.AppendInt(b, int64(h), 10)
  426. b = append(b, mr.timeSeparator...)
  427. if t.Minute() < 10 {
  428. b = append(b, '0')
  429. }
  430. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  431. b = append(b, mr.timeSeparator...)
  432. if t.Second() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Second()), 10)
  436. b = append(b, []byte{0x20}...)
  437. if t.Hour() < 12 {
  438. b = append(b, mr.periodsAbbreviated[0]...)
  439. } else {
  440. b = append(b, mr.periodsAbbreviated[1]...)
  441. }
  442. return string(b)
  443. }
  444. // FmtTimeLong returns the long time representation of 't' for 'mr'
  445. func (mr *mr) FmtTimeLong(t time.Time) string {
  446. b := make([]byte, 0, 32)
  447. h := t.Hour()
  448. if h > 12 {
  449. h -= 12
  450. }
  451. b = strconv.AppendInt(b, int64(h), 10)
  452. b = append(b, mr.timeSeparator...)
  453. if t.Minute() < 10 {
  454. b = append(b, '0')
  455. }
  456. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  457. b = append(b, mr.timeSeparator...)
  458. if t.Second() < 10 {
  459. b = append(b, '0')
  460. }
  461. b = strconv.AppendInt(b, int64(t.Second()), 10)
  462. b = append(b, []byte{0x20}...)
  463. if t.Hour() < 12 {
  464. b = append(b, mr.periodsAbbreviated[0]...)
  465. } else {
  466. b = append(b, mr.periodsAbbreviated[1]...)
  467. }
  468. b = append(b, []byte{0x20}...)
  469. tz, _ := t.Zone()
  470. b = append(b, tz...)
  471. return string(b)
  472. }
  473. // FmtTimeFull returns the full time representation of 't' for 'mr'
  474. func (mr *mr) FmtTimeFull(t time.Time) string {
  475. b := make([]byte, 0, 32)
  476. h := t.Hour()
  477. if h > 12 {
  478. h -= 12
  479. }
  480. b = strconv.AppendInt(b, int64(h), 10)
  481. b = append(b, mr.timeSeparator...)
  482. if t.Minute() < 10 {
  483. b = append(b, '0')
  484. }
  485. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  486. b = append(b, mr.timeSeparator...)
  487. if t.Second() < 10 {
  488. b = append(b, '0')
  489. }
  490. b = strconv.AppendInt(b, int64(t.Second()), 10)
  491. b = append(b, []byte{0x20}...)
  492. if t.Hour() < 12 {
  493. b = append(b, mr.periodsAbbreviated[0]...)
  494. } else {
  495. b = append(b, mr.periodsAbbreviated[1]...)
  496. }
  497. b = append(b, []byte{0x20}...)
  498. tz, _ := t.Zone()
  499. if btz, ok := mr.timezones[tz]; ok {
  500. b = append(b, btz...)
  501. } else {
  502. b = append(b, tz...)
  503. }
  504. return string(b)
  505. }