ig.go 17 KB

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