os.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "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", "STN", "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{"CAT": "CAT", "HNCU": "HNCU", "ACDT": "ACDT", "HNOG": "HNOG", "COT": "COT", "∅∅∅": "∅∅∅", "AWST": "AWST", "NZDT": "NZDT", "GFT": "GFT", "JDT": "JDT", "ECT": "ECT", "HKST": "HKST", "HEPM": "HEPM", "CLST": "CLST", "HADT": "HADT", "GMT": "Гринвичы рӕстӕмбис рӕстӕг", "EDT": "EDT", "ACWST": "ACWST", "LHST": "LHST", "HNT": "HNT", "MDT": "MDT", "SRT": "SRT", "OEZ": "Скӕсӕн Европӕйаг стандартон рӕстӕг", "ARST": "ARST", "COST": "COST", "ADT": "ADT", "HEOG": "HEOG", "EAT": "EAT", "CST": "CST", "CDT": "CDT", "SGT": "SGT", "HNNOMX": "HNNOMX", "OESZ": "Скӕсӕн Европӕйаг сӕрдыгон рӕстӕг", "UYT": "UYT", "AEST": "AEST", "WAT": "WAT", "HEEG": "HEEG", "TMT": "TMT", "HAST": "HAST", "ChST": "ChST", "WARST": "WARST", "WITA": "WITA", "WIT": "WIT", "PST": "PST", "JST": "JST", "CHADT": "CHADT", "WESZ": "Ныгъуылӕн Европӕйаг сӕрдыгон рӕстӕг", "WIB": "WIB", "BT": "BT", "MYT": "MYT", "HNEG": "HNEG", "HAT": "HAT", "CHAST": "CHAST", "AWDT": "AWDT", "WAST": "WAST", "ACWDT": "ACWDT", "VET": "VET", "AST": "AST", "AEDT": "AEDT", "WEZ": "Ныгъуылӕн Европӕйаг стандартон рӕстӕг", "EST": "EST", "MEZ": "Астӕуккаг Европӕйаг стандартон рӕстӕг", "LHDT": "LHDT", "ART": "ART", "GYT": "GYT", "UYST": "UYST", "AKST": "AKST", "ACST": "ACST", "HNPM": "HNPM", "CLT": "CLT", "TMST": "TMST", "HNPMX": "HNPMX", "AKDT": "AKDT", "IST": "IST", "WART": "WART", "MST": "MST", "PDT": "PDT", "HEPMX": "HEPMX", "NZST": "NZST", "BOT": "BOT", "MESZ": "Астӕуккаг Европӕйаг сӕрдыгон рӕстӕг", "HKT": "HKT", "HENOMX": "HENOMX", "HECU": "HECU", "SAST": "SAST"},
  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. // Decimal returns the decimal point of number
  160. func (os *os) Decimal() string {
  161. return os.decimal
  162. }
  163. // Group returns the group of number
  164. func (os *os) Group() string {
  165. return os.group
  166. }
  167. // Group returns the minus sign of number
  168. func (os *os) Minus() string {
  169. return os.minus
  170. }
  171. // FmtNumber returns 'num' with digits/precision of 'v' for 'os' and handles both Whole and Real numbers based on 'v'
  172. func (os *os) FmtNumber(num float64, v uint64) string {
  173. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  174. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  175. count := 0
  176. inWhole := v == 0
  177. b := make([]byte, 0, l)
  178. for i := len(s) - 1; i >= 0; i-- {
  179. if s[i] == '.' {
  180. b = append(b, os.decimal[0])
  181. inWhole = true
  182. continue
  183. }
  184. if inWhole {
  185. if count == 3 {
  186. for j := len(os.group) - 1; j >= 0; j-- {
  187. b = append(b, os.group[j])
  188. }
  189. count = 1
  190. } else {
  191. count++
  192. }
  193. }
  194. b = append(b, s[i])
  195. }
  196. if num < 0 {
  197. b = append(b, os.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 'os' 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 (os *os) 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, os.decimal[0])
  214. continue
  215. }
  216. b = append(b, s[i])
  217. }
  218. if num < 0 {
  219. b = append(b, os.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, os.percent...)
  226. return string(b)
  227. }
  228. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'os'
  229. func (os *os) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  230. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  231. symbol := os.currencies[currency]
  232. l := len(s) + len(symbol) + 4 + 2*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, os.decimal[0])
  239. inWhole = true
  240. continue
  241. }
  242. if inWhole {
  243. if count == 3 {
  244. for j := len(os.group) - 1; j >= 0; j-- {
  245. b = append(b, os.group[j])
  246. }
  247. count = 1
  248. } else {
  249. count++
  250. }
  251. }
  252. b = append(b, s[i])
  253. }
  254. for j := len(symbol) - 1; j >= 0; j-- {
  255. b = append(b, symbol[j])
  256. }
  257. for j := len(os.currencyPositivePrefix) - 1; j >= 0; j-- {
  258. b = append(b, os.currencyPositivePrefix[j])
  259. }
  260. if num < 0 {
  261. b = append(b, os.minus[0])
  262. }
  263. // reverse
  264. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  265. b[i], b[j] = b[j], b[i]
  266. }
  267. if int(v) < 2 {
  268. if v == 0 {
  269. b = append(b, os.decimal...)
  270. }
  271. for i := 0; i < 2-int(v); i++ {
  272. b = append(b, '0')
  273. }
  274. }
  275. return string(b)
  276. }
  277. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'os'
  278. // in accounting notation.
  279. func (os *os) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  280. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  281. symbol := os.currencies[currency]
  282. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  283. count := 0
  284. inWhole := v == 0
  285. b := make([]byte, 0, l)
  286. for i := len(s) - 1; i >= 0; i-- {
  287. if s[i] == '.' {
  288. b = append(b, os.decimal[0])
  289. inWhole = true
  290. continue
  291. }
  292. if inWhole {
  293. if count == 3 {
  294. for j := len(os.group) - 1; j >= 0; j-- {
  295. b = append(b, os.group[j])
  296. }
  297. count = 1
  298. } else {
  299. count++
  300. }
  301. }
  302. b = append(b, s[i])
  303. }
  304. if num < 0 {
  305. for j := len(symbol) - 1; j >= 0; j-- {
  306. b = append(b, symbol[j])
  307. }
  308. for j := len(os.currencyNegativePrefix) - 1; j >= 0; j-- {
  309. b = append(b, os.currencyNegativePrefix[j])
  310. }
  311. b = append(b, os.minus[0])
  312. } else {
  313. for j := len(symbol) - 1; j >= 0; j-- {
  314. b = append(b, symbol[j])
  315. }
  316. for j := len(os.currencyPositivePrefix) - 1; j >= 0; j-- {
  317. b = append(b, os.currencyPositivePrefix[j])
  318. }
  319. }
  320. // reverse
  321. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  322. b[i], b[j] = b[j], b[i]
  323. }
  324. if int(v) < 2 {
  325. if v == 0 {
  326. b = append(b, os.decimal...)
  327. }
  328. for i := 0; i < 2-int(v); i++ {
  329. b = append(b, '0')
  330. }
  331. }
  332. return string(b)
  333. }
  334. // FmtDateShort returns the short date representation of 't' for 'os'
  335. func (os *os) FmtDateShort(t time.Time) string {
  336. b := make([]byte, 0, 32)
  337. if t.Day() < 10 {
  338. b = append(b, '0')
  339. }
  340. b = strconv.AppendInt(b, int64(t.Day()), 10)
  341. b = append(b, []byte{0x2e}...)
  342. if t.Month() < 10 {
  343. b = append(b, '0')
  344. }
  345. b = strconv.AppendInt(b, int64(t.Month()), 10)
  346. b = append(b, []byte{0x2e}...)
  347. if t.Year() > 9 {
  348. b = append(b, strconv.Itoa(t.Year())[2:]...)
  349. } else {
  350. b = append(b, strconv.Itoa(t.Year())[1:]...)
  351. }
  352. return string(b)
  353. }
  354. // FmtDateMedium returns the medium date representation of 't' for 'os'
  355. func (os *os) FmtDateMedium(t time.Time) string {
  356. b := make([]byte, 0, 32)
  357. if t.Day() < 10 {
  358. b = append(b, '0')
  359. }
  360. b = strconv.AppendInt(b, int64(t.Day()), 10)
  361. b = append(b, []byte{0x20}...)
  362. b = append(b, os.monthsAbbreviated[t.Month()]...)
  363. b = append(b, []byte{0x20}...)
  364. if t.Year() > 0 {
  365. b = strconv.AppendInt(b, int64(t.Year()), 10)
  366. } else {
  367. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  368. }
  369. b = append(b, []byte{0x20, 0xd0, 0xb0, 0xd0, 0xb7}...)
  370. return string(b)
  371. }
  372. // FmtDateLong returns the long date representation of 't' for 'os'
  373. func (os *os) FmtDateLong(t time.Time) string {
  374. b := make([]byte, 0, 32)
  375. b = strconv.AppendInt(b, int64(t.Day()), 10)
  376. b = append(b, []byte{0x20}...)
  377. b = append(b, os.monthsWide[t.Month()]...)
  378. b = append(b, []byte{0x2c, 0x20}...)
  379. if t.Year() > 0 {
  380. b = strconv.AppendInt(b, int64(t.Year()), 10)
  381. } else {
  382. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  383. }
  384. b = append(b, []byte{0x20, 0xd0, 0xb0, 0xd0, 0xb7}...)
  385. return string(b)
  386. }
  387. // FmtDateFull returns the full date representation of 't' for 'os'
  388. func (os *os) FmtDateFull(t time.Time) string {
  389. b := make([]byte, 0, 32)
  390. b = append(b, os.daysWide[t.Weekday()]...)
  391. b = append(b, []byte{0x2c, 0x20}...)
  392. b = strconv.AppendInt(b, int64(t.Day()), 10)
  393. b = append(b, []byte{0x20}...)
  394. b = append(b, os.monthsWide[t.Month()]...)
  395. b = append(b, []byte{0x2c, 0x20}...)
  396. if t.Year() > 0 {
  397. b = strconv.AppendInt(b, int64(t.Year()), 10)
  398. } else {
  399. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  400. }
  401. b = append(b, []byte{0x20, 0xd0, 0xb0, 0xd0, 0xb7}...)
  402. return string(b)
  403. }
  404. // FmtTimeShort returns the short time representation of 't' for 'os'
  405. func (os *os) FmtTimeShort(t time.Time) string {
  406. b := make([]byte, 0, 32)
  407. if t.Hour() < 10 {
  408. b = append(b, '0')
  409. }
  410. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  411. b = append(b, os.timeSeparator...)
  412. if t.Minute() < 10 {
  413. b = append(b, '0')
  414. }
  415. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  416. return string(b)
  417. }
  418. // FmtTimeMedium returns the medium time representation of 't' for 'os'
  419. func (os *os) FmtTimeMedium(t time.Time) string {
  420. b := make([]byte, 0, 32)
  421. if t.Hour() < 10 {
  422. b = append(b, '0')
  423. }
  424. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  425. b = append(b, os.timeSeparator...)
  426. if t.Minute() < 10 {
  427. b = append(b, '0')
  428. }
  429. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  430. b = append(b, os.timeSeparator...)
  431. if t.Second() < 10 {
  432. b = append(b, '0')
  433. }
  434. b = strconv.AppendInt(b, int64(t.Second()), 10)
  435. return string(b)
  436. }
  437. // FmtTimeLong returns the long time representation of 't' for 'os'
  438. func (os *os) FmtTimeLong(t time.Time) string {
  439. b := make([]byte, 0, 32)
  440. if t.Hour() < 10 {
  441. b = append(b, '0')
  442. }
  443. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  444. b = append(b, os.timeSeparator...)
  445. if t.Minute() < 10 {
  446. b = append(b, '0')
  447. }
  448. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  449. b = append(b, os.timeSeparator...)
  450. if t.Second() < 10 {
  451. b = append(b, '0')
  452. }
  453. b = strconv.AppendInt(b, int64(t.Second()), 10)
  454. b = append(b, []byte{0x20}...)
  455. tz, _ := t.Zone()
  456. b = append(b, tz...)
  457. return string(b)
  458. }
  459. // FmtTimeFull returns the full time representation of 't' for 'os'
  460. func (os *os) FmtTimeFull(t time.Time) string {
  461. b := make([]byte, 0, 32)
  462. if t.Hour() < 10 {
  463. b = append(b, '0')
  464. }
  465. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  466. b = append(b, os.timeSeparator...)
  467. if t.Minute() < 10 {
  468. b = append(b, '0')
  469. }
  470. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  471. b = append(b, os.timeSeparator...)
  472. if t.Second() < 10 {
  473. b = append(b, '0')
  474. }
  475. b = strconv.AppendInt(b, int64(t.Second()), 10)
  476. b = append(b, []byte{0x20}...)
  477. tz, _ := t.Zone()
  478. if btz, ok := os.timezones[tz]; ok {
  479. b = append(b, btz...)
  480. } else {
  481. b = append(b, tz...)
  482. }
  483. return string(b)
  484. }