vi.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. package vi
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type vi 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. currencyPositiveSuffix string
  23. currencyNegativeSuffix 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 'vi' locale
  41. func New() locales.Translator {
  42. return &vi{
  43. locale: "vi",
  44. pluralsCardinal: []locales.PluralRule{6},
  45. pluralsOrdinal: []locales.PluralRule{2, 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", "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"},
  55. currencyPositiveSuffix: " ",
  56. currencyNegativeSuffix: " ",
  57. 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"},
  58. monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  59. 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"},
  60. daysAbbreviated: []string{"CN", "Th 2", "Th 3", "Th 4", "Th 5", "Th 6", "Th 7"},
  61. daysNarrow: []string{"CN", "T2", "T3", "T4", "T5", "T6", "T7"},
  62. daysShort: []string{"CN", "T2", "T3", "T4", "T5", "T6", "T7"},
  63. daysWide: []string{"Chủ Nhật", "Thứ Hai", "Thứ Ba", "Thứ Tư", "Thứ Năm", "Thứ Sáu", "Thứ Bảy"},
  64. periodsAbbreviated: []string{"SA", "CH"},
  65. periodsNarrow: []string{"s", "c"},
  66. periodsWide: []string{"SA", "CH"},
  67. erasAbbreviated: []string{"", ""},
  68. erasNarrow: []string{"tr. CN", "sau CN"},
  69. erasWide: []string{"", ""},
  70. 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"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (vi *vi) Locale() string {
  75. return vi.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'vi'
  78. func (vi *vi) PluralsCardinal() []locales.PluralRule {
  79. return vi.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'vi'
  82. func (vi *vi) PluralsOrdinal() []locales.PluralRule {
  83. return vi.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'vi'
  86. func (vi *vi) PluralsRange() []locales.PluralRule {
  87. return vi.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'vi'
  90. func (vi *vi) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. return locales.PluralRuleOther
  92. }
  93. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'vi'
  94. func (vi *vi) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  95. n := math.Abs(num)
  96. if n == 1 {
  97. return locales.PluralRuleOne
  98. }
  99. return locales.PluralRuleOther
  100. }
  101. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'vi'
  102. func (vi *vi) 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 (vi *vi) MonthAbbreviated(month time.Month) string {
  107. return vi.monthsAbbreviated[month]
  108. }
  109. // MonthsAbbreviated returns the locales abbreviated months
  110. func (vi *vi) MonthsAbbreviated() []string {
  111. return vi.monthsAbbreviated[1:]
  112. }
  113. // MonthNarrow returns the locales narrow month given the 'month' provided
  114. func (vi *vi) MonthNarrow(month time.Month) string {
  115. return vi.monthsNarrow[month]
  116. }
  117. // MonthsNarrow returns the locales narrow months
  118. func (vi *vi) MonthsNarrow() []string {
  119. return vi.monthsNarrow[1:]
  120. }
  121. // MonthWide returns the locales wide month given the 'month' provided
  122. func (vi *vi) MonthWide(month time.Month) string {
  123. return vi.monthsWide[month]
  124. }
  125. // MonthsWide returns the locales wide months
  126. func (vi *vi) MonthsWide() []string {
  127. return vi.monthsWide[1:]
  128. }
  129. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  130. func (vi *vi) WeekdayAbbreviated(weekday time.Weekday) string {
  131. return vi.daysAbbreviated[weekday]
  132. }
  133. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  134. func (vi *vi) WeekdaysAbbreviated() []string {
  135. return vi.daysAbbreviated
  136. }
  137. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  138. func (vi *vi) WeekdayNarrow(weekday time.Weekday) string {
  139. return vi.daysNarrow[weekday]
  140. }
  141. // WeekdaysNarrow returns the locales narrow weekdays
  142. func (vi *vi) WeekdaysNarrow() []string {
  143. return vi.daysNarrow
  144. }
  145. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  146. func (vi *vi) WeekdayShort(weekday time.Weekday) string {
  147. return vi.daysShort[weekday]
  148. }
  149. // WeekdaysShort returns the locales short weekdays
  150. func (vi *vi) WeekdaysShort() []string {
  151. return vi.daysShort
  152. }
  153. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  154. func (vi *vi) WeekdayWide(weekday time.Weekday) string {
  155. return vi.daysWide[weekday]
  156. }
  157. // WeekdaysWide returns the locales wide weekdays
  158. func (vi *vi) WeekdaysWide() []string {
  159. return vi.daysWide
  160. }
  161. // Decimal returns the decimal point of number
  162. func (vi *vi) Decimal() string {
  163. return vi.decimal
  164. }
  165. // Group returns the group of number
  166. func (vi *vi) Group() string {
  167. return vi.group
  168. }
  169. // Group returns the minus sign of number
  170. func (vi *vi) Minus() string {
  171. return vi.minus
  172. }
  173. // FmtNumber returns 'num' with digits/precision of 'v' for 'vi' and handles both Whole and Real numbers based on 'v'
  174. func (vi *vi) 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, vi.decimal[0])
  183. inWhole = true
  184. continue
  185. }
  186. if inWhole {
  187. if count == 3 {
  188. b = append(b, vi.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, vi.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 'vi' 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 (vi *vi) 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, vi.decimal[0])
  214. continue
  215. }
  216. b = append(b, s[i])
  217. }
  218. if num < 0 {
  219. b = append(b, vi.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, vi.percent...)
  226. return string(b)
  227. }
  228. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'vi'
  229. func (vi *vi) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  230. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  231. symbol := vi.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, vi.decimal[0])
  239. inWhole = true
  240. continue
  241. }
  242. if inWhole {
  243. if count == 3 {
  244. b = append(b, vi.group[0])
  245. count = 1
  246. } else {
  247. count++
  248. }
  249. }
  250. b = append(b, s[i])
  251. }
  252. if num < 0 {
  253. b = append(b, vi.minus[0])
  254. }
  255. // reverse
  256. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  257. b[i], b[j] = b[j], b[i]
  258. }
  259. if int(v) < 2 {
  260. if v == 0 {
  261. b = append(b, vi.decimal...)
  262. }
  263. for i := 0; i < 2-int(v); i++ {
  264. b = append(b, '0')
  265. }
  266. }
  267. b = append(b, vi.currencyPositiveSuffix...)
  268. b = append(b, symbol...)
  269. return string(b)
  270. }
  271. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'vi'
  272. // in accounting notation.
  273. func (vi *vi) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  274. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  275. symbol := vi.currencies[currency]
  276. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  277. count := 0
  278. inWhole := v == 0
  279. b := make([]byte, 0, l)
  280. for i := len(s) - 1; i >= 0; i-- {
  281. if s[i] == '.' {
  282. b = append(b, vi.decimal[0])
  283. inWhole = true
  284. continue
  285. }
  286. if inWhole {
  287. if count == 3 {
  288. b = append(b, vi.group[0])
  289. count = 1
  290. } else {
  291. count++
  292. }
  293. }
  294. b = append(b, s[i])
  295. }
  296. if num < 0 {
  297. b = append(b, vi.minus[0])
  298. }
  299. // reverse
  300. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  301. b[i], b[j] = b[j], b[i]
  302. }
  303. if int(v) < 2 {
  304. if v == 0 {
  305. b = append(b, vi.decimal...)
  306. }
  307. for i := 0; i < 2-int(v); i++ {
  308. b = append(b, '0')
  309. }
  310. }
  311. if num < 0 {
  312. b = append(b, vi.currencyNegativeSuffix...)
  313. b = append(b, symbol...)
  314. } else {
  315. b = append(b, vi.currencyPositiveSuffix...)
  316. b = append(b, symbol...)
  317. }
  318. return string(b)
  319. }
  320. // FmtDateShort returns the short date representation of 't' for 'vi'
  321. func (vi *vi) FmtDateShort(t time.Time) string {
  322. b := make([]byte, 0, 32)
  323. if t.Day() < 10 {
  324. b = append(b, '0')
  325. }
  326. b = strconv.AppendInt(b, int64(t.Day()), 10)
  327. b = append(b, []byte{0x2f}...)
  328. if t.Month() < 10 {
  329. b = append(b, '0')
  330. }
  331. b = strconv.AppendInt(b, int64(t.Month()), 10)
  332. b = append(b, []byte{0x2f}...)
  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. return string(b)
  339. }
  340. // FmtDateMedium returns the medium date representation of 't' for 'vi'
  341. func (vi *vi) FmtDateMedium(t time.Time) string {
  342. b := make([]byte, 0, 32)
  343. b = strconv.AppendInt(b, int64(t.Day()), 10)
  344. b = append(b, []byte{0x20}...)
  345. b = append(b, vi.monthsAbbreviated[t.Month()]...)
  346. b = append(b, []byte{0x2c, 0x20}...)
  347. if t.Year() > 0 {
  348. b = strconv.AppendInt(b, int64(t.Year()), 10)
  349. } else {
  350. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  351. }
  352. return string(b)
  353. }
  354. // FmtDateLong returns the long date representation of 't' for 'vi'
  355. func (vi *vi) FmtDateLong(t time.Time) string {
  356. b := make([]byte, 0, 32)
  357. b = strconv.AppendInt(b, int64(t.Day()), 10)
  358. b = append(b, []byte{0x20}...)
  359. b = append(b, vi.monthsWide[t.Month()]...)
  360. b = append(b, []byte{0x2c, 0x20}...)
  361. if t.Year() > 0 {
  362. b = strconv.AppendInt(b, int64(t.Year()), 10)
  363. } else {
  364. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  365. }
  366. return string(b)
  367. }
  368. // FmtDateFull returns the full date representation of 't' for 'vi'
  369. func (vi *vi) FmtDateFull(t time.Time) string {
  370. b := make([]byte, 0, 32)
  371. b = append(b, vi.daysWide[t.Weekday()]...)
  372. b = append(b, []byte{0x2c, 0x20}...)
  373. b = strconv.AppendInt(b, int64(t.Day()), 10)
  374. b = append(b, []byte{0x20}...)
  375. b = append(b, vi.monthsWide[t.Month()]...)
  376. b = append(b, []byte{0x2c, 0x20}...)
  377. if t.Year() > 0 {
  378. b = strconv.AppendInt(b, int64(t.Year()), 10)
  379. } else {
  380. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  381. }
  382. return string(b)
  383. }
  384. // FmtTimeShort returns the short time representation of 't' for 'vi'
  385. func (vi *vi) FmtTimeShort(t time.Time) string {
  386. b := make([]byte, 0, 32)
  387. if t.Hour() < 10 {
  388. b = append(b, '0')
  389. }
  390. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  391. b = append(b, vi.timeSeparator...)
  392. if t.Minute() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  396. return string(b)
  397. }
  398. // FmtTimeMedium returns the medium time representation of 't' for 'vi'
  399. func (vi *vi) FmtTimeMedium(t time.Time) string {
  400. b := make([]byte, 0, 32)
  401. if t.Hour() < 10 {
  402. b = append(b, '0')
  403. }
  404. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  405. b = append(b, vi.timeSeparator...)
  406. if t.Minute() < 10 {
  407. b = append(b, '0')
  408. }
  409. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  410. b = append(b, vi.timeSeparator...)
  411. if t.Second() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Second()), 10)
  415. return string(b)
  416. }
  417. // FmtTimeLong returns the long time representation of 't' for 'vi'
  418. func (vi *vi) FmtTimeLong(t time.Time) string {
  419. b := make([]byte, 0, 32)
  420. if t.Hour() < 10 {
  421. b = append(b, '0')
  422. }
  423. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  424. b = append(b, vi.timeSeparator...)
  425. if t.Minute() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  429. b = append(b, vi.timeSeparator...)
  430. if t.Second() < 10 {
  431. b = append(b, '0')
  432. }
  433. b = strconv.AppendInt(b, int64(t.Second()), 10)
  434. b = append(b, []byte{0x20}...)
  435. tz, _ := t.Zone()
  436. b = append(b, tz...)
  437. return string(b)
  438. }
  439. // FmtTimeFull returns the full time representation of 't' for 'vi'
  440. func (vi *vi) FmtTimeFull(t time.Time) string {
  441. b := make([]byte, 0, 32)
  442. if t.Hour() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  446. b = append(b, vi.timeSeparator...)
  447. if t.Minute() < 10 {
  448. b = append(b, '0')
  449. }
  450. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  451. b = append(b, vi.timeSeparator...)
  452. if t.Second() < 10 {
  453. b = append(b, '0')
  454. }
  455. b = strconv.AppendInt(b, int64(t.Second()), 10)
  456. b = append(b, []byte{0x20}...)
  457. tz, _ := t.Zone()
  458. if btz, ok := vi.timezones[tz]; ok {
  459. b = append(b, btz...)
  460. } else {
  461. b = append(b, tz...)
  462. }
  463. return string(b)
  464. }