sd.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. package sd
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type sd 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 'sd' locale
  41. func New() locales.Translator {
  42. return &sd{
  43. locale: "sd",
  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", "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", "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", "STN", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "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{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  59. monthsWide: []string{"", "جنوري", "فيبروري", "مارچ", "اپريل", "مئي", "جون", "جولاءِ", "آگسٽ", "سيپٽمبر", "آڪٽوبر", "نومبر", "ڊسمبر"},
  60. daysAbbreviated: []string{"آچر", "سومر", "اڱارو", "اربع", "خميس", "جمعو", "ڇنڇر"},
  61. daysNarrow: []string{"آچر", "سو", "اڱارو", "اربع", "خم", "جمعو", "ڇنڇر"},
  62. daysShort: []string{"آچر", "سومر", "اڱارو", "اربع", "خميس", "جمعو", "ڇنڇر"},
  63. daysWide: []string{"آچر", "سومر", "اڱارو", "اربع", "خميس", "جمعو", "ڇنڇر"},
  64. periodsAbbreviated: []string{"صبح، منجهند", "شام، منجهند"},
  65. periodsNarrow: []string{"صبح، منجهند", "منجهند، شام"},
  66. periodsWide: []string{"صبح، منجهند", "منجهند، شام"},
  67. erasAbbreviated: []string{"BCE", "CE"},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"مسيح کان اڳ", "عيسوي کان پهرين"},
  70. timezones: map[string]string{"AST": "ايٽلانٽڪ جو معياري وقت", "ADT": "ايٽلانٽڪ جي ڏينهن جو وقت", "MYT": "ملائيشيا جو وقت", "MESZ": "مرڪزي يورپي اونهاري جو وقت", "CLST": "چلي جي اونهاري جو وقت", "COT": "ڪولمبيا جو معياري وقت", "GFT": "فرانسيسي گيانا جو وقت", "ACWST": "آسٽريليا جو مرڪزي مغربي معياري وقت", "HEOG": "مغربي گرين لينڊ جي اونهاري جو وقت", "MEZ": "مرڪزي يورپي معياري وقت", "HKT": "هانگ ڪانگ جو معياري وقت", "WITA": "مرڪزي انڊونيشيا جو وقت", "HNOG": "مغربي گرين لينڊ جو معياري وقت", "CHAST": "چئٿم جو معياري وقت", "VET": "وينزويلا جو وقت", "TMT": "ترڪمانستان جو معياري وقت", "GMT": "گرين وچ مين ٽائيم", "IST": "ڀارت جو معياري وقت", "SRT": "سوري نام جو وقت", "HNCU": "ڪيوبا جو معياري وقت", "∅∅∅": "براسيليا جي اونهاري جو وقت", "HEPMX": "ميڪسيڪن پيسيفڪ جي ڏينهن جو وقت", "MDT": "پهاڙي ڏينهن جو وقت", "NZDT": "نيوزيلينڊ جي ڏينهن جو وقت", "EDT": "مشرقي ڏينهن جو وقت", "TMST": "ترڪمانستان جي اونهاري جو وقت", "ARST": "ارجنٽائن جي اونهاري جو وقت", "CDT": "مرڪزي ڏينهن جو وقت", "PDT": "پيسيفڪ ڏينهن جو وقت", "MST": "پهاڙي معياري وقت", "LHST": "لورڊ هووي جو معياري وقت", "HENOMX": "شمالي مغربي ميڪسيڪو جي ڏينهن جو وقت", "GYT": "گیانا جو وقت", "CHADT": "چئٿم جي ڏينهن جو وقت", "CST": "مرڪزي معياري وقت", "JST": "جاپان جو معياري وقت", "ACST": "آسٽريليا جو مرڪزي معياري وقت", "HAT": "نيو فائونڊ لينڊ جي ڏينهن جو وقت", "EAT": "اوڀر آفريڪا جو وقت", "WIT": "اوڀر انڊونيشيا جو وقت", "OEZ": "مشرقي يورپي معياري وقت", "UYT": "يوروگائي جو معياري وقت", "HNT": "نيو فائونڊ لينڊ جو معياري وقت", "HAST": "هوائي اليوٽين جو معياري وقت", "AEDT": "آسٽريليا جو مشرقي ڏينهن جو وقت", "WAT": "اولهه آفريقا جو معياري وقت", "BOT": "بولیویا جو وقت", "ACDT": "آسٽريليا جو مرڪزي ڏينهن جو وقت", "ACWDT": "آسٽريليا جو مرڪزي مغربي ڏينهن جو وقت", "WART": "مغربي ارجنٽائن جو معياري وقت", "ART": "ارجنٽائن معياري وقت", "ChST": "چمورو جو معياري وقت", "HNPMX": "ميڪسيڪن پيسيفڪ جو معياري وقت", "SAST": "ڏکڻ آفريڪا جو معياري وقت", "HKST": "هانگ ڪانگ جي اونهاري جو وقت", "HNPM": "سینٽ پیئر و میڪوئیلون جو معياري وقت", "HNNOMX": "شمالي مغربي ميڪسيڪو جو معياري وقت", "HADT": "هوائي اليوٽين جي ڏينهن جو وقت", "PST": "پيسيفڪ معياري وقت", "WESZ": "مغربي يورپي ڏينهن جو وقت", "JDT": "جاپان جي ڏينهن جو وقت", "OESZ": "مشرقي يورپي اونهاري جو وقت", "AWDT": "آسٽريليا جو مغربي ڏينهن جو وقت", "NZST": "نيوزيلينڊ جو معياري وقت", "AKDT": "الاسڪا جي ڏينهن جو وقت", "SGT": "سنگاپور جو معياري وقت", "AWST": "آسٽريليا جو مغربي معياري وقت", "WAST": "اولهه آفريقا جي اونهاري جو وقت", "AKST": "الاسڪا جو معياري وقت", "HEPM": "سینٽ پیئر و میڪوئیلون جي ڏينهن جو وقت", "AEST": "آسٽريليا جو مشرقي معياري وقت", "WEZ": "مغربي يورپي معياري وقت", "WIB": "اولهه انڊونيشيا جو وقت", "HEEG": "مشرقي گرين لينڊ جي اونهاري جو وقت", "COST": "ڪولمبيا جي اونهاري جو وقت", "UYST": "يوروگائي جي اونهاري جو وقت", "HECU": "ڪيوبا جي ڏينهن جو وقت", "BT": "ڀوٽان جو وقت", "ECT": "ايڪواڊور جو وقت", "EST": "مشرقي معياري وقت", "HNEG": "مشرقي گرين لينڊ جو معياري وقت", "LHDT": "لورڊ هووي جي ڏينهن جو وقت", "WARST": "مغربي ارجنٽائن جي اونهاري جو وقت", "CAT": "مرڪزي آفريقا جو وقت", "CLT": "چلي جو معياري وقت"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (sd *sd) Locale() string {
  75. return sd.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'sd'
  78. func (sd *sd) PluralsCardinal() []locales.PluralRule {
  79. return sd.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'sd'
  82. func (sd *sd) PluralsOrdinal() []locales.PluralRule {
  83. return sd.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'sd'
  86. func (sd *sd) PluralsRange() []locales.PluralRule {
  87. return sd.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'sd'
  90. func (sd *sd) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. if n == 1 {
  93. return locales.PluralRuleOne
  94. }
  95. return locales.PluralRuleOther
  96. }
  97. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'sd'
  98. func (sd *sd) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  99. return locales.PluralRuleOther
  100. }
  101. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'sd'
  102. func (sd *sd) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  103. return locales.PluralRuleOther
  104. }
  105. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  106. func (sd *sd) MonthAbbreviated(month time.Month) string {
  107. return sd.monthsAbbreviated[month]
  108. }
  109. // MonthsAbbreviated returns the locales abbreviated months
  110. func (sd *sd) MonthsAbbreviated() []string {
  111. return sd.monthsAbbreviated[1:]
  112. }
  113. // MonthNarrow returns the locales narrow month given the 'month' provided
  114. func (sd *sd) MonthNarrow(month time.Month) string {
  115. return sd.monthsNarrow[month]
  116. }
  117. // MonthsNarrow returns the locales narrow months
  118. func (sd *sd) MonthsNarrow() []string {
  119. return sd.monthsNarrow[1:]
  120. }
  121. // MonthWide returns the locales wide month given the 'month' provided
  122. func (sd *sd) MonthWide(month time.Month) string {
  123. return sd.monthsWide[month]
  124. }
  125. // MonthsWide returns the locales wide months
  126. func (sd *sd) MonthsWide() []string {
  127. return sd.monthsWide[1:]
  128. }
  129. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  130. func (sd *sd) WeekdayAbbreviated(weekday time.Weekday) string {
  131. return sd.daysAbbreviated[weekday]
  132. }
  133. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  134. func (sd *sd) WeekdaysAbbreviated() []string {
  135. return sd.daysAbbreviated
  136. }
  137. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  138. func (sd *sd) WeekdayNarrow(weekday time.Weekday) string {
  139. return sd.daysNarrow[weekday]
  140. }
  141. // WeekdaysNarrow returns the locales narrow weekdays
  142. func (sd *sd) WeekdaysNarrow() []string {
  143. return sd.daysNarrow
  144. }
  145. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  146. func (sd *sd) WeekdayShort(weekday time.Weekday) string {
  147. return sd.daysShort[weekday]
  148. }
  149. // WeekdaysShort returns the locales short weekdays
  150. func (sd *sd) WeekdaysShort() []string {
  151. return sd.daysShort
  152. }
  153. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  154. func (sd *sd) WeekdayWide(weekday time.Weekday) string {
  155. return sd.daysWide[weekday]
  156. }
  157. // WeekdaysWide returns the locales wide weekdays
  158. func (sd *sd) WeekdaysWide() []string {
  159. return sd.daysWide
  160. }
  161. // Decimal returns the decimal point of number
  162. func (sd *sd) Decimal() string {
  163. return sd.decimal
  164. }
  165. // Group returns the group of number
  166. func (sd *sd) Group() string {
  167. return sd.group
  168. }
  169. // Group returns the minus sign of number
  170. func (sd *sd) Minus() string {
  171. return sd.minus
  172. }
  173. // FmtNumber returns 'num' with digits/precision of 'v' for 'sd' and handles both Whole and Real numbers based on 'v'
  174. func (sd *sd) 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. b := make([]byte, 0, l)
  180. for i := len(s) - 1; i >= 0; i-- {
  181. if s[i] == '.' {
  182. b = append(b, sd.decimal[0])
  183. inWhole = true
  184. continue
  185. }
  186. if inWhole {
  187. if count == 3 {
  188. b = append(b, sd.group[0])
  189. count = 1
  190. } else {
  191. count++
  192. }
  193. }
  194. b = append(b, s[i])
  195. }
  196. if num < 0 {
  197. b = append(b, sd.minus[0])
  198. }
  199. // reverse
  200. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  201. b[i], b[j] = b[j], b[i]
  202. }
  203. return string(b)
  204. }
  205. // FmtPercent returns 'num' with digits/precision of 'v' for 'sd' and handles both Whole and Real numbers based on 'v'
  206. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  207. func (sd *sd) FmtPercent(num float64, v uint64) string {
  208. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  209. l := len(s) + 3
  210. b := make([]byte, 0, l)
  211. for i := len(s) - 1; i >= 0; i-- {
  212. if s[i] == '.' {
  213. b = append(b, sd.decimal[0])
  214. continue
  215. }
  216. b = append(b, s[i])
  217. }
  218. if num < 0 {
  219. b = append(b, sd.minus[0])
  220. }
  221. // reverse
  222. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  223. b[i], b[j] = b[j], b[i]
  224. }
  225. b = append(b, sd.percent...)
  226. return string(b)
  227. }
  228. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'sd'
  229. func (sd *sd) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  230. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  231. symbol := sd.currencies[currency]
  232. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  233. count := 0
  234. inWhole := v == 0
  235. b := make([]byte, 0, l)
  236. for i := len(s) - 1; i >= 0; i-- {
  237. if s[i] == '.' {
  238. b = append(b, sd.decimal[0])
  239. inWhole = true
  240. continue
  241. }
  242. if inWhole {
  243. if count == 3 {
  244. b = append(b, sd.group[0])
  245. count = 1
  246. } else {
  247. count++
  248. }
  249. }
  250. b = append(b, s[i])
  251. }
  252. for j := len(symbol) - 1; j >= 0; j-- {
  253. b = append(b, symbol[j])
  254. }
  255. for j := len(sd.currencyPositivePrefix) - 1; j >= 0; j-- {
  256. b = append(b, sd.currencyPositivePrefix[j])
  257. }
  258. if num < 0 {
  259. b = append(b, sd.minus[0])
  260. }
  261. // reverse
  262. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  263. b[i], b[j] = b[j], b[i]
  264. }
  265. if int(v) < 2 {
  266. if v == 0 {
  267. b = append(b, sd.decimal...)
  268. }
  269. for i := 0; i < 2-int(v); i++ {
  270. b = append(b, '0')
  271. }
  272. }
  273. return string(b)
  274. }
  275. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'sd'
  276. // in accounting notation.
  277. func (sd *sd) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  278. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  279. symbol := sd.currencies[currency]
  280. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  281. count := 0
  282. inWhole := v == 0
  283. b := make([]byte, 0, l)
  284. for i := len(s) - 1; i >= 0; i-- {
  285. if s[i] == '.' {
  286. b = append(b, sd.decimal[0])
  287. inWhole = true
  288. continue
  289. }
  290. if inWhole {
  291. if count == 3 {
  292. b = append(b, sd.group[0])
  293. count = 1
  294. } else {
  295. count++
  296. }
  297. }
  298. b = append(b, s[i])
  299. }
  300. if num < 0 {
  301. for j := len(symbol) - 1; j >= 0; j-- {
  302. b = append(b, symbol[j])
  303. }
  304. for j := len(sd.currencyNegativePrefix) - 1; j >= 0; j-- {
  305. b = append(b, sd.currencyNegativePrefix[j])
  306. }
  307. b = append(b, sd.minus[0])
  308. } else {
  309. for j := len(symbol) - 1; j >= 0; j-- {
  310. b = append(b, symbol[j])
  311. }
  312. for j := len(sd.currencyPositivePrefix) - 1; j >= 0; j-- {
  313. b = append(b, sd.currencyPositivePrefix[j])
  314. }
  315. }
  316. // reverse
  317. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  318. b[i], b[j] = b[j], b[i]
  319. }
  320. if int(v) < 2 {
  321. if v == 0 {
  322. b = append(b, sd.decimal...)
  323. }
  324. for i := 0; i < 2-int(v); i++ {
  325. b = append(b, '0')
  326. }
  327. }
  328. return string(b)
  329. }
  330. // FmtDateShort returns the short date representation of 't' for 'sd'
  331. func (sd *sd) FmtDateShort(t time.Time) string {
  332. b := make([]byte, 0, 32)
  333. if t.Year() > 0 {
  334. b = strconv.AppendInt(b, int64(t.Year()), 10)
  335. } else {
  336. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  337. }
  338. b = append(b, []byte{0x2d}...)
  339. if t.Month() < 10 {
  340. b = append(b, '0')
  341. }
  342. b = strconv.AppendInt(b, int64(t.Month()), 10)
  343. b = append(b, []byte{0x2d}...)
  344. if t.Day() < 10 {
  345. b = append(b, '0')
  346. }
  347. b = strconv.AppendInt(b, int64(t.Day()), 10)
  348. return string(b)
  349. }
  350. // FmtDateMedium returns the medium date representation of 't' for 'sd'
  351. func (sd *sd) FmtDateMedium(t time.Time) string {
  352. b := make([]byte, 0, 32)
  353. if t.Year() > 0 {
  354. b = strconv.AppendInt(b, int64(t.Year()), 10)
  355. } else {
  356. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  357. }
  358. b = append(b, []byte{0x20}...)
  359. b = append(b, sd.monthsAbbreviated[t.Month()]...)
  360. b = append(b, []byte{0x20}...)
  361. b = strconv.AppendInt(b, int64(t.Day()), 10)
  362. return string(b)
  363. }
  364. // FmtDateLong returns the long date representation of 't' for 'sd'
  365. func (sd *sd) FmtDateLong(t time.Time) string {
  366. b := make([]byte, 0, 32)
  367. if t.Year() > 0 {
  368. b = strconv.AppendInt(b, int64(t.Year()), 10)
  369. } else {
  370. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  371. }
  372. b = append(b, []byte{0x20}...)
  373. b = append(b, sd.monthsWide[t.Month()]...)
  374. b = append(b, []byte{0x20}...)
  375. b = strconv.AppendInt(b, int64(t.Day()), 10)
  376. return string(b)
  377. }
  378. // FmtDateFull returns the full date representation of 't' for 'sd'
  379. func (sd *sd) FmtDateFull(t time.Time) string {
  380. b := make([]byte, 0, 32)
  381. if t.Year() > 0 {
  382. b = strconv.AppendInt(b, int64(t.Year()), 10)
  383. } else {
  384. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  385. }
  386. b = append(b, []byte{0x20}...)
  387. b = append(b, sd.monthsWide[t.Month()]...)
  388. b = append(b, []byte{0x20}...)
  389. b = strconv.AppendInt(b, int64(t.Day()), 10)
  390. b = append(b, []byte{0x2c, 0x20}...)
  391. b = append(b, sd.daysWide[t.Weekday()]...)
  392. return string(b)
  393. }
  394. // FmtTimeShort returns the short time representation of 't' for 'sd'
  395. func (sd *sd) FmtTimeShort(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, sd.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, []byte{0x20}...)
  408. if t.Hour() < 12 {
  409. b = append(b, sd.periodsAbbreviated[0]...)
  410. } else {
  411. b = append(b, sd.periodsAbbreviated[1]...)
  412. }
  413. return string(b)
  414. }
  415. // FmtTimeMedium returns the medium time representation of 't' for 'sd'
  416. func (sd *sd) FmtTimeMedium(t time.Time) string {
  417. b := make([]byte, 0, 32)
  418. h := t.Hour()
  419. if h > 12 {
  420. h -= 12
  421. }
  422. b = strconv.AppendInt(b, int64(h), 10)
  423. b = append(b, sd.timeSeparator...)
  424. if t.Minute() < 10 {
  425. b = append(b, '0')
  426. }
  427. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  428. b = append(b, sd.timeSeparator...)
  429. if t.Second() < 10 {
  430. b = append(b, '0')
  431. }
  432. b = strconv.AppendInt(b, int64(t.Second()), 10)
  433. b = append(b, []byte{0x20}...)
  434. if t.Hour() < 12 {
  435. b = append(b, sd.periodsAbbreviated[0]...)
  436. } else {
  437. b = append(b, sd.periodsAbbreviated[1]...)
  438. }
  439. return string(b)
  440. }
  441. // FmtTimeLong returns the long time representation of 't' for 'sd'
  442. func (sd *sd) FmtTimeLong(t time.Time) string {
  443. b := make([]byte, 0, 32)
  444. h := t.Hour()
  445. if h > 12 {
  446. h -= 12
  447. }
  448. b = strconv.AppendInt(b, int64(h), 10)
  449. b = append(b, sd.timeSeparator...)
  450. if t.Minute() < 10 {
  451. b = append(b, '0')
  452. }
  453. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  454. b = append(b, sd.timeSeparator...)
  455. if t.Second() < 10 {
  456. b = append(b, '0')
  457. }
  458. b = strconv.AppendInt(b, int64(t.Second()), 10)
  459. b = append(b, []byte{0x20}...)
  460. if t.Hour() < 12 {
  461. b = append(b, sd.periodsAbbreviated[0]...)
  462. } else {
  463. b = append(b, sd.periodsAbbreviated[1]...)
  464. }
  465. b = append(b, []byte{0x20}...)
  466. tz, _ := t.Zone()
  467. b = append(b, tz...)
  468. return string(b)
  469. }
  470. // FmtTimeFull returns the full time representation of 't' for 'sd'
  471. func (sd *sd) FmtTimeFull(t time.Time) string {
  472. b := make([]byte, 0, 32)
  473. h := t.Hour()
  474. if h > 12 {
  475. h -= 12
  476. }
  477. b = strconv.AppendInt(b, int64(h), 10)
  478. b = append(b, sd.timeSeparator...)
  479. if t.Minute() < 10 {
  480. b = append(b, '0')
  481. }
  482. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  483. b = append(b, sd.timeSeparator...)
  484. if t.Second() < 10 {
  485. b = append(b, '0')
  486. }
  487. b = strconv.AppendInt(b, int64(t.Second()), 10)
  488. b = append(b, []byte{0x20}...)
  489. if t.Hour() < 12 {
  490. b = append(b, sd.periodsAbbreviated[0]...)
  491. } else {
  492. b = append(b, sd.periodsAbbreviated[1]...)
  493. }
  494. b = append(b, []byte{0x20}...)
  495. tz, _ := t.Zone()
  496. if btz, ok := sd.timezones[tz]; ok {
  497. b = append(b, btz...)
  498. } else {
  499. b = append(b, tz...)
  500. }
  501. return string(b)
  502. }