ig.go 18 KB

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