os.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. package os
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type os 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 'os' locale
  41. func New() locales.Translator {
  42. return &os{
  43. locale: "os",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  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 ", "AUD ", "AWG ", "AZM ", "AZN ", "BAD ", "BAM ", "BAN ", "BBD ", "BDT ", "BEC ", "BEF ", "BEL ", "BGL ", "BGM ", "BGN ", "BGO ", "BHD ", "BIF ", "BMD ", "BND ", "BOB ", "BOL ", "BOP ", "BOV ", "BRB ", "BRC ", "BRE ", "R$", "BRN ", "BRR ", "BRZ ", "BSD ", "BTN ", "BUK ", "BWP ", "BYB ", "BYR ", "BZD ", "CAD ", "CDF ", "CHE ", "CHF ", "CHW ", "CLE ", "CLF ", "CLP ", "CNX ", "CNY ", "COP ", "COU ", "CRC ", "CSD ", "CSK ", "CUC ", "CUP ", "CVE ", "CYP ", "CZK ", "DDM ", "DEM ", "DJF ", "DKK ", "DOP ", "DZD ", "ECS ", "ECV ", "EEK ", "EGP ", "ERN ", "ESA ", "ESB ", "ESP ", "ETB ", "€", "FIM ", "FJD ", "FKP ", "FRF ", "£", "GEK ", "₾", "GHC ", "GHS ", "GIP ", "GMD ", "GNF ", "GNS ", "GQE ", "GRD ", "GTQ ", "GWE ", "GWP ", "GYD ", "HKD ", "HNL ", "HRD ", "HRK ", "HTG ", "HUF ", "IDR ", "IEP ", "ILP ", "ILR ", "ILS ", "INR ", "IQD ", "IRR ", "ISJ ", "ISK ", "ITL ", "JMD ", "JOD ", "JPY ", "KES ", "KGS ", "KHR ", "KMF ", "KPW ", "KRH ", "KRO ", "KRW ", "KWD ", "KYD ", "KZT ", "LAK ", "LBP ", "LKR ", "LRD ", "LSL ", "LTL ", "LTT ", "LUC ", "LUF ", "LUL ", "LVL ", "LVR ", "LYD ", "MAD ", "MAF ", "MCF ", "MDC ", "MDL ", "MGA ", "MGF ", "MKD ", "MKN ", "MLF ", "MMK ", "MNT ", "MOP ", "MRO ", "MTL ", "MTP ", "MUR ", "MVP ", "MVR ", "MWK ", "MXN ", "MXP ", "MXV ", "MYR ", "MZE ", "MZM ", "MZN ", "NAD ", "NGN ", "NIC ", "NIO ", "NLG ", "NOK ", "NPR ", "NZD ", "OMR ", "PAB ", "PEI ", "PEN ", "PES ", "PGK ", "PHP ", "PKR ", "PLN ", "PLZ ", "PTE ", "PYG ", "QAR ", "RHD ", "ROL ", "RON ", "RSD ", "RUB ", "RUR ", "RWF ", "SAR ", "SBD ", "SCR ", "SDD ", "SDG ", "SDP ", "SEK ", "SGD ", "SHP ", "SIT ", "SKK ", "SLL ", "SOS ", "SRD ", "SRG ", "SSP ", "STD ", "SUR ", "SVC ", "SYP ", "SZL ", "THB ", "TJR ", "TJS ", "TMM ", "TMT ", "TND ", "TOP ", "TPE ", "TRL ", "TRY ", "TTD ", "TWD ", "TZS ", "UAH ", "UAK ", "UGS ", "UGX ", "$", "USN ", "USS ", "UYI ", "UYP ", "UYU ", "UZS ", "VEB ", "VEF ", "VND ", "VNN ", "VUV ", "WST ", "XAF ", "XAG ", "XAU ", "XBA ", "XBB ", "XBC ", "XBD ", "XCD ", "XDR ", "XEU ", "XFO ", "XFU ", "XOF ", "XPD ", "XPF ", "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{"", "Я", "Ф", "М", "А", "М", "И", "И", "А", "С", "О", "Н", "Д"},
  59. monthsWide: []string{"", "январы", "февралы", "мартъийы", "апрелы", "майы", "июны", "июлы", "августы", "сентябры", "октябры", "ноябры", "декабры"},
  60. daysAbbreviated: []string{"хцб", "крс", "дцг", "ӕрт", "цпр", "мрб", "сбт"},
  61. daysNarrow: []string{"Х", "К", "Д", "Ӕ", "Ц", "М", "С"},
  62. daysWide: []string{"хуыцаубон", "къуырисӕр", "дыццӕг", "ӕртыццӕг", "цыппӕрӕм", "майрӕмбон", "сабат"},
  63. periodsAbbreviated: []string{"AM", "PM"},
  64. periodsWide: []string{"ӕмбисбоны размӕ", "ӕмбисбоны фӕстӕ"},
  65. erasAbbreviated: []string{"н.д.а.", "н.д."},
  66. erasNarrow: []string{"", ""},
  67. erasWide: []string{"", ""},
  68. timezones: map[string]string{"PDT": "PDT", "LHDT": "LHDT", "CLT": "CLT", "CLST": "CLST", "COST": "COST", "WART": "WART", "MYT": "MYT", "AWST": "AWST", "NZST": "NZST", "CHAST": "CHAST", "EAT": "EAT", "WEZ": "Ныгъуылӕн Европӕйаг стандартон рӕстӕг", "HKT": "HKT", "ART": "ART", "∅∅∅": "∅∅∅", "ChST": "ChST", "HKST": "HKST", "HAT": "HAT", "AWDT": "AWDT", "NZDT": "NZDT", "SAST": "SAST", "HNT": "HNT", "LHST": "LHST", "GYT": "GYT", "HAST": "HAST", "ACDT": "ACDT", "ACST": "ACST", "AKST": "AKST", "AEDT": "AEDT", "MST": "MST", "CAT": "CAT", "EST": "EST", "BT": "BT", "MEZ": "Астӕуккаг Европӕйаг стандартон рӕстӕг", "UYST": "UYST", "VET": "VET", "COT": "COT", "ARST": "ARST", "AKDT": "AKDT", "MESZ": "Астӕуккаг Европӕйаг сӕрдыгон рӕстӕг", "WESZ": "Ныгъуылӕн Европӕйаг сӕрдыгон рӕстӕг", "AST": "AST", "WAT": "WAT", "OEZ": "Скӕсӕн Европӕйаг стандартон рӕстӕг", "UYT": "UYT", "ADT": "ADT", "CST": "CST", "MDT": "MDT", "HADT": "HADT", "IST": "IST", "GFT": "GFT", "TMT": "TMT", "CDT": "CDT", "ACWDT": "ACWDT", "SGT": "SGT", "OESZ": "Скӕсӕн Европӕйаг сӕрдыгон рӕстӕг", "SRT": "SRT", "AEST": "AEST", "WARST": "WARST", "WITA": "WITA", "WIT": "WIT", "PST": "PST", "JST": "JST", "BOT": "BOT", "ACWST": "ACWST", "ECT": "ECT", "TMST": "TMST", "JDT": "JDT", "CHADT": "CHADT", "EDT": "EDT", "WAST": "WAST", "GMT": "Гринвичы рӕстӕмбис рӕстӕг", "WIB": "WIB"},
  69. }
  70. }
  71. // Locale returns the current translators string locale
  72. func (os *os) Locale() string {
  73. return os.locale
  74. }
  75. // PluralsCardinal returns the list of cardinal plural rules associated with 'os'
  76. func (os *os) PluralsCardinal() []locales.PluralRule {
  77. return os.pluralsCardinal
  78. }
  79. // PluralsOrdinal returns the list of ordinal plural rules associated with 'os'
  80. func (os *os) PluralsOrdinal() []locales.PluralRule {
  81. return os.pluralsOrdinal
  82. }
  83. // PluralsRange returns the list of range plural rules associated with 'os'
  84. func (os *os) PluralsRange() []locales.PluralRule {
  85. return os.pluralsRange
  86. }
  87. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'os'
  88. func (os *os) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  89. n := math.Abs(num)
  90. if n == 1 {
  91. return locales.PluralRuleOne
  92. }
  93. return locales.PluralRuleOther
  94. }
  95. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'os'
  96. func (os *os) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  97. return locales.PluralRuleUnknown
  98. }
  99. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'os'
  100. func (os *os) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  101. return locales.PluralRuleUnknown
  102. }
  103. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  104. func (os *os) MonthAbbreviated(month time.Month) string {
  105. return os.monthsAbbreviated[month]
  106. }
  107. // MonthsAbbreviated returns the locales abbreviated months
  108. func (os *os) MonthsAbbreviated() []string {
  109. return os.monthsAbbreviated[1:]
  110. }
  111. // MonthNarrow returns the locales narrow month given the 'month' provided
  112. func (os *os) MonthNarrow(month time.Month) string {
  113. return os.monthsNarrow[month]
  114. }
  115. // MonthsNarrow returns the locales narrow months
  116. func (os *os) MonthsNarrow() []string {
  117. return os.monthsNarrow[1:]
  118. }
  119. // MonthWide returns the locales wide month given the 'month' provided
  120. func (os *os) MonthWide(month time.Month) string {
  121. return os.monthsWide[month]
  122. }
  123. // MonthsWide returns the locales wide months
  124. func (os *os) MonthsWide() []string {
  125. return os.monthsWide[1:]
  126. }
  127. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  128. func (os *os) WeekdayAbbreviated(weekday time.Weekday) string {
  129. return os.daysAbbreviated[weekday]
  130. }
  131. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  132. func (os *os) WeekdaysAbbreviated() []string {
  133. return os.daysAbbreviated
  134. }
  135. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  136. func (os *os) WeekdayNarrow(weekday time.Weekday) string {
  137. return os.daysNarrow[weekday]
  138. }
  139. // WeekdaysNarrow returns the locales narrow weekdays
  140. func (os *os) WeekdaysNarrow() []string {
  141. return os.daysNarrow
  142. }
  143. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  144. func (os *os) WeekdayShort(weekday time.Weekday) string {
  145. return os.daysShort[weekday]
  146. }
  147. // WeekdaysShort returns the locales short weekdays
  148. func (os *os) WeekdaysShort() []string {
  149. return os.daysShort
  150. }
  151. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  152. func (os *os) WeekdayWide(weekday time.Weekday) string {
  153. return os.daysWide[weekday]
  154. }
  155. // WeekdaysWide returns the locales wide weekdays
  156. func (os *os) WeekdaysWide() []string {
  157. return os.daysWide
  158. }
  159. // FmtNumber returns 'num' with digits/precision of 'v' for 'os' and handles both Whole and Real numbers based on 'v'
  160. func (os *os) FmtNumber(num float64, v uint64) string {
  161. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  162. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  163. count := 0
  164. inWhole := v == 0
  165. b := make([]byte, 0, l)
  166. for i := len(s) - 1; i >= 0; i-- {
  167. if s[i] == '.' {
  168. b = append(b, os.decimal[0])
  169. inWhole = true
  170. continue
  171. }
  172. if inWhole {
  173. if count == 3 {
  174. for j := len(os.group) - 1; j >= 0; j-- {
  175. b = append(b, os.group[j])
  176. }
  177. count = 1
  178. } else {
  179. count++
  180. }
  181. }
  182. b = append(b, s[i])
  183. }
  184. if num < 0 {
  185. b = append(b, os.minus[0])
  186. }
  187. // reverse
  188. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  189. b[i], b[j] = b[j], b[i]
  190. }
  191. return string(b)
  192. }
  193. // FmtPercent returns 'num' with digits/precision of 'v' for 'os' and handles both Whole and Real numbers based on 'v'
  194. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  195. func (os *os) FmtPercent(num float64, v uint64) string {
  196. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  197. l := len(s) + 3
  198. b := make([]byte, 0, l)
  199. for i := len(s) - 1; i >= 0; i-- {
  200. if s[i] == '.' {
  201. b = append(b, os.decimal[0])
  202. continue
  203. }
  204. b = append(b, s[i])
  205. }
  206. if num < 0 {
  207. b = append(b, os.minus[0])
  208. }
  209. // reverse
  210. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  211. b[i], b[j] = b[j], b[i]
  212. }
  213. b = append(b, os.percent...)
  214. return string(b)
  215. }
  216. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'os'
  217. func (os *os) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  218. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  219. symbol := os.currencies[currency]
  220. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  221. count := 0
  222. inWhole := v == 0
  223. b := make([]byte, 0, l)
  224. for i := len(s) - 1; i >= 0; i-- {
  225. if s[i] == '.' {
  226. b = append(b, os.decimal[0])
  227. inWhole = true
  228. continue
  229. }
  230. if inWhole {
  231. if count == 3 {
  232. for j := len(os.group) - 1; j >= 0; j-- {
  233. b = append(b, os.group[j])
  234. }
  235. count = 1
  236. } else {
  237. count++
  238. }
  239. }
  240. b = append(b, s[i])
  241. }
  242. for j := len(symbol) - 1; j >= 0; j-- {
  243. b = append(b, symbol[j])
  244. }
  245. for j := len(os.currencyPositivePrefix) - 1; j >= 0; j-- {
  246. b = append(b, os.currencyPositivePrefix[j])
  247. }
  248. if num < 0 {
  249. b = append(b, os.minus[0])
  250. }
  251. // reverse
  252. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  253. b[i], b[j] = b[j], b[i]
  254. }
  255. if int(v) < 2 {
  256. if v == 0 {
  257. b = append(b, os.decimal...)
  258. }
  259. for i := 0; i < 2-int(v); i++ {
  260. b = append(b, '0')
  261. }
  262. }
  263. return string(b)
  264. }
  265. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'os'
  266. // in accounting notation.
  267. func (os *os) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  268. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  269. symbol := os.currencies[currency]
  270. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  271. count := 0
  272. inWhole := v == 0
  273. b := make([]byte, 0, l)
  274. for i := len(s) - 1; i >= 0; i-- {
  275. if s[i] == '.' {
  276. b = append(b, os.decimal[0])
  277. inWhole = true
  278. continue
  279. }
  280. if inWhole {
  281. if count == 3 {
  282. for j := len(os.group) - 1; j >= 0; j-- {
  283. b = append(b, os.group[j])
  284. }
  285. count = 1
  286. } else {
  287. count++
  288. }
  289. }
  290. b = append(b, s[i])
  291. }
  292. if num < 0 {
  293. for j := len(symbol) - 1; j >= 0; j-- {
  294. b = append(b, symbol[j])
  295. }
  296. for j := len(os.currencyNegativePrefix) - 1; j >= 0; j-- {
  297. b = append(b, os.currencyNegativePrefix[j])
  298. }
  299. b = append(b, os.minus[0])
  300. } else {
  301. for j := len(symbol) - 1; j >= 0; j-- {
  302. b = append(b, symbol[j])
  303. }
  304. for j := len(os.currencyPositivePrefix) - 1; j >= 0; j-- {
  305. b = append(b, os.currencyPositivePrefix[j])
  306. }
  307. }
  308. // reverse
  309. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  310. b[i], b[j] = b[j], b[i]
  311. }
  312. if int(v) < 2 {
  313. if v == 0 {
  314. b = append(b, os.decimal...)
  315. }
  316. for i := 0; i < 2-int(v); i++ {
  317. b = append(b, '0')
  318. }
  319. }
  320. return string(b)
  321. }
  322. // FmtDateShort returns the short date representation of 't' for 'os'
  323. func (os *os) FmtDateShort(t time.Time) string {
  324. b := make([]byte, 0, 32)
  325. if t.Day() < 10 {
  326. b = append(b, '0')
  327. }
  328. b = strconv.AppendInt(b, int64(t.Day()), 10)
  329. b = append(b, []byte{0x2e}...)
  330. if t.Month() < 10 {
  331. b = append(b, '0')
  332. }
  333. b = strconv.AppendInt(b, int64(t.Month()), 10)
  334. b = append(b, []byte{0x2e}...)
  335. if t.Year() > 9 {
  336. b = append(b, strconv.Itoa(t.Year())[2:]...)
  337. } else {
  338. b = append(b, strconv.Itoa(t.Year())[1:]...)
  339. }
  340. return string(b)
  341. }
  342. // FmtDateMedium returns the medium date representation of 't' for 'os'
  343. func (os *os) FmtDateMedium(t time.Time) string {
  344. b := make([]byte, 0, 32)
  345. if t.Day() < 10 {
  346. b = append(b, '0')
  347. }
  348. b = strconv.AppendInt(b, int64(t.Day()), 10)
  349. b = append(b, []byte{0x20}...)
  350. b = append(b, os.monthsAbbreviated[t.Month()]...)
  351. b = append(b, []byte{0x20}...)
  352. b = strconv.AppendInt(b, int64(t.Year()), 10)
  353. b = append(b, []byte{}...)
  354. b = append(b, []byte{0x27, 0xd0, 0xb0, 0xd0, 0xb7, 0x27}...)
  355. return string(b)
  356. }
  357. // FmtDateLong returns the long date representation of 't' for 'os'
  358. func (os *os) FmtDateLong(t time.Time) string {
  359. b := make([]byte, 0, 32)
  360. b = strconv.AppendInt(b, int64(t.Day()), 10)
  361. b = append(b, []byte{0x20}...)
  362. b = append(b, os.monthsWide[t.Month()]...)
  363. b = append(b, []byte{0x2c, 0x20}...)
  364. b = strconv.AppendInt(b, int64(t.Year()), 10)
  365. b = append(b, []byte{}...)
  366. b = append(b, []byte{0x27, 0xd0, 0xb0, 0xd0, 0xb7, 0x27}...)
  367. return string(b)
  368. }
  369. // FmtDateFull returns the full date representation of 't' for 'os'
  370. func (os *os) FmtDateFull(t time.Time) string {
  371. b := make([]byte, 0, 32)
  372. b = append(b, os.daysWide[t.Weekday()]...)
  373. b = append(b, []byte{0x2c, 0x20}...)
  374. b = strconv.AppendInt(b, int64(t.Day()), 10)
  375. b = append(b, []byte{0x20}...)
  376. b = append(b, os.monthsWide[t.Month()]...)
  377. b = append(b, []byte{0x2c, 0x20}...)
  378. b = strconv.AppendInt(b, int64(t.Year()), 10)
  379. b = append(b, []byte{}...)
  380. b = append(b, []byte{0x27, 0xd0, 0xb0, 0xd0, 0xb7, 0x27}...)
  381. return string(b)
  382. }
  383. // FmtTimeShort returns the short time representation of 't' for 'os'
  384. func (os *os) FmtTimeShort(t time.Time) string {
  385. b := make([]byte, 0, 32)
  386. if t.Hour() < 10 {
  387. b = append(b, '0')
  388. }
  389. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  390. b = append(b, os.timeSeparator...)
  391. if t.Minute() < 10 {
  392. b = append(b, '0')
  393. }
  394. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  395. return string(b)
  396. }
  397. // FmtTimeMedium returns the medium time representation of 't' for 'os'
  398. func (os *os) FmtTimeMedium(t time.Time) string {
  399. b := make([]byte, 0, 32)
  400. if t.Hour() < 10 {
  401. b = append(b, '0')
  402. }
  403. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  404. b = append(b, os.timeSeparator...)
  405. if t.Minute() < 10 {
  406. b = append(b, '0')
  407. }
  408. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  409. b = append(b, os.timeSeparator...)
  410. if t.Second() < 10 {
  411. b = append(b, '0')
  412. }
  413. b = strconv.AppendInt(b, int64(t.Second()), 10)
  414. return string(b)
  415. }
  416. // FmtTimeLong returns the long time representation of 't' for 'os'
  417. func (os *os) FmtTimeLong(t time.Time) string {
  418. b := make([]byte, 0, 32)
  419. if t.Hour() < 10 {
  420. b = append(b, '0')
  421. }
  422. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  423. b = append(b, os.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, os.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. tz, _ := t.Zone()
  435. b = append(b, tz...)
  436. return string(b)
  437. }
  438. // FmtTimeFull returns the full time representation of 't' for 'os'
  439. func (os *os) FmtTimeFull(t time.Time) string {
  440. b := make([]byte, 0, 32)
  441. if t.Hour() < 10 {
  442. b = append(b, '0')
  443. }
  444. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  445. b = append(b, os.timeSeparator...)
  446. if t.Minute() < 10 {
  447. b = append(b, '0')
  448. }
  449. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  450. b = append(b, os.timeSeparator...)
  451. if t.Second() < 10 {
  452. b = append(b, '0')
  453. }
  454. b = strconv.AppendInt(b, int64(t.Second()), 10)
  455. b = append(b, []byte{0x20}...)
  456. tz, _ := t.Zone()
  457. if btz, ok := os.timezones[tz]; ok {
  458. b = append(b, btz...)
  459. } else {
  460. b = append(b, tz...)
  461. }
  462. return string(b)
  463. }