dua.go 17 KB

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