ti.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. package ti
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ti 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 'ti' locale
  39. func New() locales.Translator {
  40. return &ti{
  41. locale: "ti",
  42. pluralsCardinal: []locales.PluralRule{2, 6},
  43. pluralsOrdinal: nil,
  44. pluralsRange: nil,
  45. timeSeparator: ":",
  46. 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 ", "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 ", "Br", "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 ", "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 ", "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 "},
  47. monthsAbbreviated: []string{"", "ጃንዩ", "ፌብሩ", "ማርች", "ኤፕረ", "ሜይ", "ጁን", "ጁላይ", "ኦገስ", "ሴፕቴ", "ኦክተ", "ኖቬም", "ዲሴም"},
  48. monthsNarrow: []string{"", "ጃ", "ፌ", "ማ", "ኤ", "ሜ", "ጁ", "ጁ", "ኦ", "ሴ", "ኦ", "ኖ", "ዲ"},
  49. monthsWide: []string{"", "ጃንዩወሪ", "ፌብሩወሪ", "ማርች", "ኤፕረል", "ሜይ", "ጁን", "ጁላይ", "ኦገስት", "ሴፕቴምበር", "ኦክተውበር", "ኖቬምበር", "ዲሴምበር"},
  50. daysNarrow: []string{"ሰ", "ሰ", "ሠ", "ረ", "ኃ", "ዓ", "ቀ"},
  51. daysWide: []string{"ሰንበት", "ሰኑይ", "ሠሉስ", "ረቡዕ", "ኃሙስ", "ዓርቢ", "ቀዳም"},
  52. periodsAbbreviated: []string{"ንጉሆ ሰዓተ", "ድሕር ሰዓት"},
  53. periodsWide: []string{"ንጉሆ ሰዓተ", "ድሕር ሰዓት"},
  54. erasAbbreviated: []string{"ዓ/ዓ", "ዓ/ም"},
  55. erasNarrow: []string{"", ""},
  56. erasWide: []string{"", ""},
  57. timezones: map[string]string{"AKDT": "AKDT", "AWDT": "AWDT", "CLT": "CLT", "COT": "COT", "ECT": "ECT", "SAST": "SAST", "IST": "IST", "AKST": "AKST", "HNT": "HNT", "VET": "VET", "JDT": "JDT", "JST": "JST", "NZDT": "NZDT", "WIB": "WIB", "HAT": "HAT", "PDT": "PDT", "HKT": "HKT", "SGT": "SGT", "WARST": "WARST", "OESZ": "OESZ", "CHAST": "CHAST", "LHDT": "LHDT", "MESZ": "MESZ", "NZST": "NZST", "EDT": "EDT", "GMT": "GMT", "TMST": "TMST", "ChST": "ChST", "GFT": "GFT", "GYT": "GYT", "LHST": "LHST", "MEZ": "MEZ", "EST": "EST", "ADT": "ADT", "WIT": "WIT", "MDT": "MDT", "PST": "PST", "CST": "CST", "HADT": "HADT", "HKST": "HKST", "ART": "ART", "ARST": "ARST", "MYT": "MYT", "WEZ": "WEZ", "WESZ": "WESZ", "COST": "COST", "WAT": "WAT", "EAT": "EAT", "BOT": "BOT", "UYT": "UYT", "UYST": "UYST", "AEDT": "AEDT", "CLST": "CLST", "AST": "AST", "ACDT": "ACDT", "CDT": "CDT", "AEST": "AEST", "TMT": "TMT", "AWST": "AWST", "ACWDT": "ACWDT", "WAST": "WAST", "BT": "BT", "OEZ": "OEZ", "SRT": "SRT", "∅∅∅": "∅∅∅", "ACWST": "ACWST", "CHADT": "CHADT", "CAT": "CAT", "WART": "WART", "WITA": "WITA", "ACST": "ACST", "HAST": "HAST", "MST": "MST"},
  58. }
  59. }
  60. // Locale returns the current translators string locale
  61. func (ti *ti) Locale() string {
  62. return ti.locale
  63. }
  64. // PluralsCardinal returns the list of cardinal plural rules associated with 'ti'
  65. func (ti *ti) PluralsCardinal() []locales.PluralRule {
  66. return ti.pluralsCardinal
  67. }
  68. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ti'
  69. func (ti *ti) PluralsOrdinal() []locales.PluralRule {
  70. return ti.pluralsOrdinal
  71. }
  72. // PluralsRange returns the list of range plural rules associated with 'ti'
  73. func (ti *ti) PluralsRange() []locales.PluralRule {
  74. return ti.pluralsRange
  75. }
  76. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ti'
  77. func (ti *ti) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  78. n := math.Abs(num)
  79. if n >= 0 && n <= 1 {
  80. return locales.PluralRuleOne
  81. }
  82. return locales.PluralRuleOther
  83. }
  84. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ti'
  85. func (ti *ti) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  86. return locales.PluralRuleUnknown
  87. }
  88. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ti'
  89. func (ti *ti) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  90. return locales.PluralRuleUnknown
  91. }
  92. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  93. func (ti *ti) MonthAbbreviated(month time.Month) string {
  94. return ti.monthsAbbreviated[month]
  95. }
  96. // MonthsAbbreviated returns the locales abbreviated months
  97. func (ti *ti) MonthsAbbreviated() []string {
  98. return ti.monthsAbbreviated[1:]
  99. }
  100. // MonthNarrow returns the locales narrow month given the 'month' provided
  101. func (ti *ti) MonthNarrow(month time.Month) string {
  102. return ti.monthsNarrow[month]
  103. }
  104. // MonthsNarrow returns the locales narrow months
  105. func (ti *ti) MonthsNarrow() []string {
  106. return ti.monthsNarrow[1:]
  107. }
  108. // MonthWide returns the locales wide month given the 'month' provided
  109. func (ti *ti) MonthWide(month time.Month) string {
  110. return ti.monthsWide[month]
  111. }
  112. // MonthsWide returns the locales wide months
  113. func (ti *ti) MonthsWide() []string {
  114. return ti.monthsWide[1:]
  115. }
  116. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  117. func (ti *ti) WeekdayAbbreviated(weekday time.Weekday) string {
  118. return ti.daysAbbreviated[weekday]
  119. }
  120. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  121. func (ti *ti) WeekdaysAbbreviated() []string {
  122. return ti.daysAbbreviated
  123. }
  124. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  125. func (ti *ti) WeekdayNarrow(weekday time.Weekday) string {
  126. return ti.daysNarrow[weekday]
  127. }
  128. // WeekdaysNarrow returns the locales narrow weekdays
  129. func (ti *ti) WeekdaysNarrow() []string {
  130. return ti.daysNarrow
  131. }
  132. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  133. func (ti *ti) WeekdayShort(weekday time.Weekday) string {
  134. return ti.daysShort[weekday]
  135. }
  136. // WeekdaysShort returns the locales short weekdays
  137. func (ti *ti) WeekdaysShort() []string {
  138. return ti.daysShort
  139. }
  140. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  141. func (ti *ti) WeekdayWide(weekday time.Weekday) string {
  142. return ti.daysWide[weekday]
  143. }
  144. // WeekdaysWide returns the locales wide weekdays
  145. func (ti *ti) WeekdaysWide() []string {
  146. return ti.daysWide
  147. }
  148. // FmtNumber returns 'num' with digits/precision of 'v' for 'ti' and handles both Whole and Real numbers based on 'v'
  149. func (ti *ti) FmtNumber(num float64, v uint64) string {
  150. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  151. }
  152. // FmtPercent returns 'num' with digits/precision of 'v' for 'ti' and handles both Whole and Real numbers based on 'v'
  153. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  154. func (ti *ti) FmtPercent(num float64, v uint64) string {
  155. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  156. }
  157. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ti'
  158. func (ti *ti) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  159. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  160. symbol := ti.currencies[currency]
  161. l := len(s) + len(symbol) + 0 + 0*len(s[:len(s)-int(v)-1])/3
  162. count := 0
  163. inWhole := v == 0
  164. b := make([]byte, 0, l)
  165. for i := len(s) - 1; i >= 0; i-- {
  166. if s[i] == '.' {
  167. b = append(b, ti.decimal[0])
  168. inWhole = true
  169. continue
  170. }
  171. if inWhole {
  172. if count == 3 {
  173. b = append(b, ti.group[0])
  174. count = 1
  175. } else {
  176. count++
  177. }
  178. }
  179. b = append(b, s[i])
  180. }
  181. for j := len(symbol) - 1; j >= 0; j-- {
  182. b = append(b, symbol[j])
  183. }
  184. if num < 0 {
  185. b = append(b, ti.minus[0])
  186. }
  187. // reverse
  188. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  189. b[i], b[j] = b[j], b[i]
  190. }
  191. if int(v) < 2 {
  192. if v == 0 {
  193. b = append(b, ti.decimal...)
  194. }
  195. for i := 0; i < 2-int(v); i++ {
  196. b = append(b, '0')
  197. }
  198. }
  199. return string(b)
  200. }
  201. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ti'
  202. // in accounting notation.
  203. func (ti *ti) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  204. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  205. symbol := ti.currencies[currency]
  206. l := len(s) + len(symbol) + 0 + 0*len(s[:len(s)-int(v)-1])/3
  207. count := 0
  208. inWhole := v == 0
  209. b := make([]byte, 0, l)
  210. for i := len(s) - 1; i >= 0; i-- {
  211. if s[i] == '.' {
  212. b = append(b, ti.decimal[0])
  213. inWhole = true
  214. continue
  215. }
  216. if inWhole {
  217. if count == 3 {
  218. b = append(b, ti.group[0])
  219. count = 1
  220. } else {
  221. count++
  222. }
  223. }
  224. b = append(b, s[i])
  225. }
  226. if num < 0 {
  227. for j := len(symbol) - 1; j >= 0; j-- {
  228. b = append(b, symbol[j])
  229. }
  230. b = append(b, ti.minus[0])
  231. } else {
  232. for j := len(symbol) - 1; j >= 0; j-- {
  233. b = append(b, symbol[j])
  234. }
  235. }
  236. // reverse
  237. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  238. b[i], b[j] = b[j], b[i]
  239. }
  240. if int(v) < 2 {
  241. if v == 0 {
  242. b = append(b, ti.decimal...)
  243. }
  244. for i := 0; i < 2-int(v); i++ {
  245. b = append(b, '0')
  246. }
  247. }
  248. return string(b)
  249. }
  250. // FmtDateShort returns the short date representation of 't' for 'ti'
  251. func (ti *ti) FmtDateShort(t time.Time) string {
  252. b := make([]byte, 0, 32)
  253. if t.Day() < 10 {
  254. b = append(b, '0')
  255. }
  256. b = strconv.AppendInt(b, int64(t.Day()), 10)
  257. b = append(b, []byte{0x2f}...)
  258. if t.Month() < 10 {
  259. b = append(b, '0')
  260. }
  261. b = strconv.AppendInt(b, int64(t.Month()), 10)
  262. b = append(b, []byte{0x2f}...)
  263. if t.Year() > 9 {
  264. b = append(b, strconv.Itoa(t.Year())[2:]...)
  265. } else {
  266. b = append(b, strconv.Itoa(t.Year())[1:]...)
  267. }
  268. return string(b)
  269. }
  270. // FmtDateMedium returns the medium date representation of 't' for 'ti'
  271. func (ti *ti) FmtDateMedium(t time.Time) string {
  272. b := make([]byte, 0, 32)
  273. if t.Day() < 10 {
  274. b = append(b, '0')
  275. }
  276. b = strconv.AppendInt(b, int64(t.Day()), 10)
  277. b = append(b, []byte{0x2d}...)
  278. b = append(b, ti.monthsAbbreviated[t.Month()]...)
  279. b = append(b, []byte{0x2d}...)
  280. b = strconv.AppendInt(b, int64(t.Year()), 10)
  281. return string(b)
  282. }
  283. // FmtDateLong returns the long date representation of 't' for 'ti'
  284. func (ti *ti) FmtDateLong(t time.Time) string {
  285. b := make([]byte, 0, 32)
  286. if t.Day() < 10 {
  287. b = append(b, '0')
  288. }
  289. b = strconv.AppendInt(b, int64(t.Day()), 10)
  290. b = append(b, []byte{0x20}...)
  291. b = append(b, ti.monthsWide[t.Month()]...)
  292. b = append(b, []byte{0x20}...)
  293. b = strconv.AppendInt(b, int64(t.Year()), 10)
  294. return string(b)
  295. }
  296. // FmtDateFull returns the full date representation of 't' for 'ti'
  297. func (ti *ti) FmtDateFull(t time.Time) string {
  298. b := make([]byte, 0, 32)
  299. b = append(b, ti.daysWide[t.Weekday()]...)
  300. b = append(b, []byte{0xe1, 0x8d, 0xa3, 0x20}...)
  301. if t.Day() < 10 {
  302. b = append(b, '0')
  303. }
  304. b = strconv.AppendInt(b, int64(t.Day()), 10)
  305. b = append(b, []byte{0x20}...)
  306. b = append(b, ti.monthsWide[t.Month()]...)
  307. b = append(b, []byte{0x20, 0xe1, 0x88, 0x98, 0xe1, 0x8b, 0x93, 0xe1, 0x88, 0x8d, 0xe1, 0x89, 0xb2, 0x20}...)
  308. b = strconv.AppendInt(b, int64(t.Year()), 10)
  309. b = append(b, []byte{0x20}...)
  310. if t.Year() < 0 {
  311. b = append(b, ti.erasWide[0]...)
  312. } else {
  313. b = append(b, ti.erasWide[1]...)
  314. }
  315. return string(b)
  316. }
  317. // FmtTimeShort returns the short time representation of 't' for 'ti'
  318. func (ti *ti) FmtTimeShort(t time.Time) string {
  319. b := make([]byte, 0, 32)
  320. h := t.Hour()
  321. if h > 12 {
  322. h -= 12
  323. }
  324. b = strconv.AppendInt(b, int64(h), 10)
  325. b = append(b, ti.timeSeparator...)
  326. if t.Minute() < 10 {
  327. b = append(b, '0')
  328. }
  329. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  330. b = append(b, []byte{0x20}...)
  331. if t.Hour() < 12 {
  332. b = append(b, ti.periodsAbbreviated[0]...)
  333. } else {
  334. b = append(b, ti.periodsAbbreviated[1]...)
  335. }
  336. return string(b)
  337. }
  338. // FmtTimeMedium returns the medium time representation of 't' for 'ti'
  339. func (ti *ti) FmtTimeMedium(t time.Time) string {
  340. b := make([]byte, 0, 32)
  341. h := t.Hour()
  342. if h > 12 {
  343. h -= 12
  344. }
  345. b = strconv.AppendInt(b, int64(h), 10)
  346. b = append(b, ti.timeSeparator...)
  347. if t.Minute() < 10 {
  348. b = append(b, '0')
  349. }
  350. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  351. b = append(b, ti.timeSeparator...)
  352. if t.Second() < 10 {
  353. b = append(b, '0')
  354. }
  355. b = strconv.AppendInt(b, int64(t.Second()), 10)
  356. b = append(b, []byte{0x20}...)
  357. if t.Hour() < 12 {
  358. b = append(b, ti.periodsAbbreviated[0]...)
  359. } else {
  360. b = append(b, ti.periodsAbbreviated[1]...)
  361. }
  362. return string(b)
  363. }
  364. // FmtTimeLong returns the long time representation of 't' for 'ti'
  365. func (ti *ti) FmtTimeLong(t time.Time) string {
  366. b := make([]byte, 0, 32)
  367. h := t.Hour()
  368. if h > 12 {
  369. h -= 12
  370. }
  371. b = strconv.AppendInt(b, int64(h), 10)
  372. b = append(b, ti.timeSeparator...)
  373. if t.Minute() < 10 {
  374. b = append(b, '0')
  375. }
  376. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  377. b = append(b, ti.timeSeparator...)
  378. if t.Second() < 10 {
  379. b = append(b, '0')
  380. }
  381. b = strconv.AppendInt(b, int64(t.Second()), 10)
  382. b = append(b, []byte{0x20}...)
  383. if t.Hour() < 12 {
  384. b = append(b, ti.periodsAbbreviated[0]...)
  385. } else {
  386. b = append(b, ti.periodsAbbreviated[1]...)
  387. }
  388. b = append(b, []byte{0x20}...)
  389. tz, _ := t.Zone()
  390. b = append(b, tz...)
  391. return string(b)
  392. }
  393. // FmtTimeFull returns the full time representation of 't' for 'ti'
  394. func (ti *ti) FmtTimeFull(t time.Time) string {
  395. b := make([]byte, 0, 32)
  396. h := t.Hour()
  397. if h > 12 {
  398. h -= 12
  399. }
  400. b = strconv.AppendInt(b, int64(h), 10)
  401. b = append(b, ti.timeSeparator...)
  402. if t.Minute() < 10 {
  403. b = append(b, '0')
  404. }
  405. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  406. b = append(b, ti.timeSeparator...)
  407. if t.Second() < 10 {
  408. b = append(b, '0')
  409. }
  410. b = strconv.AppendInt(b, int64(t.Second()), 10)
  411. b = append(b, []byte{0x20}...)
  412. if t.Hour() < 12 {
  413. b = append(b, ti.periodsAbbreviated[0]...)
  414. } else {
  415. b = append(b, ti.periodsAbbreviated[1]...)
  416. }
  417. b = append(b, []byte{0x20}...)
  418. tz, _ := t.Zone()
  419. if btz, ok := ti.timezones[tz]; ok {
  420. b = append(b, btz...)
  421. } else {
  422. b = append(b, tz...)
  423. }
  424. return string(b)
  425. }