vai.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. package vai
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type vai 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. currencyNegativePrefix 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 'vai' locale
  41. func New() locales.Translator {
  42. return &vai{
  43. locale: "vai",
  44. pluralsCardinal: nil,
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  47. decimal: ".",
  48. group: ",",
  49. timeSeparator: ":",
  50. 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", "BRL", "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", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "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", "$", "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", "USD", "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"},
  51. currencyNegativePrefix: "(",
  52. currencyNegativeSuffix: ")",
  53. monthsAbbreviated: []string{"", "ꖨꕪꖃ", "ꕒꕡ", "ꕾꖺ", "ꖢꖕ", "ꖑꕱ", "ꖱꘋ", "ꖱꕞ", "ꗛꔕ", "ꕢꕌ", "ꕭꖃ", "ꔞꘋ", "ꖨꕪꕱ"},
  54. monthsWide: []string{"", "ꖨꕪꖃ ꔞꕮ", "ꕒꕡꖝꖕ", "ꕾꖺ", "ꖢꖕ", "ꖑꕱ", "ꖱꘋ", "ꖱꕞꔤ", "ꗛꔕ", "ꕢꕌ", "ꕭꖃ", "ꔞꘋꕔꕿ ꕸꖃꗏ", "ꖨꕪꕱ ꗏꕮ"},
  55. daysWide: []string{"ꕞꕌꔵ", "ꗳꗡꘉ", "ꕚꕞꕚ", "ꕉꕞꕒ", "ꕉꔤꕆꕢ", "ꕉꔤꕀꕮ", "ꔻꔬꔳ"},
  56. timezones: map[string]string{"WESZ": "WESZ", "MYT": "MYT", "SGT": "SGT", "EAT": "EAT", "TMST": "TMST", "GYT": "GYT", "CST": "CST", "SAST": "SAST", "NZDT": "NZDT", "HKT": "HKT", "HKST": "HKST", "HAT": "HAT", "HNNOMX": "HNNOMX", "BOT": "BOT", "ECT": "ECT", "ACST": "ACST", "HNT": "HNT", "HENOMX": "HENOMX", "CAT": "CAT", "UYST": "UYST", "CHAST": "CHAST", "AEDT": "AEDT", "ACWDT": "ACWDT", "EDT": "EDT", "AWST": "AWST", "MST": "MST", "HADT": "HADT", "COST": "COST", "HNPMX": "HNPMX", "IST": "IST", "HAST": "HAST", "AWDT": "AWDT", "HEEG": "HEEG", "LHST": "LHST", "GMT": "GMT", "HNCU": "HNCU", "CHADT": "CHADT", "WAT": "WAT", "WAST": "WAST", "EST": "EST", "MESZ": "MESZ", "ARST": "ARST", "UYT": "UYT", "PST": "PST", "CDT": "CDT", "TMT": "TMT", "HECU": "HECU", "AEST": "AEST", "ADT": "ADT", "WART": "WART", "∅∅∅": "∅∅∅", "WEZ": "WEZ", "WIB": "WIB", "JST": "JST", "ACWST": "ACWST", "LHDT": "LHDT", "WIT": "WIT", "COT": "COT", "NZST": "NZST", "VET": "VET", "OEZ": "OEZ", "OESZ": "OESZ", "HEPMX": "HEPMX", "MDT": "MDT", "GFT": "GFT", "CLST": "CLST", "AST": "AST", "JDT": "JDT", "ACDT": "ACDT", "HEOG": "HEOG", "WARST": "WARST", "HNPM": "HNPM", "WITA": "WITA", "ART": "ART", "PDT": "PDT", "BT": "BT", "AKDT": "AKDT", "MEZ": "MEZ", "HEPM": "HEPM", "CLT": "CLT", "ChST": "ChST", "AKST": "AKST", "HNEG": "HNEG", "HNOG": "HNOG", "SRT": "SRT"},
  57. }
  58. }
  59. // Locale returns the current translators string locale
  60. func (vai *vai) Locale() string {
  61. return vai.locale
  62. }
  63. // PluralsCardinal returns the list of cardinal plural rules associated with 'vai'
  64. func (vai *vai) PluralsCardinal() []locales.PluralRule {
  65. return vai.pluralsCardinal
  66. }
  67. // PluralsOrdinal returns the list of ordinal plural rules associated with 'vai'
  68. func (vai *vai) PluralsOrdinal() []locales.PluralRule {
  69. return vai.pluralsOrdinal
  70. }
  71. // PluralsRange returns the list of range plural rules associated with 'vai'
  72. func (vai *vai) PluralsRange() []locales.PluralRule {
  73. return vai.pluralsRange
  74. }
  75. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'vai'
  76. func (vai *vai) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  77. return locales.PluralRuleUnknown
  78. }
  79. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'vai'
  80. func (vai *vai) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  81. return locales.PluralRuleUnknown
  82. }
  83. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'vai'
  84. func (vai *vai) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  85. return locales.PluralRuleUnknown
  86. }
  87. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  88. func (vai *vai) MonthAbbreviated(month time.Month) string {
  89. return vai.monthsAbbreviated[month]
  90. }
  91. // MonthsAbbreviated returns the locales abbreviated months
  92. func (vai *vai) MonthsAbbreviated() []string {
  93. return vai.monthsAbbreviated[1:]
  94. }
  95. // MonthNarrow returns the locales narrow month given the 'month' provided
  96. func (vai *vai) MonthNarrow(month time.Month) string {
  97. return vai.monthsNarrow[month]
  98. }
  99. // MonthsNarrow returns the locales narrow months
  100. func (vai *vai) MonthsNarrow() []string {
  101. return nil
  102. }
  103. // MonthWide returns the locales wide month given the 'month' provided
  104. func (vai *vai) MonthWide(month time.Month) string {
  105. return vai.monthsWide[month]
  106. }
  107. // MonthsWide returns the locales wide months
  108. func (vai *vai) MonthsWide() []string {
  109. return vai.monthsWide[1:]
  110. }
  111. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  112. func (vai *vai) WeekdayAbbreviated(weekday time.Weekday) string {
  113. return vai.daysAbbreviated[weekday]
  114. }
  115. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  116. func (vai *vai) WeekdaysAbbreviated() []string {
  117. return vai.daysAbbreviated
  118. }
  119. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  120. func (vai *vai) WeekdayNarrow(weekday time.Weekday) string {
  121. return vai.daysNarrow[weekday]
  122. }
  123. // WeekdaysNarrow returns the locales narrow weekdays
  124. func (vai *vai) WeekdaysNarrow() []string {
  125. return vai.daysNarrow
  126. }
  127. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  128. func (vai *vai) WeekdayShort(weekday time.Weekday) string {
  129. return vai.daysShort[weekday]
  130. }
  131. // WeekdaysShort returns the locales short weekdays
  132. func (vai *vai) WeekdaysShort() []string {
  133. return vai.daysShort
  134. }
  135. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  136. func (vai *vai) WeekdayWide(weekday time.Weekday) string {
  137. return vai.daysWide[weekday]
  138. }
  139. // WeekdaysWide returns the locales wide weekdays
  140. func (vai *vai) WeekdaysWide() []string {
  141. return vai.daysWide
  142. }
  143. // Decimal returns the decimal point of number
  144. func (vai *vai) Decimal() string {
  145. return vai.decimal
  146. }
  147. // Group returns the group of number
  148. func (vai *vai) Group() string {
  149. return vai.group
  150. }
  151. // Group returns the minus sign of number
  152. func (vai *vai) Minus() string {
  153. return vai.minus
  154. }
  155. // FmtNumber returns 'num' with digits/precision of 'v' for 'vai' and handles both Whole and Real numbers based on 'v'
  156. func (vai *vai) FmtNumber(num float64, v uint64) string {
  157. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  158. l := len(s) + 1 + 1*len(s[:len(s)-int(v)-1])/3
  159. count := 0
  160. inWhole := v == 0
  161. b := make([]byte, 0, l)
  162. for i := len(s) - 1; i >= 0; i-- {
  163. if s[i] == '.' {
  164. b = append(b, vai.decimal[0])
  165. inWhole = true
  166. continue
  167. }
  168. if inWhole {
  169. if count == 3 {
  170. b = append(b, vai.group[0])
  171. count = 1
  172. } else {
  173. count++
  174. }
  175. }
  176. b = append(b, s[i])
  177. }
  178. if num < 0 {
  179. b = append(b, vai.minus[0])
  180. }
  181. // reverse
  182. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  183. b[i], b[j] = b[j], b[i]
  184. }
  185. return string(b)
  186. }
  187. // FmtPercent returns 'num' with digits/precision of 'v' for 'vai' and handles both Whole and Real numbers based on 'v'
  188. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  189. func (vai *vai) FmtPercent(num float64, v uint64) string {
  190. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  191. }
  192. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'vai'
  193. func (vai *vai) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  194. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  195. symbol := vai.currencies[currency]
  196. l := len(s) + len(symbol) + 1 + 1*len(s[:len(s)-int(v)-1])/3
  197. count := 0
  198. inWhole := v == 0
  199. b := make([]byte, 0, l)
  200. for i := len(s) - 1; i >= 0; i-- {
  201. if s[i] == '.' {
  202. b = append(b, vai.decimal[0])
  203. inWhole = true
  204. continue
  205. }
  206. if inWhole {
  207. if count == 3 {
  208. b = append(b, vai.group[0])
  209. count = 1
  210. } else {
  211. count++
  212. }
  213. }
  214. b = append(b, s[i])
  215. }
  216. for j := len(symbol) - 1; j >= 0; j-- {
  217. b = append(b, symbol[j])
  218. }
  219. if num < 0 {
  220. b = append(b, vai.minus[0])
  221. }
  222. // reverse
  223. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  224. b[i], b[j] = b[j], b[i]
  225. }
  226. if int(v) < 2 {
  227. if v == 0 {
  228. b = append(b, vai.decimal...)
  229. }
  230. for i := 0; i < 2-int(v); i++ {
  231. b = append(b, '0')
  232. }
  233. }
  234. return string(b)
  235. }
  236. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'vai'
  237. // in accounting notation.
  238. func (vai *vai) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  239. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  240. symbol := vai.currencies[currency]
  241. l := len(s) + len(symbol) + 3 + 1*len(s[:len(s)-int(v)-1])/3
  242. count := 0
  243. inWhole := v == 0
  244. b := make([]byte, 0, l)
  245. for i := len(s) - 1; i >= 0; i-- {
  246. if s[i] == '.' {
  247. b = append(b, vai.decimal[0])
  248. inWhole = true
  249. continue
  250. }
  251. if inWhole {
  252. if count == 3 {
  253. b = append(b, vai.group[0])
  254. count = 1
  255. } else {
  256. count++
  257. }
  258. }
  259. b = append(b, s[i])
  260. }
  261. if num < 0 {
  262. for j := len(symbol) - 1; j >= 0; j-- {
  263. b = append(b, symbol[j])
  264. }
  265. b = append(b, vai.currencyNegativePrefix[0])
  266. } else {
  267. for j := len(symbol) - 1; j >= 0; j-- {
  268. b = append(b, symbol[j])
  269. }
  270. }
  271. // reverse
  272. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  273. b[i], b[j] = b[j], b[i]
  274. }
  275. if int(v) < 2 {
  276. if v == 0 {
  277. b = append(b, vai.decimal...)
  278. }
  279. for i := 0; i < 2-int(v); i++ {
  280. b = append(b, '0')
  281. }
  282. }
  283. if num < 0 {
  284. b = append(b, vai.currencyNegativeSuffix...)
  285. }
  286. return string(b)
  287. }
  288. // FmtDateShort returns the short date representation of 't' for 'vai'
  289. func (vai *vai) FmtDateShort(t time.Time) string {
  290. b := make([]byte, 0, 32)
  291. if t.Day() < 10 {
  292. b = append(b, '0')
  293. }
  294. b = strconv.AppendInt(b, int64(t.Day()), 10)
  295. b = append(b, []byte{0x2f}...)
  296. if t.Month() < 10 {
  297. b = append(b, '0')
  298. }
  299. b = strconv.AppendInt(b, int64(t.Month()), 10)
  300. b = append(b, []byte{0x2f}...)
  301. if t.Year() > 0 {
  302. b = strconv.AppendInt(b, int64(t.Year()), 10)
  303. } else {
  304. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  305. }
  306. return string(b)
  307. }
  308. // FmtDateMedium returns the medium date representation of 't' for 'vai'
  309. func (vai *vai) FmtDateMedium(t time.Time) string {
  310. b := make([]byte, 0, 32)
  311. b = strconv.AppendInt(b, int64(t.Day()), 10)
  312. b = append(b, []byte{0x20}...)
  313. b = append(b, vai.monthsAbbreviated[t.Month()]...)
  314. b = append(b, []byte{0x20}...)
  315. if t.Year() > 0 {
  316. b = strconv.AppendInt(b, int64(t.Year()), 10)
  317. } else {
  318. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  319. }
  320. return string(b)
  321. }
  322. // FmtDateLong returns the long date representation of 't' for 'vai'
  323. func (vai *vai) FmtDateLong(t time.Time) string {
  324. b := make([]byte, 0, 32)
  325. b = strconv.AppendInt(b, int64(t.Day()), 10)
  326. b = append(b, []byte{0x20}...)
  327. b = append(b, vai.monthsWide[t.Month()]...)
  328. b = append(b, []byte{0x20}...)
  329. if t.Year() > 0 {
  330. b = strconv.AppendInt(b, int64(t.Year()), 10)
  331. } else {
  332. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  333. }
  334. return string(b)
  335. }
  336. // FmtDateFull returns the full date representation of 't' for 'vai'
  337. func (vai *vai) FmtDateFull(t time.Time) string {
  338. b := make([]byte, 0, 32)
  339. b = append(b, vai.daysWide[t.Weekday()]...)
  340. b = append(b, []byte{0x2c, 0x20}...)
  341. b = strconv.AppendInt(b, int64(t.Day()), 10)
  342. b = append(b, []byte{0x20}...)
  343. b = append(b, vai.monthsWide[t.Month()]...)
  344. b = append(b, []byte{0x20}...)
  345. if t.Year() > 0 {
  346. b = strconv.AppendInt(b, int64(t.Year()), 10)
  347. } else {
  348. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  349. }
  350. return string(b)
  351. }
  352. // FmtTimeShort returns the short time representation of 't' for 'vai'
  353. func (vai *vai) FmtTimeShort(t time.Time) string {
  354. b := make([]byte, 0, 32)
  355. h := t.Hour()
  356. if h > 12 {
  357. h -= 12
  358. }
  359. b = strconv.AppendInt(b, int64(h), 10)
  360. b = append(b, vai.timeSeparator...)
  361. if t.Minute() < 10 {
  362. b = append(b, '0')
  363. }
  364. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  365. b = append(b, []byte{0x20}...)
  366. if t.Hour() < 12 {
  367. b = append(b, vai.periodsAbbreviated[0]...)
  368. } else {
  369. b = append(b, vai.periodsAbbreviated[1]...)
  370. }
  371. return string(b)
  372. }
  373. // FmtTimeMedium returns the medium time representation of 't' for 'vai'
  374. func (vai *vai) FmtTimeMedium(t time.Time) string {
  375. b := make([]byte, 0, 32)
  376. h := t.Hour()
  377. if h > 12 {
  378. h -= 12
  379. }
  380. b = strconv.AppendInt(b, int64(h), 10)
  381. b = append(b, vai.timeSeparator...)
  382. if t.Minute() < 10 {
  383. b = append(b, '0')
  384. }
  385. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  386. b = append(b, vai.timeSeparator...)
  387. if t.Second() < 10 {
  388. b = append(b, '0')
  389. }
  390. b = strconv.AppendInt(b, int64(t.Second()), 10)
  391. b = append(b, []byte{0x20}...)
  392. if t.Hour() < 12 {
  393. b = append(b, vai.periodsAbbreviated[0]...)
  394. } else {
  395. b = append(b, vai.periodsAbbreviated[1]...)
  396. }
  397. return string(b)
  398. }
  399. // FmtTimeLong returns the long time representation of 't' for 'vai'
  400. func (vai *vai) FmtTimeLong(t time.Time) string {
  401. b := make([]byte, 0, 32)
  402. h := t.Hour()
  403. if h > 12 {
  404. h -= 12
  405. }
  406. b = strconv.AppendInt(b, int64(h), 10)
  407. b = append(b, vai.timeSeparator...)
  408. if t.Minute() < 10 {
  409. b = append(b, '0')
  410. }
  411. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  412. b = append(b, vai.timeSeparator...)
  413. if t.Second() < 10 {
  414. b = append(b, '0')
  415. }
  416. b = strconv.AppendInt(b, int64(t.Second()), 10)
  417. b = append(b, []byte{0x20}...)
  418. if t.Hour() < 12 {
  419. b = append(b, vai.periodsAbbreviated[0]...)
  420. } else {
  421. b = append(b, vai.periodsAbbreviated[1]...)
  422. }
  423. b = append(b, []byte{0x20}...)
  424. tz, _ := t.Zone()
  425. b = append(b, tz...)
  426. return string(b)
  427. }
  428. // FmtTimeFull returns the full time representation of 't' for 'vai'
  429. func (vai *vai) FmtTimeFull(t time.Time) string {
  430. b := make([]byte, 0, 32)
  431. h := t.Hour()
  432. if h > 12 {
  433. h -= 12
  434. }
  435. b = strconv.AppendInt(b, int64(h), 10)
  436. b = append(b, vai.timeSeparator...)
  437. if t.Minute() < 10 {
  438. b = append(b, '0')
  439. }
  440. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  441. b = append(b, vai.timeSeparator...)
  442. if t.Second() < 10 {
  443. b = append(b, '0')
  444. }
  445. b = strconv.AppendInt(b, int64(t.Second()), 10)
  446. b = append(b, []byte{0x20}...)
  447. if t.Hour() < 12 {
  448. b = append(b, vai.periodsAbbreviated[0]...)
  449. } else {
  450. b = append(b, vai.periodsAbbreviated[1]...)
  451. }
  452. b = append(b, []byte{0x20}...)
  453. tz, _ := t.Zone()
  454. if btz, ok := vai.timezones[tz]; ok {
  455. b = append(b, btz...)
  456. } else {
  457. b = append(b, tz...)
  458. }
  459. return string(b)
  460. }