ur.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. package ur
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ur 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. currencyPositivePrefix string
  23. currencyNegativePrefix 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 'ur' locale
  41. func New() locales.Translator {
  42. return &ur{
  43. locale: "ur",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: []locales.PluralRule{6},
  46. pluralsRange: []locales.PluralRule{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 ", "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", "Rs", "PLN", "PLZ ", "PTE ", "PYG", "QAR", "RHD ", "ROL ", "RON", "RSD", "RUB", "RUR ", "RWF", "SAR", "SBD", "SCR", "SDD ", "SDG", "SDP ", "SEK", "SGD", "SHP", "SIT ", "SKK ", "SLL", "SOS", "SRD", "SRG ", "SSP", "STD", "SUR ", "SVC ", "SYP", "SZL", "฿", "TJR ", "TJS", "TMM ", "TMT", "TND", "TOP", "TPE ", "TRL ", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK ", "UGS ", "UGX", "$", "USN ", "USS ", "UYI ", "UYP ", "UYU", "UZS", "VEB ", "VEF", "₫", "VNN ", "VUV", "WST", "FCFA", "XAG ", "XAU ", "XBA ", "XBB ", "XBC ", "XBD ", "EC$", "XDR ", "XEU ", "XFO ", "XFU ", "CFA", "XPD ", "CFPF", "XPT ", "XRE ", "XSU ", "XTS ", "XUA ", "XXX ", "YDD ", "YER", "YUD ", "YUM ", "YUN ", "YUR ", "ZAL ", "ZAR", "ZMK ", "ZMW", "ZRN ", "ZRZ ", "ZWD ", "ZWL ", "ZWR "},
  55. currencyPositivePrefix: " ",
  56. currencyNegativePrefix: " ",
  57. monthsAbbreviated: []string{"", "جنوری", "فروری", "مارچ", "اپریل", "مئی", "جون", "جولائی", "اگست", "ستمبر", "اکتوبر", "نومبر", "دسمبر"},
  58. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  59. monthsWide: []string{"", "جنوری", "فروری", "مارچ", "اپریل", "مئی", "جون", "جولائی", "اگست", "ستمبر", "اکتوبر", "نومبر", "دسمبر"},
  60. daysAbbreviated: []string{"اتوار", "سوموار", "منگل", "بدھ", "جمعرات", "جمعہ", "ہفتہ"},
  61. daysNarrow: []string{"S", "M", "T", "W", "T", "F", "S"},
  62. daysShort: []string{"اتوار", "سوموار", "منگل", "بدھ", "جمعرات", "جمعہ", "ہفتہ"},
  63. daysWide: []string{"اتوار", "سوموار", "منگل", "بدھ", "جمعرات", "جمعہ", "ہفتہ"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"a", "p"},
  66. periodsWide: []string{"قبل دوپہر", "بعد دوپہر"},
  67. erasAbbreviated: []string{"قبل مسیح", "عیسوی"},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"قبل مسیح", "عیسوی"},
  70. timezones: map[string]string{"MDT": "MDT", "JST": "جاپان سٹینڈرڈ ٹائم", "HAST": "ہوائی الیوٹیئن اسٹینڈرڈ ٹائم", "JDT": "جاپان ڈے لائٹ ٹائم", "NZST": "نیوزی لینڈ کا معیاری وقت", "EST": "ایسٹرن اسٹینڈرڈ ٹائم", "COST": "کولمبیا کا موسم گرما کا وقت", "HKT": "ہانگ کانگ سٹینڈرڈ ٹائم", "AKST": "الاسکا اسٹینڈرڈ ٹائم", "UYST": "یوروگوئے کا موسم گرما کا وقت", "VET": "وینزوئیلا کا وقت", "WIT": "مشرقی انڈونیشیا ٹائم", "IST": "ہندوستان کا معیاری وقت", "ART": "ارجنٹینا سٹینڈرڈ ٹائم", "ACWDT": "آسٹریلین سنٹرل ویسٹرن ڈے لائٹ ٹائم", "AEST": "آسٹریلین ایسٹرن اسٹینڈرڈ ٹائم", "HADT": "ہوائی الیوٹیئن ڈے لائٹ ٹائم", "GMT": "گرین وچ کا اصل وقت", "WAT": "مغربی افریقہ سٹینڈرڈ ٹائم", "OEZ": "مشرقی یورپ کا معیاری وقت", "TMT": "ترکمانستان کا معیاری وقت", "MYT": "ملیشیا ٹائم", "AWDT": "آسٹریلین ویسٹرن ڈے لائٹ ٹائم", "CHAST": "چیتھم اسٹینڈرڈ ٹائم", "AST": "اٹلانٹک اسٹینڈرڈ ٹائم", "CDT": "سنٹرل ڈے لائٹ ٹائم", "MESZ": "وسطی یورپ کا موسم گرما کا وقت", "WEZ": "مغربی یورپ کا معیاری وقت", "AKDT": "الاسکا ڈے لائٹ ٹائم", "BOT": "بولیویا کا وقت", "CHADT": "چیتھم ڈے لائٹ ٹائم", "WARST": "مغربی ارجنٹینا کا موسم گرما کا وقت", "GYT": "گیانا کا وقت", "AEDT": "آسٹریلین ایسٹرن ڈے لائٹ ٹائم", "CLST": "چلی کا موسم گرما کا وقت", "CAT": "وسطی افریقہ ٹائم", "HNT": "نیو فاؤنڈ لینڈ اسٹینڈرڈ ٹائم", "TMST": "ترکمانستان کا موسم گرما کا وقت", "EAT": "مشرقی افریقہ ٹائم", "LHDT": "لارڈ ہووے ڈے لائٹ ٹائم", "AWST": "آسٹریلیا ویسٹرن اسٹینڈرڈ ٹائم", "NZDT": "نیوزی لینڈ ڈے لائٹ ٹائم", "GFT": "فرینچ گیانا کا وقت", "MEZ": "وسطی یورپ کا معیاری وقت", "ADT": "اٹلانٹک ڈے لائٹ ٹائم", "SGT": "سنگاپور سٹینڈرڈ ٹائم", "HKST": "ہانگ کانگ سمر ٹائم", "PDT": "پیسفک ڈے لائٹ ٹائم", "WESZ": "مغربی یورپ کا موسم گرما کا وقت", "ECT": "ایکواڈور کا وقت", "WAST": "مغربی افریقہ سمر ٹائم", "WITA": "وسطی انڈونیشیا ٹائم", "CST": "سنٹرل اسٹینڈرڈ ٹائم", "ChST": "چامورو سٹینڈرڈ ٹائم", "ACWST": "آسٹریلین سنٹرل ویسٹرن اسٹینڈرڈ ٹائم", "COT": "کولمبیا کا معیاری وقت", "HAT": "نیو فاؤنڈ لینڈ ڈے لائٹ ٹائم", "∅∅∅": "امیزون کا موسم گرما کا وقت", "ACST": "آسٹریلین سنٹرل اسٹینڈرڈ ٹائم", "CLT": "چلی کا معیاری وقت", "MST": "MST", "PST": "پیسفک اسٹینڈرڈ ٹائم", "UYT": "یوروگوئے کا معیاری وقت", "SAST": "جنوبی افریقہ سٹینڈرڈ ٹائم", "OESZ": "مشرقی یورپ کا موسم گرما کا وقت", "ARST": "ارجنٹینا سمر ٹائم", "ACDT": "آسٹریلین سنٹرل ڈے لائٹ ٹائم", "LHST": "لارڈ ہووے اسٹینڈرڈ ٹائم", "SRT": "سورینام کا وقت", "BT": "بھوٹان کا وقت", "EDT": "ایسٹرن ڈے لائٹ ٹائم", "WART": "مغربی ارجنٹینا کا معیاری وقت", "WIB": "مغربی انڈونیشیا ٹائم"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (ur *ur) Locale() string {
  75. return ur.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'ur'
  78. func (ur *ur) PluralsCardinal() []locales.PluralRule {
  79. return ur.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ur'
  82. func (ur *ur) PluralsOrdinal() []locales.PluralRule {
  83. return ur.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'ur'
  86. func (ur *ur) PluralsRange() []locales.PluralRule {
  87. return ur.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ur'
  90. func (ur *ur) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. if i == 1 && v == 0 {
  94. return locales.PluralRuleOne
  95. }
  96. return locales.PluralRuleOther
  97. }
  98. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ur'
  99. func (ur *ur) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  100. return locales.PluralRuleOther
  101. }
  102. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ur'
  103. func (ur *ur) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  104. return locales.PluralRuleOther
  105. }
  106. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  107. func (ur *ur) MonthAbbreviated(month time.Month) string {
  108. return ur.monthsAbbreviated[month]
  109. }
  110. // MonthsAbbreviated returns the locales abbreviated months
  111. func (ur *ur) MonthsAbbreviated() []string {
  112. return ur.monthsAbbreviated[1:]
  113. }
  114. // MonthNarrow returns the locales narrow month given the 'month' provided
  115. func (ur *ur) MonthNarrow(month time.Month) string {
  116. return ur.monthsNarrow[month]
  117. }
  118. // MonthsNarrow returns the locales narrow months
  119. func (ur *ur) MonthsNarrow() []string {
  120. return ur.monthsNarrow[1:]
  121. }
  122. // MonthWide returns the locales wide month given the 'month' provided
  123. func (ur *ur) MonthWide(month time.Month) string {
  124. return ur.monthsWide[month]
  125. }
  126. // MonthsWide returns the locales wide months
  127. func (ur *ur) MonthsWide() []string {
  128. return ur.monthsWide[1:]
  129. }
  130. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  131. func (ur *ur) WeekdayAbbreviated(weekday time.Weekday) string {
  132. return ur.daysAbbreviated[weekday]
  133. }
  134. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  135. func (ur *ur) WeekdaysAbbreviated() []string {
  136. return ur.daysAbbreviated
  137. }
  138. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  139. func (ur *ur) WeekdayNarrow(weekday time.Weekday) string {
  140. return ur.daysNarrow[weekday]
  141. }
  142. // WeekdaysNarrow returns the locales narrow weekdays
  143. func (ur *ur) WeekdaysNarrow() []string {
  144. return ur.daysNarrow
  145. }
  146. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  147. func (ur *ur) WeekdayShort(weekday time.Weekday) string {
  148. return ur.daysShort[weekday]
  149. }
  150. // WeekdaysShort returns the locales short weekdays
  151. func (ur *ur) WeekdaysShort() []string {
  152. return ur.daysShort
  153. }
  154. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  155. func (ur *ur) WeekdayWide(weekday time.Weekday) string {
  156. return ur.daysWide[weekday]
  157. }
  158. // WeekdaysWide returns the locales wide weekdays
  159. func (ur *ur) WeekdaysWide() []string {
  160. return ur.daysWide
  161. }
  162. // FmtNumber returns 'num' with digits/precision of 'v' for 'ur' and handles both Whole and Real numbers based on 'v'
  163. func (ur *ur) FmtNumber(num float64, v uint64) string {
  164. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  165. l := len(s) + 8 + 1*len(s[:len(s)-int(v)-1])/3
  166. count := 0
  167. inWhole := v == 0
  168. b := make([]byte, 0, l)
  169. for i := len(s) - 1; i >= 0; i-- {
  170. if s[i] == '.' {
  171. b = append(b, ur.decimal[0])
  172. inWhole = true
  173. continue
  174. }
  175. if inWhole {
  176. if count == 3 {
  177. b = append(b, ur.group[0])
  178. count = 1
  179. } else {
  180. count++
  181. }
  182. }
  183. b = append(b, s[i])
  184. }
  185. if num < 0 {
  186. for j := len(ur.minus) - 1; j >= 0; j-- {
  187. b = append(b, ur.minus[j])
  188. }
  189. }
  190. // reverse
  191. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  192. b[i], b[j] = b[j], b[i]
  193. }
  194. return string(b)
  195. }
  196. // FmtPercent returns 'num' with digits/precision of 'v' for 'ur' and handles both Whole and Real numbers based on 'v'
  197. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  198. func (ur *ur) FmtPercent(num float64, v uint64) string {
  199. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  200. l := len(s) + 9
  201. b := make([]byte, 0, l)
  202. for i := len(s) - 1; i >= 0; i-- {
  203. if s[i] == '.' {
  204. b = append(b, ur.decimal[0])
  205. continue
  206. }
  207. b = append(b, s[i])
  208. }
  209. if num < 0 {
  210. for j := len(ur.minus) - 1; j >= 0; j-- {
  211. b = append(b, ur.minus[j])
  212. }
  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. b = append(b, ur.percent...)
  219. return string(b)
  220. }
  221. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ur'
  222. func (ur *ur) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  223. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  224. symbol := ur.currencies[currency]
  225. l := len(s) + len(symbol) + 10 + 1*len(s[:len(s)-int(v)-1])/3
  226. count := 0
  227. inWhole := v == 0
  228. inSecondary := false
  229. groupThreshold := 3
  230. b := make([]byte, 0, l)
  231. for i := len(s) - 1; i >= 0; i-- {
  232. if s[i] == '.' {
  233. b = append(b, ur.decimal[0])
  234. inWhole = true
  235. continue
  236. }
  237. if inWhole {
  238. if count == groupThreshold {
  239. b = append(b, ur.group[0])
  240. count = 1
  241. if !inSecondary {
  242. inSecondary = true
  243. groupThreshold = 2
  244. }
  245. } else {
  246. count++
  247. }
  248. }
  249. b = append(b, s[i])
  250. }
  251. for j := len(symbol) - 1; j >= 0; j-- {
  252. b = append(b, symbol[j])
  253. }
  254. for j := len(ur.currencyPositivePrefix) - 1; j >= 0; j-- {
  255. b = append(b, ur.currencyPositivePrefix[j])
  256. }
  257. if num < 0 {
  258. for j := len(ur.minus) - 1; j >= 0; j-- {
  259. b = append(b, ur.minus[j])
  260. }
  261. }
  262. // reverse
  263. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  264. b[i], b[j] = b[j], b[i]
  265. }
  266. if int(v) < 2 {
  267. if v == 0 {
  268. b = append(b, ur.decimal...)
  269. }
  270. for i := 0; i < 2-int(v); i++ {
  271. b = append(b, '0')
  272. }
  273. }
  274. return string(b)
  275. }
  276. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ur'
  277. // in accounting notation.
  278. func (ur *ur) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  279. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  280. symbol := ur.currencies[currency]
  281. l := len(s) + len(symbol) + 10 + 1*len(s[:len(s)-int(v)-1])/3
  282. count := 0
  283. inWhole := v == 0
  284. inSecondary := false
  285. groupThreshold := 3
  286. b := make([]byte, 0, l)
  287. for i := len(s) - 1; i >= 0; i-- {
  288. if s[i] == '.' {
  289. b = append(b, ur.decimal[0])
  290. inWhole = true
  291. continue
  292. }
  293. if inWhole {
  294. if count == groupThreshold {
  295. b = append(b, ur.group[0])
  296. count = 1
  297. if !inSecondary {
  298. inSecondary = true
  299. groupThreshold = 2
  300. }
  301. } else {
  302. count++
  303. }
  304. }
  305. b = append(b, s[i])
  306. }
  307. if num < 0 {
  308. for j := len(symbol) - 1; j >= 0; j-- {
  309. b = append(b, symbol[j])
  310. }
  311. for j := len(ur.currencyNegativePrefix) - 1; j >= 0; j-- {
  312. b = append(b, ur.currencyNegativePrefix[j])
  313. }
  314. for j := len(ur.minus) - 1; j >= 0; j-- {
  315. b = append(b, ur.minus[j])
  316. }
  317. } else {
  318. for j := len(symbol) - 1; j >= 0; j-- {
  319. b = append(b, symbol[j])
  320. }
  321. for j := len(ur.currencyPositivePrefix) - 1; j >= 0; j-- {
  322. b = append(b, ur.currencyPositivePrefix[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, ur.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 'ur'
  340. func (ur *ur) 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 'ur'
  354. func (ur *ur) 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, ur.monthsAbbreviated[t.Month()]...)
  359. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  360. b = strconv.AppendInt(b, int64(t.Year()), 10)
  361. return string(b)
  362. }
  363. // FmtDateLong returns the long date representation of 't' for 'ur'
  364. func (ur *ur) FmtDateLong(t time.Time) string {
  365. b := make([]byte, 0, 32)
  366. b = strconv.AppendInt(b, int64(t.Day()), 10)
  367. b = append(b, []byte{0x20}...)
  368. b = append(b, ur.monthsWide[t.Month()]...)
  369. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  370. b = strconv.AppendInt(b, int64(t.Year()), 10)
  371. return string(b)
  372. }
  373. // FmtDateFull returns the full date representation of 't' for 'ur'
  374. func (ur *ur) FmtDateFull(t time.Time) string {
  375. b := make([]byte, 0, 32)
  376. b = append(b, ur.daysWide[t.Weekday()]...)
  377. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  378. b = strconv.AppendInt(b, int64(t.Day()), 10)
  379. b = append(b, []byte{0x20}...)
  380. b = append(b, ur.monthsWide[t.Month()]...)
  381. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  382. b = strconv.AppendInt(b, int64(t.Year()), 10)
  383. return string(b)
  384. }
  385. // FmtTimeShort returns the short time representation of 't' for 'ur'
  386. func (ur *ur) FmtTimeShort(t time.Time) string {
  387. b := make([]byte, 0, 32)
  388. h := t.Hour()
  389. if h > 12 {
  390. h -= 12
  391. }
  392. b = strconv.AppendInt(b, int64(h), 10)
  393. b = append(b, ur.timeSeparator...)
  394. if t.Minute() < 10 {
  395. b = append(b, '0')
  396. }
  397. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  398. b = append(b, []byte{0x20}...)
  399. if t.Hour() < 12 {
  400. b = append(b, ur.periodsAbbreviated[0]...)
  401. } else {
  402. b = append(b, ur.periodsAbbreviated[1]...)
  403. }
  404. return string(b)
  405. }
  406. // FmtTimeMedium returns the medium time representation of 't' for 'ur'
  407. func (ur *ur) FmtTimeMedium(t time.Time) string {
  408. b := make([]byte, 0, 32)
  409. h := t.Hour()
  410. if h > 12 {
  411. h -= 12
  412. }
  413. b = strconv.AppendInt(b, int64(h), 10)
  414. b = append(b, ur.timeSeparator...)
  415. if t.Minute() < 10 {
  416. b = append(b, '0')
  417. }
  418. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  419. b = append(b, ur.timeSeparator...)
  420. if t.Second() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Second()), 10)
  424. b = append(b, []byte{0x20}...)
  425. if t.Hour() < 12 {
  426. b = append(b, ur.periodsAbbreviated[0]...)
  427. } else {
  428. b = append(b, ur.periodsAbbreviated[1]...)
  429. }
  430. return string(b)
  431. }
  432. // FmtTimeLong returns the long time representation of 't' for 'ur'
  433. func (ur *ur) FmtTimeLong(t time.Time) string {
  434. b := make([]byte, 0, 32)
  435. h := t.Hour()
  436. if h > 12 {
  437. h -= 12
  438. }
  439. b = strconv.AppendInt(b, int64(h), 10)
  440. b = append(b, ur.timeSeparator...)
  441. if t.Minute() < 10 {
  442. b = append(b, '0')
  443. }
  444. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  445. b = append(b, ur.timeSeparator...)
  446. if t.Second() < 10 {
  447. b = append(b, '0')
  448. }
  449. b = strconv.AppendInt(b, int64(t.Second()), 10)
  450. b = append(b, []byte{0x20}...)
  451. if t.Hour() < 12 {
  452. b = append(b, ur.periodsAbbreviated[0]...)
  453. } else {
  454. b = append(b, ur.periodsAbbreviated[1]...)
  455. }
  456. b = append(b, []byte{0x20}...)
  457. tz, _ := t.Zone()
  458. b = append(b, tz...)
  459. return string(b)
  460. }
  461. // FmtTimeFull returns the full time representation of 't' for 'ur'
  462. func (ur *ur) FmtTimeFull(t time.Time) string {
  463. b := make([]byte, 0, 32)
  464. h := t.Hour()
  465. if h > 12 {
  466. h -= 12
  467. }
  468. b = strconv.AppendInt(b, int64(h), 10)
  469. b = append(b, ur.timeSeparator...)
  470. if t.Minute() < 10 {
  471. b = append(b, '0')
  472. }
  473. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  474. b = append(b, ur.timeSeparator...)
  475. if t.Second() < 10 {
  476. b = append(b, '0')
  477. }
  478. b = strconv.AppendInt(b, int64(t.Second()), 10)
  479. b = append(b, []byte{0x20}...)
  480. if t.Hour() < 12 {
  481. b = append(b, ur.periodsAbbreviated[0]...)
  482. } else {
  483. b = append(b, ur.periodsAbbreviated[1]...)
  484. }
  485. b = append(b, []byte{0x20}...)
  486. tz, _ := t.Zone()
  487. if btz, ok := ur.timezones[tz]; ok {
  488. b = append(b, btz...)
  489. } else {
  490. b = append(b, tz...)
  491. }
  492. return string(b)
  493. }