id.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. package id
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type id 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. monthsAbbreviated []string
  23. monthsNarrow []string
  24. monthsWide []string
  25. daysAbbreviated []string
  26. daysNarrow []string
  27. daysShort []string
  28. daysWide []string
  29. periodsAbbreviated []string
  30. periodsNarrow []string
  31. periodsShort []string
  32. periodsWide []string
  33. erasAbbreviated []string
  34. erasNarrow []string
  35. erasWide []string
  36. timezones map[string]string
  37. }
  38. // New returns a new instance of translator for the 'id' locale
  39. func New() locales.Translator {
  40. return &id{
  41. locale: "id",
  42. pluralsCardinal: []locales.PluralRule{6},
  43. pluralsOrdinal: []locales.PluralRule{6},
  44. pluralsRange: []locales.PluralRule{6},
  45. decimal: ",",
  46. group: ".",
  47. minus: "-",
  48. percent: "%",
  49. perMille: "‰",
  50. timeSeparator: ".",
  51. inifinity: "∞",
  52. 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", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "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", "Rp", "IEP", "ILP", "ILR ", "₪", "Rs", "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", "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"},
  53. monthsAbbreviated: []string{"", "Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agt", "Sep", "Okt", "Nov", "Des"},
  54. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  55. monthsWide: []string{"", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"},
  56. daysAbbreviated: []string{"Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"},
  57. daysNarrow: []string{"M", "S", "S", "R", "K", "J", "S"},
  58. daysShort: []string{"Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"},
  59. daysWide: []string{"Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"},
  60. periodsAbbreviated: []string{"AM", "PM"},
  61. periodsNarrow: []string{"AM", "PM"},
  62. periodsWide: []string{"AM", "PM"},
  63. erasAbbreviated: []string{"SM", "M"},
  64. erasNarrow: []string{"SM", "M"},
  65. erasWide: []string{"Sebelum Masehi", "M"},
  66. timezones: map[string]string{"ACWST": "Waktu Standar Barat Tengah Australia", "HKT": "Waktu Standar Hong Kong", "HNT": "Waktu Standar Newfoundland", "PST": "Waktu Standar Pasifik", "CHAST": "Waktu Standar Chatham", "WAT": "Waktu Standar Afrika Barat", "AKST": "Waktu Standar Alaska", "AKDT": "Waktu Musim Panas Alaska", "CHADT": "Waktu Musim Panas Chatham", "COT": "Waktu Standar Kolombia", "∅∅∅": "Waktu Musim Panas Acre", "WIB": "Waktu Indonesia Barat", "TMST": "Waktu Musim Panas Turkmenistan", "JST": "Waktu Standar Jepang", "SRT": "Waktu Suriname", "ACWDT": "Waktu Musim Panas Barat Tengah Australia", "GYT": "Waktu Guyana", "NZDT": "Waktu Musim Panas Selandia Baru", "OEZ": "Waktu Standar Eropa Timur", "ACST": "Waktu Standar Tengah Australia", "TMT": "Waktu Standar Turkmenistan", "EAT": "Waktu Afrika Timur", "HKST": "Waktu Musim Panas Hong Kong", "AEST": "Waktu Standar Timur Australia", "WESZ": "Waktu Musim Panas Eropa Barat", "JDT": "Waktu Musim Panas Jepang", "UYST": "Waktu Musim Panas Uruguay", "CLT": "Waktu Standar Cile", "BT": "Waktu Bhutan", "WART": "Waktu Standar Argentina Bagian Barat", "ART": "Waktu Standar Argentina", "MYT": "Waktu Malaysia", "HADT": "Waktu Musim Panas Hawaii-Aleutian", "GFT": "Waktu Guyana Prancis", "ChST": "Waktu Chamorro", "AWDT": "Waktu Musim Panas Barat Australia", "CST": "Waktu Standar Tengah", "CLST": "Waktu Musim Panas Cile", "CAT": "Waktu Afrika Tengah", "AWST": "Waktu Standar Barat Australia", "CDT": "Waktu Musim Panas Tengah", "AEDT": "Waktu Musim Panas Timur Australia", "SGT": "Waktu Standar Singapura", "WARST": "Waktu Musim Panas Argentina Bagian Barat", "SAST": "Waktu Standar Afrika Selatan", "WITA": "Waktu Indonesia Tengah", "EDT": "Waktu Musim Panas Timur", "MESZ": "Waktu Musim Panas Eropa Tengah", "EST": "Waktu Standar Timur", "WAST": "Waktu Musim Panas Afrika Barat", "IST": "Waktu India", "OESZ": "Waktu Musim Panas Eropa Timur", "BOT": "Waktu Bolivia", "HAT": "Waktu Musim Panas Newfoundland", "NZST": "Waktu Standar Selandia Baru", "MEZ": "Waktu Standar Eropa Tengah", "WEZ": "Waktu Standar Eropa Barat", "VET": "Waktu Venezuela", "ECT": "Waktu Ekuador", "AST": "Waktu Standar Atlantik", "ARST": "Waktu Musim Panas Argentina", "MDT": "Waktu Musim Panas Makau", "PDT": "Waktu Musim Panas Pasifik", "COST": "Waktu Musim Panas Kolombia", "ACDT": "Waktu Musim Panas Tengah Australia", "MST": "Waktu Standar Makau", "LHDT": "Waktu Musim Panas Lord Howe", "UYT": "Waktu Standar Uruguay", "LHST": "Waktu Standar Lord Howe", "ADT": "Waktu Musim Panas Atlantik", "HAST": "Waktu Standar Hawaii-Aleutian", "GMT": "Waktu Rata-rata Greenwich", "WIT": "Waktu Indonesia Timur"},
  67. }
  68. }
  69. // Locale returns the current translators string locale
  70. func (id *id) Locale() string {
  71. return id.locale
  72. }
  73. // PluralsCardinal returns the list of cardinal plural rules associated with 'id'
  74. func (id *id) PluralsCardinal() []locales.PluralRule {
  75. return id.pluralsCardinal
  76. }
  77. // PluralsOrdinal returns the list of ordinal plural rules associated with 'id'
  78. func (id *id) PluralsOrdinal() []locales.PluralRule {
  79. return id.pluralsOrdinal
  80. }
  81. // PluralsRange returns the list of range plural rules associated with 'id'
  82. func (id *id) PluralsRange() []locales.PluralRule {
  83. return id.pluralsRange
  84. }
  85. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'id'
  86. func (id *id) 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 'id'
  90. func (id *id) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. return locales.PluralRuleOther
  92. }
  93. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'id'
  94. func (id *id) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  95. return locales.PluralRuleOther
  96. }
  97. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  98. func (id *id) MonthAbbreviated(month time.Month) string {
  99. return id.monthsAbbreviated[month]
  100. }
  101. // MonthsAbbreviated returns the locales abbreviated months
  102. func (id *id) MonthsAbbreviated() []string {
  103. return id.monthsAbbreviated[1:]
  104. }
  105. // MonthNarrow returns the locales narrow month given the 'month' provided
  106. func (id *id) MonthNarrow(month time.Month) string {
  107. return id.monthsNarrow[month]
  108. }
  109. // MonthsNarrow returns the locales narrow months
  110. func (id *id) MonthsNarrow() []string {
  111. return id.monthsNarrow[1:]
  112. }
  113. // MonthWide returns the locales wide month given the 'month' provided
  114. func (id *id) MonthWide(month time.Month) string {
  115. return id.monthsWide[month]
  116. }
  117. // MonthsWide returns the locales wide months
  118. func (id *id) MonthsWide() []string {
  119. return id.monthsWide[1:]
  120. }
  121. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  122. func (id *id) WeekdayAbbreviated(weekday time.Weekday) string {
  123. return id.daysAbbreviated[weekday]
  124. }
  125. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  126. func (id *id) WeekdaysAbbreviated() []string {
  127. return id.daysAbbreviated
  128. }
  129. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  130. func (id *id) WeekdayNarrow(weekday time.Weekday) string {
  131. return id.daysNarrow[weekday]
  132. }
  133. // WeekdaysNarrow returns the locales narrow weekdays
  134. func (id *id) WeekdaysNarrow() []string {
  135. return id.daysNarrow
  136. }
  137. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  138. func (id *id) WeekdayShort(weekday time.Weekday) string {
  139. return id.daysShort[weekday]
  140. }
  141. // WeekdaysShort returns the locales short weekdays
  142. func (id *id) WeekdaysShort() []string {
  143. return id.daysShort
  144. }
  145. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  146. func (id *id) WeekdayWide(weekday time.Weekday) string {
  147. return id.daysWide[weekday]
  148. }
  149. // WeekdaysWide returns the locales wide weekdays
  150. func (id *id) WeekdaysWide() []string {
  151. return id.daysWide
  152. }
  153. // FmtNumber returns 'num' with digits/precision of 'v' for 'id' and handles both Whole and Real numbers based on 'v'
  154. func (id *id) FmtNumber(num float64, v uint64) string {
  155. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  156. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  157. count := 0
  158. inWhole := v == 0
  159. b := make([]byte, 0, l)
  160. for i := len(s) - 1; i >= 0; i-- {
  161. if s[i] == '.' {
  162. b = append(b, id.decimal[0])
  163. inWhole = true
  164. continue
  165. }
  166. if inWhole {
  167. if count == 3 {
  168. b = append(b, id.group[0])
  169. count = 1
  170. } else {
  171. count++
  172. }
  173. }
  174. b = append(b, s[i])
  175. }
  176. if num < 0 {
  177. b = append(b, id.minus[0])
  178. }
  179. // reverse
  180. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  181. b[i], b[j] = b[j], b[i]
  182. }
  183. return string(b)
  184. }
  185. // FmtPercent returns 'num' with digits/precision of 'v' for 'id' and handles both Whole and Real numbers based on 'v'
  186. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  187. func (id *id) FmtPercent(num float64, v uint64) string {
  188. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  189. l := len(s) + 3
  190. b := make([]byte, 0, l)
  191. for i := len(s) - 1; i >= 0; i-- {
  192. if s[i] == '.' {
  193. b = append(b, id.decimal[0])
  194. continue
  195. }
  196. b = append(b, s[i])
  197. }
  198. if num < 0 {
  199. b = append(b, id.minus[0])
  200. }
  201. // reverse
  202. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  203. b[i], b[j] = b[j], b[i]
  204. }
  205. b = append(b, id.percent...)
  206. return string(b)
  207. }
  208. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'id'
  209. func (id *id) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  210. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  211. symbol := id.currencies[currency]
  212. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  213. count := 0
  214. inWhole := v == 0
  215. b := make([]byte, 0, l)
  216. for i := len(s) - 1; i >= 0; i-- {
  217. if s[i] == '.' {
  218. b = append(b, id.decimal[0])
  219. inWhole = true
  220. continue
  221. }
  222. if inWhole {
  223. if count == 3 {
  224. b = append(b, id.group[0])
  225. count = 1
  226. } else {
  227. count++
  228. }
  229. }
  230. b = append(b, s[i])
  231. }
  232. for j := len(symbol) - 1; j >= 0; j-- {
  233. b = append(b, symbol[j])
  234. }
  235. if num < 0 {
  236. b = append(b, id.minus[0])
  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. if int(v) < 2 {
  243. if v == 0 {
  244. b = append(b, id.decimal...)
  245. }
  246. for i := 0; i < 2-int(v); i++ {
  247. b = append(b, '0')
  248. }
  249. }
  250. return string(b)
  251. }
  252. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'id'
  253. // in accounting notation.
  254. func (id *id) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  255. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  256. symbol := id.currencies[currency]
  257. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  258. count := 0
  259. inWhole := v == 0
  260. b := make([]byte, 0, l)
  261. for i := len(s) - 1; i >= 0; i-- {
  262. if s[i] == '.' {
  263. b = append(b, id.decimal[0])
  264. inWhole = true
  265. continue
  266. }
  267. if inWhole {
  268. if count == 3 {
  269. b = append(b, id.group[0])
  270. count = 1
  271. } else {
  272. count++
  273. }
  274. }
  275. b = append(b, s[i])
  276. }
  277. if num < 0 {
  278. for j := len(symbol) - 1; j >= 0; j-- {
  279. b = append(b, symbol[j])
  280. }
  281. b = append(b, id.minus[0])
  282. } else {
  283. for j := len(symbol) - 1; j >= 0; j-- {
  284. b = append(b, symbol[j])
  285. }
  286. }
  287. // reverse
  288. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  289. b[i], b[j] = b[j], b[i]
  290. }
  291. if int(v) < 2 {
  292. if v == 0 {
  293. b = append(b, id.decimal...)
  294. }
  295. for i := 0; i < 2-int(v); i++ {
  296. b = append(b, '0')
  297. }
  298. }
  299. return string(b)
  300. }
  301. // FmtDateShort returns the short date representation of 't' for 'id'
  302. func (id *id) FmtDateShort(t time.Time) string {
  303. b := make([]byte, 0, 32)
  304. if t.Day() < 10 {
  305. b = append(b, '0')
  306. }
  307. b = strconv.AppendInt(b, int64(t.Day()), 10)
  308. b = append(b, []byte{0x2f}...)
  309. if t.Month() < 10 {
  310. b = append(b, '0')
  311. }
  312. b = strconv.AppendInt(b, int64(t.Month()), 10)
  313. b = append(b, []byte{0x2f}...)
  314. if t.Year() > 9 {
  315. b = append(b, strconv.Itoa(t.Year())[2:]...)
  316. } else {
  317. b = append(b, strconv.Itoa(t.Year())[1:]...)
  318. }
  319. return string(b)
  320. }
  321. // FmtDateMedium returns the medium date representation of 't' for 'id'
  322. func (id *id) FmtDateMedium(t time.Time) string {
  323. b := make([]byte, 0, 32)
  324. b = strconv.AppendInt(b, int64(t.Day()), 10)
  325. b = append(b, []byte{0x20}...)
  326. b = append(b, id.monthsAbbreviated[t.Month()]...)
  327. b = append(b, []byte{0x20}...)
  328. b = strconv.AppendInt(b, int64(t.Year()), 10)
  329. return string(b)
  330. }
  331. // FmtDateLong returns the long date representation of 't' for 'id'
  332. func (id *id) FmtDateLong(t time.Time) string {
  333. b := make([]byte, 0, 32)
  334. b = strconv.AppendInt(b, int64(t.Day()), 10)
  335. b = append(b, []byte{0x20}...)
  336. b = append(b, id.monthsWide[t.Month()]...)
  337. b = append(b, []byte{0x20}...)
  338. b = strconv.AppendInt(b, int64(t.Year()), 10)
  339. return string(b)
  340. }
  341. // FmtDateFull returns the full date representation of 't' for 'id'
  342. func (id *id) FmtDateFull(t time.Time) string {
  343. b := make([]byte, 0, 32)
  344. b = append(b, id.daysWide[t.Weekday()]...)
  345. b = append(b, []byte{0x2c, 0x20}...)
  346. if t.Day() < 10 {
  347. b = append(b, '0')
  348. }
  349. b = strconv.AppendInt(b, int64(t.Day()), 10)
  350. b = append(b, []byte{0x20}...)
  351. b = append(b, id.monthsWide[t.Month()]...)
  352. b = append(b, []byte{0x20}...)
  353. b = strconv.AppendInt(b, int64(t.Year()), 10)
  354. return string(b)
  355. }
  356. // FmtTimeShort returns the short time representation of 't' for 'id'
  357. func (id *id) FmtTimeShort(t time.Time) string {
  358. b := make([]byte, 0, 32)
  359. if t.Hour() < 10 {
  360. b = append(b, '0')
  361. }
  362. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  363. b = append(b, []byte{0x2e}...)
  364. if t.Minute() < 10 {
  365. b = append(b, '0')
  366. }
  367. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  368. return string(b)
  369. }
  370. // FmtTimeMedium returns the medium time representation of 't' for 'id'
  371. func (id *id) FmtTimeMedium(t time.Time) string {
  372. b := make([]byte, 0, 32)
  373. if t.Hour() < 10 {
  374. b = append(b, '0')
  375. }
  376. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  377. b = append(b, []byte{0x2e}...)
  378. if t.Minute() < 10 {
  379. b = append(b, '0')
  380. }
  381. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  382. b = append(b, []byte{0x2e}...)
  383. if t.Second() < 10 {
  384. b = append(b, '0')
  385. }
  386. b = strconv.AppendInt(b, int64(t.Second()), 10)
  387. return string(b)
  388. }
  389. // FmtTimeLong returns the long time representation of 't' for 'id'
  390. func (id *id) FmtTimeLong(t time.Time) string {
  391. b := make([]byte, 0, 32)
  392. if t.Hour() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  396. b = append(b, []byte{0x2e}...)
  397. if t.Minute() < 10 {
  398. b = append(b, '0')
  399. }
  400. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  401. b = append(b, []byte{0x2e}...)
  402. if t.Second() < 10 {
  403. b = append(b, '0')
  404. }
  405. b = strconv.AppendInt(b, int64(t.Second()), 10)
  406. b = append(b, []byte{0x20}...)
  407. tz, _ := t.Zone()
  408. b = append(b, tz...)
  409. return string(b)
  410. }
  411. // FmtTimeFull returns the full time representation of 't' for 'id'
  412. func (id *id) FmtTimeFull(t time.Time) string {
  413. b := make([]byte, 0, 32)
  414. if t.Hour() < 10 {
  415. b = append(b, '0')
  416. }
  417. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  418. b = append(b, []byte{0x2e}...)
  419. if t.Minute() < 10 {
  420. b = append(b, '0')
  421. }
  422. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  423. b = append(b, []byte{0x2e}...)
  424. if t.Second() < 10 {
  425. b = append(b, '0')
  426. }
  427. b = strconv.AppendInt(b, int64(t.Second()), 10)
  428. b = append(b, []byte{0x20}...)
  429. tz, _ := t.Zone()
  430. if btz, ok := id.timezones[tz]; ok {
  431. b = append(b, btz...)
  432. } else {
  433. b = append(b, tz...)
  434. }
  435. return string(b)
  436. }