dyo.go 17 KB

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