1package vi 2 3import ( 4 "math" 5 "strconv" 6 "time" 7 8 "github.com/go-playground/locales" 9 "github.com/go-playground/locales/currency" 10) 11 12type vi struct { 13 locale string 14 pluralsCardinal []locales.PluralRule 15 pluralsOrdinal []locales.PluralRule 16 pluralsRange []locales.PluralRule 17 decimal string 18 group string 19 minus string 20 percent string 21 perMille string 22 timeSeparator string 23 inifinity string 24 currencies []string // idx = enum of currency code 25 currencyPositiveSuffix string 26 currencyNegativeSuffix string 27 monthsAbbreviated []string 28 monthsNarrow []string 29 monthsWide []string 30 daysAbbreviated []string 31 daysNarrow []string 32 daysShort []string 33 daysWide []string 34 periodsAbbreviated []string 35 periodsNarrow []string 36 periodsShort []string 37 periodsWide []string 38 erasAbbreviated []string 39 erasNarrow []string 40 erasWide []string 41 timezones map[string]string 42} 43 44// New returns a new instance of translator for the 'vi' locale 45func New() locales.Translator { 46 return &vi{ 47 locale: "vi", 48 pluralsCardinal: []locales.PluralRule{6}, 49 pluralsOrdinal: []locales.PluralRule{2, 6}, 50 pluralsRange: []locales.PluralRule{6}, 51 decimal: ",", 52 group: ".", 53 minus: "-", 54 percent: "%", 55 perMille: "‰", 56 timeSeparator: ":", 57 inifinity: "∞", 58 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AU$", "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", "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"}, 59 currencyPositiveSuffix: " ", 60 currencyNegativeSuffix: " ", 61 monthsAbbreviated: []string{"", "thg 1", "thg 2", "thg 3", "thg 4", "thg 5", "thg 6", "thg 7", "thg 8", "thg 9", "thg 10", "thg 11", "thg 12"}, 62 monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, 63 monthsWide: []string{"", "tháng 1", "tháng 2", "tháng 3", "tháng 4", "tháng 5", "tháng 6", "tháng 7", "tháng 8", "tháng 9", "tháng 10", "tháng 11", "tháng 12"}, 64 daysAbbreviated: []string{"CN", "Th 2", "Th 3", "Th 4", "Th 5", "Th 6", "Th 7"}, 65 daysNarrow: []string{"CN", "T2", "T3", "T4", "T5", "T6", "T7"}, 66 daysShort: []string{"CN", "T2", "T3", "T4", "T5", "T6", "T7"}, 67 daysWide: []string{"Chủ Nhật", "Thứ Hai", "Thứ Ba", "Thứ Tư", "Thứ Năm", "Thứ Sáu", "Thứ Bảy"}, 68 periodsAbbreviated: []string{"SA", "CH"}, 69 periodsNarrow: []string{"s", "c"}, 70 periodsWide: []string{"SA", "CH"}, 71 erasAbbreviated: []string{"", ""}, 72 erasNarrow: []string{"tr. CN", "sau CN"}, 73 erasWide: []string{"", ""}, 74 timezones: map[string]string{"ACDT": "Giờ Mùa Hè Miền Trung Australia", "VET": "Giờ Venezuela", "HNNOMX": "Giờ Chuẩn Tây Bắc Mexico", "ChST": "Giờ Chamorro", "HKT": "Giờ Chuẩn Hồng Kông", "HKST": "Giờ Mùa Hè Hồng Kông", "OESZ": "Giờ mùa hè Đông Âu", "COT": "Giờ Chuẩn Colombia", "AST": "Giờ Chuẩn Đại Tây Dương", "UYT": "Giờ Chuẩn Uruguay", "WAST": "Giờ Mùa Hè Tây Phi", "HNEG": "Giờ Chuẩn Miền Đông Greenland", "MESZ": "Giờ mùa hè Trung Âu", "MST": "Giờ Chuẩn Ma Cao", "CLST": "Giờ Mùa Hè Chile", "TMST": "Giờ Mùa Hè Turkmenistan", "GYT": "Giờ Guyana", "WIB": "Giờ Miền Tây Indonesia", "JST": "Giờ Chuẩn Nhật Bản", "ACWDT": "Giờ Mùa Hè Miền Trung Tây Australia", "HNOG": "Giờ Chuẩn Miền Tây Greenland", "HEOG": "Giờ Mùa Hè Miền Tây Greenland", "WART": "Giờ chuẩn miền tây Argentina", "HEEG": "Giờ Mùa Hè Miền Đông Greenland", "HNPM": "Giờ Chuẩn St. Pierre và Miquelon", "WIT": "Giờ Miền Đông Indonesia", "JDT": "Giờ Mùa Hè Nhật Bản", "EST": "Giờ chuẩn miền Đông", "COST": "Giờ Mùa Hè Colombia", "CHAST": "Giờ Chuẩn Chatham", "HEPMX": "Giờ Mùa Hè Thái Bình Dương Mexico", "SAST": "Giờ Chuẩn Nam Phi", "WAT": "Giờ Chuẩn Tây Phi", "MYT": "Giờ Malaysia", "LHST": "Giờ Chuẩn Lord Howe", "WITA": "Giờ Miền Trung Indonesia", "CAT": "Giờ Trung Phi", "ART": "Giờ Chuẩn Argentina", "AWDT": "Giờ Mùa Hè Miền Tây Australia", "BT": "Giờ Bhutan", "EAT": "Giờ Đông Phi", "OEZ": "Giờ chuẩn Đông Âu", "HADT": "Giờ Mùa Hè Hawaii-Aleut", "ARST": "Giờ Mùa Hè Argentina", "AWST": "Giờ Chuẩn Miền Tây Australia", "MEZ": "Giờ chuẩn Trung Âu", "UYST": "Giờ Mùa Hè Uruguay", "AEDT": "Giờ Mùa Hè Miền Đông Australia", "WEZ": "Giờ Chuẩn Tây Âu", "WESZ": "Giờ mùa hè Tây Âu", "NZST": "Giờ Chuẩn New Zealand", "ECT": "Giờ Ecuador", "IST": "Giờ Chuẩn Ấn Độ", "SRT": "Giờ Suriname", "SGT": "Giờ Singapore", "TMT": "Giờ Chuẩn Turkmenistan", "CDT": "Giờ mùa hè miền Trung", "HNPMX": "Giờ Chuẩn Thái Bình Dương Mexico", "NZDT": "Giờ Mùa Hè New Zealand", "AKST": "Giờ Chuẩn Alaska", "HAT": "Giờ Mùa Hè Newfoundland", "HENOMX": "Giờ Mùa Hè Tây Bắc Mexico", "MDT": "Giờ Mùa Hè Ma Cao", "CST": "Giờ chuẩn miền Trung", "EDT": "Giờ mùa hè miền Đông", "LHDT": "Giờ Mùa Hè Lord Howe", "HNT": "Giờ Chuẩn Newfoundland", "HEPM": "Giờ Mùa Hè Saint Pierre và Miquelon", "HAST": "Giờ Chuẩn Hawaii-Aleut", "BOT": "Giờ Bolivia", "GFT": "Giờ Guiana thuộc Pháp", "ACWST": "Giờ Chuẩn Miền Trung Tây Australia", "GMT": "Giờ Trung bình Greenwich", "PST": "Giờ chuẩn Thái Bình Dương", "ADT": "Giờ mùa hè Đại Tây Dương", "AKDT": "Giờ Mùa Hè Alaska", "ACST": "Giờ Chuẩn Miền Trung Australia", "∅∅∅": "Giờ Mùa Hè Azores", "HECU": "Giờ Mùa Hè Cuba", "AEST": "Giờ Chuẩn Miền Đông Australia", "WARST": "Giờ mùa hè miền tây Argentina", "CLT": "Giờ Chuẩn Chile", "CHADT": "Giờ Mùa Hè Chatham", "HNCU": "Giờ Chuẩn Cuba", "PDT": "Giờ mùa hè Thái Bình Dương"}, 75 } 76} 77 78// Locale returns the current translators string locale 79func (vi *vi) Locale() string { 80 return vi.locale 81} 82 83// PluralsCardinal returns the list of cardinal plural rules associated with 'vi' 84func (vi *vi) PluralsCardinal() []locales.PluralRule { 85 return vi.pluralsCardinal 86} 87 88// PluralsOrdinal returns the list of ordinal plural rules associated with 'vi' 89func (vi *vi) PluralsOrdinal() []locales.PluralRule { 90 return vi.pluralsOrdinal 91} 92 93// PluralsRange returns the list of range plural rules associated with 'vi' 94func (vi *vi) PluralsRange() []locales.PluralRule { 95 return vi.pluralsRange 96} 97 98// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'vi' 99func (vi *vi) CardinalPluralRule(num float64, v uint64) locales.PluralRule { 100 return locales.PluralRuleOther 101} 102 103// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'vi' 104func (vi *vi) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 105 106 n := math.Abs(num) 107 108 if n == 1 { 109 return locales.PluralRuleOne 110 } 111 112 return locales.PluralRuleOther 113} 114 115// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'vi' 116func (vi *vi) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 117 return locales.PluralRuleOther 118} 119 120// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 121func (vi *vi) MonthAbbreviated(month time.Month) string { 122 return vi.monthsAbbreviated[month] 123} 124 125// MonthsAbbreviated returns the locales abbreviated months 126func (vi *vi) MonthsAbbreviated() []string { 127 return vi.monthsAbbreviated[1:] 128} 129 130// MonthNarrow returns the locales narrow month given the 'month' provided 131func (vi *vi) MonthNarrow(month time.Month) string { 132 return vi.monthsNarrow[month] 133} 134 135// MonthsNarrow returns the locales narrow months 136func (vi *vi) MonthsNarrow() []string { 137 return vi.monthsNarrow[1:] 138} 139 140// MonthWide returns the locales wide month given the 'month' provided 141func (vi *vi) MonthWide(month time.Month) string { 142 return vi.monthsWide[month] 143} 144 145// MonthsWide returns the locales wide months 146func (vi *vi) MonthsWide() []string { 147 return vi.monthsWide[1:] 148} 149 150// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 151func (vi *vi) WeekdayAbbreviated(weekday time.Weekday) string { 152 return vi.daysAbbreviated[weekday] 153} 154 155// WeekdaysAbbreviated returns the locales abbreviated weekdays 156func (vi *vi) WeekdaysAbbreviated() []string { 157 return vi.daysAbbreviated 158} 159 160// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 161func (vi *vi) WeekdayNarrow(weekday time.Weekday) string { 162 return vi.daysNarrow[weekday] 163} 164 165// WeekdaysNarrow returns the locales narrow weekdays 166func (vi *vi) WeekdaysNarrow() []string { 167 return vi.daysNarrow 168} 169 170// WeekdayShort returns the locales short weekday given the 'weekday' provided 171func (vi *vi) WeekdayShort(weekday time.Weekday) string { 172 return vi.daysShort[weekday] 173} 174 175// WeekdaysShort returns the locales short weekdays 176func (vi *vi) WeekdaysShort() []string { 177 return vi.daysShort 178} 179 180// WeekdayWide returns the locales wide weekday given the 'weekday' provided 181func (vi *vi) WeekdayWide(weekday time.Weekday) string { 182 return vi.daysWide[weekday] 183} 184 185// WeekdaysWide returns the locales wide weekdays 186func (vi *vi) WeekdaysWide() []string { 187 return vi.daysWide 188} 189 190// Decimal returns the decimal point of number 191func (vi *vi) Decimal() string { 192 return vi.decimal 193} 194 195// Group returns the group of number 196func (vi *vi) Group() string { 197 return vi.group 198} 199 200// Group returns the minus sign of number 201func (vi *vi) Minus() string { 202 return vi.minus 203} 204 205// FmtNumber returns 'num' with digits/precision of 'v' for 'vi' and handles both Whole and Real numbers based on 'v' 206func (vi *vi) FmtNumber(num float64, v uint64) string { 207 208 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 209 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3 210 count := 0 211 inWhole := v == 0 212 b := make([]byte, 0, l) 213 214 for i := len(s) - 1; i >= 0; i-- { 215 216 if s[i] == '.' { 217 b = append(b, vi.decimal[0]) 218 inWhole = true 219 continue 220 } 221 222 if inWhole { 223 if count == 3 { 224 b = append(b, vi.group[0]) 225 count = 1 226 } else { 227 count++ 228 } 229 } 230 231 b = append(b, s[i]) 232 } 233 234 if num < 0 { 235 b = append(b, vi.minus[0]) 236 } 237 238 // reverse 239 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 240 b[i], b[j] = b[j], b[i] 241 } 242 243 return string(b) 244} 245 246// FmtPercent returns 'num' with digits/precision of 'v' for 'vi' and handles both Whole and Real numbers based on 'v' 247// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 248func (vi *vi) FmtPercent(num float64, v uint64) string { 249 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 250 l := len(s) + 3 251 b := make([]byte, 0, l) 252 253 for i := len(s) - 1; i >= 0; i-- { 254 255 if s[i] == '.' { 256 b = append(b, vi.decimal[0]) 257 continue 258 } 259 260 b = append(b, s[i]) 261 } 262 263 if num < 0 { 264 b = append(b, vi.minus[0]) 265 } 266 267 // reverse 268 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 269 b[i], b[j] = b[j], b[i] 270 } 271 272 b = append(b, vi.percent...) 273 274 return string(b) 275} 276 277// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'vi' 278func (vi *vi) FmtCurrency(num float64, v uint64, currency currency.Type) string { 279 280 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 281 symbol := vi.currencies[currency] 282 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 283 count := 0 284 inWhole := v == 0 285 b := make([]byte, 0, l) 286 287 for i := len(s) - 1; i >= 0; i-- { 288 289 if s[i] == '.' { 290 b = append(b, vi.decimal[0]) 291 inWhole = true 292 continue 293 } 294 295 if inWhole { 296 if count == 3 { 297 b = append(b, vi.group[0]) 298 count = 1 299 } else { 300 count++ 301 } 302 } 303 304 b = append(b, s[i]) 305 } 306 307 if num < 0 { 308 b = append(b, vi.minus[0]) 309 } 310 311 // reverse 312 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 313 b[i], b[j] = b[j], b[i] 314 } 315 316 if int(v) < 2 { 317 318 if v == 0 { 319 b = append(b, vi.decimal...) 320 } 321 322 for i := 0; i < 2-int(v); i++ { 323 b = append(b, '0') 324 } 325 } 326 327 b = append(b, vi.currencyPositiveSuffix...) 328 329 b = append(b, symbol...) 330 331 return string(b) 332} 333 334// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'vi' 335// in accounting notation. 336func (vi *vi) FmtAccounting(num float64, v uint64, currency currency.Type) string { 337 338 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 339 symbol := vi.currencies[currency] 340 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 341 count := 0 342 inWhole := v == 0 343 b := make([]byte, 0, l) 344 345 for i := len(s) - 1; i >= 0; i-- { 346 347 if s[i] == '.' { 348 b = append(b, vi.decimal[0]) 349 inWhole = true 350 continue 351 } 352 353 if inWhole { 354 if count == 3 { 355 b = append(b, vi.group[0]) 356 count = 1 357 } else { 358 count++ 359 } 360 } 361 362 b = append(b, s[i]) 363 } 364 365 if num < 0 { 366 367 b = append(b, vi.minus[0]) 368 369 } 370 371 // reverse 372 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 373 b[i], b[j] = b[j], b[i] 374 } 375 376 if int(v) < 2 { 377 378 if v == 0 { 379 b = append(b, vi.decimal...) 380 } 381 382 for i := 0; i < 2-int(v); i++ { 383 b = append(b, '0') 384 } 385 } 386 387 if num < 0 { 388 b = append(b, vi.currencyNegativeSuffix...) 389 b = append(b, symbol...) 390 } else { 391 392 b = append(b, vi.currencyPositiveSuffix...) 393 b = append(b, symbol...) 394 } 395 396 return string(b) 397} 398 399// FmtDateShort returns the short date representation of 't' for 'vi' 400func (vi *vi) FmtDateShort(t time.Time) string { 401 402 b := make([]byte, 0, 32) 403 404 if t.Day() < 10 { 405 b = append(b, '0') 406 } 407 408 b = strconv.AppendInt(b, int64(t.Day()), 10) 409 b = append(b, []byte{0x2f}...) 410 411 if t.Month() < 10 { 412 b = append(b, '0') 413 } 414 415 b = strconv.AppendInt(b, int64(t.Month()), 10) 416 417 b = append(b, []byte{0x2f}...) 418 419 if t.Year() > 0 { 420 b = strconv.AppendInt(b, int64(t.Year()), 10) 421 } else { 422 b = strconv.AppendInt(b, int64(-t.Year()), 10) 423 } 424 425 return string(b) 426} 427 428// FmtDateMedium returns the medium date representation of 't' for 'vi' 429func (vi *vi) FmtDateMedium(t time.Time) string { 430 431 b := make([]byte, 0, 32) 432 433 b = strconv.AppendInt(b, int64(t.Day()), 10) 434 b = append(b, []byte{0x20}...) 435 b = append(b, vi.monthsAbbreviated[t.Month()]...) 436 b = append(b, []byte{0x2c, 0x20}...) 437 438 if t.Year() > 0 { 439 b = strconv.AppendInt(b, int64(t.Year()), 10) 440 } else { 441 b = strconv.AppendInt(b, int64(-t.Year()), 10) 442 } 443 444 return string(b) 445} 446 447// FmtDateLong returns the long date representation of 't' for 'vi' 448func (vi *vi) FmtDateLong(t time.Time) string { 449 450 b := make([]byte, 0, 32) 451 452 b = strconv.AppendInt(b, int64(t.Day()), 10) 453 b = append(b, []byte{0x20}...) 454 b = append(b, vi.monthsWide[t.Month()]...) 455 b = append(b, []byte{0x2c, 0x20}...) 456 457 if t.Year() > 0 { 458 b = strconv.AppendInt(b, int64(t.Year()), 10) 459 } else { 460 b = strconv.AppendInt(b, int64(-t.Year()), 10) 461 } 462 463 return string(b) 464} 465 466// FmtDateFull returns the full date representation of 't' for 'vi' 467func (vi *vi) FmtDateFull(t time.Time) string { 468 469 b := make([]byte, 0, 32) 470 471 b = append(b, vi.daysWide[t.Weekday()]...) 472 b = append(b, []byte{0x2c, 0x20}...) 473 b = strconv.AppendInt(b, int64(t.Day()), 10) 474 b = append(b, []byte{0x20}...) 475 b = append(b, vi.monthsWide[t.Month()]...) 476 b = append(b, []byte{0x2c, 0x20}...) 477 478 if t.Year() > 0 { 479 b = strconv.AppendInt(b, int64(t.Year()), 10) 480 } else { 481 b = strconv.AppendInt(b, int64(-t.Year()), 10) 482 } 483 484 return string(b) 485} 486 487// FmtTimeShort returns the short time representation of 't' for 'vi' 488func (vi *vi) FmtTimeShort(t time.Time) string { 489 490 b := make([]byte, 0, 32) 491 492 if t.Hour() < 10 { 493 b = append(b, '0') 494 } 495 496 b = strconv.AppendInt(b, int64(t.Hour()), 10) 497 b = append(b, vi.timeSeparator...) 498 499 if t.Minute() < 10 { 500 b = append(b, '0') 501 } 502 503 b = strconv.AppendInt(b, int64(t.Minute()), 10) 504 505 return string(b) 506} 507 508// FmtTimeMedium returns the medium time representation of 't' for 'vi' 509func (vi *vi) FmtTimeMedium(t time.Time) string { 510 511 b := make([]byte, 0, 32) 512 513 if t.Hour() < 10 { 514 b = append(b, '0') 515 } 516 517 b = strconv.AppendInt(b, int64(t.Hour()), 10) 518 b = append(b, vi.timeSeparator...) 519 520 if t.Minute() < 10 { 521 b = append(b, '0') 522 } 523 524 b = strconv.AppendInt(b, int64(t.Minute()), 10) 525 b = append(b, vi.timeSeparator...) 526 527 if t.Second() < 10 { 528 b = append(b, '0') 529 } 530 531 b = strconv.AppendInt(b, int64(t.Second()), 10) 532 533 return string(b) 534} 535 536// FmtTimeLong returns the long time representation of 't' for 'vi' 537func (vi *vi) FmtTimeLong(t time.Time) string { 538 539 b := make([]byte, 0, 32) 540 541 if t.Hour() < 10 { 542 b = append(b, '0') 543 } 544 545 b = strconv.AppendInt(b, int64(t.Hour()), 10) 546 b = append(b, vi.timeSeparator...) 547 548 if t.Minute() < 10 { 549 b = append(b, '0') 550 } 551 552 b = strconv.AppendInt(b, int64(t.Minute()), 10) 553 b = append(b, vi.timeSeparator...) 554 555 if t.Second() < 10 { 556 b = append(b, '0') 557 } 558 559 b = strconv.AppendInt(b, int64(t.Second()), 10) 560 b = append(b, []byte{0x20}...) 561 562 tz, _ := t.Zone() 563 b = append(b, tz...) 564 565 return string(b) 566} 567 568// FmtTimeFull returns the full time representation of 't' for 'vi' 569func (vi *vi) FmtTimeFull(t time.Time) string { 570 571 b := make([]byte, 0, 32) 572 573 if t.Hour() < 10 { 574 b = append(b, '0') 575 } 576 577 b = strconv.AppendInt(b, int64(t.Hour()), 10) 578 b = append(b, vi.timeSeparator...) 579 580 if t.Minute() < 10 { 581 b = append(b, '0') 582 } 583 584 b = strconv.AppendInt(b, int64(t.Minute()), 10) 585 b = append(b, vi.timeSeparator...) 586 587 if t.Second() < 10 { 588 b = append(b, '0') 589 } 590 591 b = strconv.AppendInt(b, int64(t.Second()), 10) 592 b = append(b, []byte{0x20}...) 593 594 tz, _ := t.Zone() 595 596 if btz, ok := vi.timezones[tz]; ok { 597 b = append(b, btz...) 598 } else { 599 b = append(b, tz...) 600 } 601 602 return string(b) 603} 604