da.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. package da
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type da 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 'da' locale
  42. func New() locales.Translator {
  43. return &da{
  44. locale: "da",
  45. pluralsCardinal: []locales.PluralRule{2, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: []locales.PluralRule{2, 6},
  48. decimal: ",",
  49. group: ".",
  50. minus: "-",
  51. percent: "%",
  52. perMille: "‰",
  53. timeSeparator: ".",
  54. inifinity: "∞",
  55. 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", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "kr.", "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", "IDR", "IEP", "ILP", "ILR", "₪", "₹", "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", "STN", "SUR", "SVC", "SYP", "SZL", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "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"},
  56. percentSuffix: " ",
  57. currencyPositiveSuffix: " ",
  58. currencyNegativeSuffix: " ",
  59. monthsAbbreviated: []string{"", "jan.", "feb.", "mar.", "apr.", "maj", "jun.", "jul.", "aug.", "sep.", "okt.", "nov.", "dec."},
  60. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  61. monthsWide: []string{"", "januar", "februar", "marts", "april", "maj", "juni", "juli", "august", "september", "oktober", "november", "december"},
  62. daysAbbreviated: []string{"søn.", "man.", "tir.", "ons.", "tor.", "fre.", "lør."},
  63. daysNarrow: []string{"S", "M", "T", "O", "T", "F", "L"},
  64. daysShort: []string{"sø", "ma", "ti", "on", "to", "fr", "lø"},
  65. daysWide: []string{"søndag", "mandag", "tirsdag", "onsdag", "torsdag", "fredag", "lørdag"},
  66. periodsAbbreviated: []string{"AM", "PM"},
  67. periodsNarrow: []string{"a", "p"},
  68. periodsWide: []string{"AM", "PM"},
  69. erasAbbreviated: []string{"f.Kr.", "e.Kr."},
  70. erasNarrow: []string{"fKr", "eKr"},
  71. erasWide: []string{"f.Kr.", "e.Kr."},
  72. timezones: map[string]string{"UYST": "Uruguayansk sommertid", "HEPMX": "Mexicansk Pacific-sommertid", "AKST": "Alaska-normaltid", "ACST": "Centralaustralsk normaltid", "MEZ": "Centraleuropæisk normaltid", "MESZ": "Centraleuropæisk sommertid", "WARST": "Vestargentinsk sommertid", "LHDT": "Lord Howe-sommertid", "SAST": "Sydafrikansk tid", "MYT": "Malaysia-tid", "SGT": "Singapore-tid", "MST": "Macao-normaltid", "WIT": "Østindonesisk tid", "TMST": "Turkmensk sommertid", "HADT": "Hawaii-Aleutian-sommertid", "ChST": "Chamorro-tid", "HNCU": "Cubansk normaltid", "HNPMX": "Mexicansk Pacific-normaltid", "CST": "Central-normaltid", "WART": "Vestargentinsk normaltid", "HNPM": "Saint Pierre- og Miquelon-normaltid", "CLST": "Chilensk sommertid", "HAST": "Hawaii-Aleutian-normaltid", "COST": "Colombiansk sommertid", "CHAST": "Chatham-normaltid", "PST": "Pacific-normaltid", "AEST": "Østaustralsk normaltid", "∅∅∅": "Azorerne-sommertid", "HNNOMX": "Nordvestmexicansk normaltid", "SRT": "Surinam-tid", "TMT": "Turkmensk normaltid", "WAT": "Vestafrikansk normaltid", "EDT": "Eastern-sommertid", "LHST": "Lord Howe-normaltid", "HNT": "Newfoundlandsk normaltid", "GYT": "Guyana-tid", "WEZ": "Vesteuropæisk normaltid", "ART": "Argentinsk normaltid", "WIB": "Vestindonesisk tid", "GFT": "Fransk Guyana-tid", "JST": "Japansk normaltid", "EAT": "Østafrikansk tid", "COT": "Colombiansk normaltid", "HEEG": "Østgrønlandsk sommertid", "HEOG": "Vestgrønlandsk sommertid", "CAT": "Centralafrikansk tid", "NZDT": "New Zealand-sommertid", "AEDT": "Østaustralsk sommertid", "ECT": "Ecuadoriansk tid", "HNEG": "Østgrønlandsk normaltid", "VET": "Venezuelansk tid", "OEZ": "Østeuropæisk normaltid", "AWDT": "Vestaustralsk sommertid", "AST": "Atlantic-normaltid", "HKST": "Hongkong-sommertid", "HAT": "Newfoundlandsk sommertid", "PDT": "Pacific-sommertid", "HNOG": "Vestgrønlandsk normaltid", "WAST": "Vestafrikansk sommertid", "EST": "Eastern-normaltid", "HENOMX": "Nordvestmexicansk sommertid", "MDT": "Macao-sommertid", "ARST": "Argentinsk sommertid", "WESZ": "Vesteuropæisk sommertid", "UYT": "Uruguayansk normaltid", "BOT": "Boliviansk tid", "JDT": "Japansk sommertid", "ACWST": "Vestlig centralaustralsk normaltid", "CDT": "Central-sommertid", "HKT": "Hongkong-normaltid", "IST": "Indien-normaltid", "HEPM": "Saint Pierre- og Miquelon-sommertid", "HECU": "Cubansk sommertid", "WITA": "Centralindonesisk tid", "GMT": "GMT", "ADT": "Atlantic-sommertid", "ACWDT": "Vestlig centralaustralsk sommertid", "OESZ": "Østeuropæisk sommertid", "AWST": "Vestaustralsk normaltid", "BT": "Bhutan-tid", "NZST": "New Zealand-normaltid", "CLT": "Chilensk normaltid", "CHADT": "Chatham-sommertid", "AKDT": "Alaska-sommertid", "ACDT": "Centralaustralsk sommertid"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (da *da) Locale() string {
  77. return da.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'da'
  80. func (da *da) PluralsCardinal() []locales.PluralRule {
  81. return da.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'da'
  84. func (da *da) PluralsOrdinal() []locales.PluralRule {
  85. return da.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'da'
  88. func (da *da) PluralsRange() []locales.PluralRule {
  89. return da.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'da'
  92. func (da *da) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. i := int64(n)
  95. t := locales.T(n, v)
  96. if (n == 1) || (t != 0 && (i == 0 || i == 1)) {
  97. return locales.PluralRuleOne
  98. }
  99. return locales.PluralRuleOther
  100. }
  101. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'da'
  102. func (da *da) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  103. return locales.PluralRuleOther
  104. }
  105. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'da'
  106. func (da *da) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  107. start := da.CardinalPluralRule(num1, v1)
  108. end := da.CardinalPluralRule(num2, v2)
  109. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  110. return locales.PluralRuleOne
  111. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  112. return locales.PluralRuleOther
  113. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  114. return locales.PluralRuleOne
  115. }
  116. return locales.PluralRuleOther
  117. }
  118. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  119. func (da *da) MonthAbbreviated(month time.Month) string {
  120. return da.monthsAbbreviated[month]
  121. }
  122. // MonthsAbbreviated returns the locales abbreviated months
  123. func (da *da) MonthsAbbreviated() []string {
  124. return da.monthsAbbreviated[1:]
  125. }
  126. // MonthNarrow returns the locales narrow month given the 'month' provided
  127. func (da *da) MonthNarrow(month time.Month) string {
  128. return da.monthsNarrow[month]
  129. }
  130. // MonthsNarrow returns the locales narrow months
  131. func (da *da) MonthsNarrow() []string {
  132. return da.monthsNarrow[1:]
  133. }
  134. // MonthWide returns the locales wide month given the 'month' provided
  135. func (da *da) MonthWide(month time.Month) string {
  136. return da.monthsWide[month]
  137. }
  138. // MonthsWide returns the locales wide months
  139. func (da *da) MonthsWide() []string {
  140. return da.monthsWide[1:]
  141. }
  142. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  143. func (da *da) WeekdayAbbreviated(weekday time.Weekday) string {
  144. return da.daysAbbreviated[weekday]
  145. }
  146. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  147. func (da *da) WeekdaysAbbreviated() []string {
  148. return da.daysAbbreviated
  149. }
  150. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  151. func (da *da) WeekdayNarrow(weekday time.Weekday) string {
  152. return da.daysNarrow[weekday]
  153. }
  154. // WeekdaysNarrow returns the locales narrow weekdays
  155. func (da *da) WeekdaysNarrow() []string {
  156. return da.daysNarrow
  157. }
  158. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  159. func (da *da) WeekdayShort(weekday time.Weekday) string {
  160. return da.daysShort[weekday]
  161. }
  162. // WeekdaysShort returns the locales short weekdays
  163. func (da *da) WeekdaysShort() []string {
  164. return da.daysShort
  165. }
  166. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  167. func (da *da) WeekdayWide(weekday time.Weekday) string {
  168. return da.daysWide[weekday]
  169. }
  170. // WeekdaysWide returns the locales wide weekdays
  171. func (da *da) WeekdaysWide() []string {
  172. return da.daysWide
  173. }
  174. // Decimal returns the decimal point of number
  175. func (da *da) Decimal() string {
  176. return da.decimal
  177. }
  178. // Group returns the group of number
  179. func (da *da) Group() string {
  180. return da.group
  181. }
  182. // Group returns the minus sign of number
  183. func (da *da) Minus() string {
  184. return da.minus
  185. }
  186. // FmtNumber returns 'num' with digits/precision of 'v' for 'da' and handles both Whole and Real numbers based on 'v'
  187. func (da *da) FmtNumber(num float64, v uint64) string {
  188. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  189. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  190. count := 0
  191. inWhole := v == 0
  192. b := make([]byte, 0, l)
  193. for i := len(s) - 1; i >= 0; i-- {
  194. if s[i] == '.' {
  195. b = append(b, da.decimal[0])
  196. inWhole = true
  197. continue
  198. }
  199. if inWhole {
  200. if count == 3 {
  201. b = append(b, da.group[0])
  202. count = 1
  203. } else {
  204. count++
  205. }
  206. }
  207. b = append(b, s[i])
  208. }
  209. if num < 0 {
  210. b = append(b, da.minus[0])
  211. }
  212. // reverse
  213. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  214. b[i], b[j] = b[j], b[i]
  215. }
  216. return string(b)
  217. }
  218. // FmtPercent returns 'num' with digits/precision of 'v' for 'da' and handles both Whole and Real numbers based on 'v'
  219. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  220. func (da *da) FmtPercent(num float64, v uint64) string {
  221. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  222. l := len(s) + 5
  223. b := make([]byte, 0, l)
  224. for i := len(s) - 1; i >= 0; i-- {
  225. if s[i] == '.' {
  226. b = append(b, da.decimal[0])
  227. continue
  228. }
  229. b = append(b, s[i])
  230. }
  231. if num < 0 {
  232. b = append(b, da.minus[0])
  233. }
  234. // reverse
  235. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  236. b[i], b[j] = b[j], b[i]
  237. }
  238. b = append(b, da.percentSuffix...)
  239. b = append(b, da.percent...)
  240. return string(b)
  241. }
  242. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'da'
  243. func (da *da) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  244. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  245. symbol := da.currencies[currency]
  246. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  247. count := 0
  248. inWhole := v == 0
  249. b := make([]byte, 0, l)
  250. for i := len(s) - 1; i >= 0; i-- {
  251. if s[i] == '.' {
  252. b = append(b, da.decimal[0])
  253. inWhole = true
  254. continue
  255. }
  256. if inWhole {
  257. if count == 3 {
  258. b = append(b, da.group[0])
  259. count = 1
  260. } else {
  261. count++
  262. }
  263. }
  264. b = append(b, s[i])
  265. }
  266. if num < 0 {
  267. b = append(b, da.minus[0])
  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, da.decimal...)
  276. }
  277. for i := 0; i < 2-int(v); i++ {
  278. b = append(b, '0')
  279. }
  280. }
  281. b = append(b, da.currencyPositiveSuffix...)
  282. b = append(b, symbol...)
  283. return string(b)
  284. }
  285. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'da'
  286. // in accounting notation.
  287. func (da *da) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  288. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  289. symbol := da.currencies[currency]
  290. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  291. count := 0
  292. inWhole := v == 0
  293. b := make([]byte, 0, l)
  294. for i := len(s) - 1; i >= 0; i-- {
  295. if s[i] == '.' {
  296. b = append(b, da.decimal[0])
  297. inWhole = true
  298. continue
  299. }
  300. if inWhole {
  301. if count == 3 {
  302. b = append(b, da.group[0])
  303. count = 1
  304. } else {
  305. count++
  306. }
  307. }
  308. b = append(b, s[i])
  309. }
  310. if num < 0 {
  311. b = append(b, da.minus[0])
  312. }
  313. // reverse
  314. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  315. b[i], b[j] = b[j], b[i]
  316. }
  317. if int(v) < 2 {
  318. if v == 0 {
  319. b = append(b, da.decimal...)
  320. }
  321. for i := 0; i < 2-int(v); i++ {
  322. b = append(b, '0')
  323. }
  324. }
  325. if num < 0 {
  326. b = append(b, da.currencyNegativeSuffix...)
  327. b = append(b, symbol...)
  328. } else {
  329. b = append(b, da.currencyPositiveSuffix...)
  330. b = append(b, symbol...)
  331. }
  332. return string(b)
  333. }
  334. // FmtDateShort returns the short date representation of 't' for 'da'
  335. func (da *da) FmtDateShort(t time.Time) string {
  336. b := make([]byte, 0, 32)
  337. if t.Day() < 10 {
  338. b = append(b, '0')
  339. }
  340. b = strconv.AppendInt(b, int64(t.Day()), 10)
  341. b = append(b, []byte{0x2f}...)
  342. if t.Month() < 10 {
  343. b = append(b, '0')
  344. }
  345. b = strconv.AppendInt(b, int64(t.Month()), 10)
  346. b = append(b, []byte{0x2f}...)
  347. if t.Year() > 0 {
  348. b = strconv.AppendInt(b, int64(t.Year()), 10)
  349. } else {
  350. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  351. }
  352. return string(b)
  353. }
  354. // FmtDateMedium returns the medium date representation of 't' for 'da'
  355. func (da *da) FmtDateMedium(t time.Time) string {
  356. b := make([]byte, 0, 32)
  357. b = strconv.AppendInt(b, int64(t.Day()), 10)
  358. b = append(b, []byte{0x2e, 0x20}...)
  359. b = append(b, da.monthsAbbreviated[t.Month()]...)
  360. b = append(b, []byte{0x20}...)
  361. if t.Year() > 0 {
  362. b = strconv.AppendInt(b, int64(t.Year()), 10)
  363. } else {
  364. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  365. }
  366. return string(b)
  367. }
  368. // FmtDateLong returns the long date representation of 't' for 'da'
  369. func (da *da) FmtDateLong(t time.Time) string {
  370. b := make([]byte, 0, 32)
  371. b = strconv.AppendInt(b, int64(t.Day()), 10)
  372. b = append(b, []byte{0x2e, 0x20}...)
  373. b = append(b, da.monthsWide[t.Month()]...)
  374. b = append(b, []byte{0x20}...)
  375. if t.Year() > 0 {
  376. b = strconv.AppendInt(b, int64(t.Year()), 10)
  377. } else {
  378. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  379. }
  380. return string(b)
  381. }
  382. // FmtDateFull returns the full date representation of 't' for 'da'
  383. func (da *da) FmtDateFull(t time.Time) string {
  384. b := make([]byte, 0, 32)
  385. b = append(b, da.daysWide[t.Weekday()]...)
  386. b = append(b, []byte{0x20, 0x64, 0x65, 0x6e}...)
  387. b = append(b, []byte{0x20}...)
  388. b = strconv.AppendInt(b, int64(t.Day()), 10)
  389. b = append(b, []byte{0x2e, 0x20}...)
  390. b = append(b, da.monthsWide[t.Month()]...)
  391. b = append(b, []byte{0x20}...)
  392. if t.Year() > 0 {
  393. b = strconv.AppendInt(b, int64(t.Year()), 10)
  394. } else {
  395. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  396. }
  397. return string(b)
  398. }
  399. // FmtTimeShort returns the short time representation of 't' for 'da'
  400. func (da *da) FmtTimeShort(t time.Time) string {
  401. b := make([]byte, 0, 32)
  402. if t.Hour() < 10 {
  403. b = append(b, '0')
  404. }
  405. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  406. b = append(b, []byte{0x2e}...)
  407. if t.Minute() < 10 {
  408. b = append(b, '0')
  409. }
  410. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  411. return string(b)
  412. }
  413. // FmtTimeMedium returns the medium time representation of 't' for 'da'
  414. func (da *da) FmtTimeMedium(t time.Time) string {
  415. b := make([]byte, 0, 32)
  416. if t.Hour() < 10 {
  417. b = append(b, '0')
  418. }
  419. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  420. b = append(b, []byte{0x2e}...)
  421. if t.Minute() < 10 {
  422. b = append(b, '0')
  423. }
  424. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  425. b = append(b, []byte{0x2e}...)
  426. if t.Second() < 10 {
  427. b = append(b, '0')
  428. }
  429. b = strconv.AppendInt(b, int64(t.Second()), 10)
  430. return string(b)
  431. }
  432. // FmtTimeLong returns the long time representation of 't' for 'da'
  433. func (da *da) FmtTimeLong(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, []byte{0x2e}...)
  440. if t.Minute() < 10 {
  441. b = append(b, '0')
  442. }
  443. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  444. b = append(b, []byte{0x2e}...)
  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. b = append(b, tz...)
  452. return string(b)
  453. }
  454. // FmtTimeFull returns the full time representation of 't' for 'da'
  455. func (da *da) FmtTimeFull(t time.Time) string {
  456. b := make([]byte, 0, 32)
  457. if t.Hour() < 10 {
  458. b = append(b, '0')
  459. }
  460. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  461. b = append(b, []byte{0x2e}...)
  462. if t.Minute() < 10 {
  463. b = append(b, '0')
  464. }
  465. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  466. b = append(b, []byte{0x2e}...)
  467. if t.Second() < 10 {
  468. b = append(b, '0')
  469. }
  470. b = strconv.AppendInt(b, int64(t.Second()), 10)
  471. b = append(b, []byte{0x20}...)
  472. tz, _ := t.Zone()
  473. if btz, ok := da.timezones[tz]; ok {
  474. b = append(b, btz...)
  475. } else {
  476. b = append(b, tz...)
  477. }
  478. return string(b)
  479. }