Extract Format#format_date from outputs.
This commit is contained in:
parent
b26b3494d0
commit
59a17a9896
5 changed files with 7 additions and 4 deletions
|
@ -9,6 +9,9 @@ class Format:
|
|||
symbol: str = "rightspace"
|
||||
datesep: str = "-"
|
||||
|
||||
def format_date(self, date):
|
||||
return str(date).replace("-", self.datesep)
|
||||
|
||||
def format_quote_amount(self, quote, amount):
|
||||
formatted_amount = self.format_num(amount)
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class Beancount(BaseOutput):
|
|||
# TODO warn if fmt settings make an invalid number (not . for decimal)
|
||||
# TODO warn if fmt settings make an invalid quote (not right/rightspace)
|
||||
|
||||
date = str(price.date).replace("-", fmt.datesep)
|
||||
date = fmt.format_date(price.date)
|
||||
lines.append(f"{date} price {series.base} {quote_amount}")
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class CSV(BaseOutput):
|
|||
def format(self, series, source=None, fmt=Format()):
|
||||
lines = ["date,base,quote,amount,source,type"]
|
||||
for price in series.prices:
|
||||
date = str(price.date).replace("-", fmt.datesep)
|
||||
date = fmt.format_date(price.date)
|
||||
amount = fmt.format_num(price.amount)
|
||||
line = ",".join(
|
||||
[date, series.base, series.quote, amount, source.id(), series.type]
|
||||
|
|
|
@ -14,7 +14,7 @@ class GnuCashSQL(BaseOutput):
|
|||
|
||||
values_parts = []
|
||||
for price in series.prices:
|
||||
date = f"{price.date} {fmt.time}"
|
||||
date = f"{fmt.format_date(price.date)} {fmt.time}"
|
||||
m = hashlib.sha256()
|
||||
m.update(
|
||||
"".join(
|
||||
|
|
|
@ -7,7 +7,7 @@ class Ledger(BaseOutput):
|
|||
def format(self, series, source=None, fmt=Format()):
|
||||
lines = []
|
||||
for price in series.prices:
|
||||
date = str(price.date).replace("-", fmt.datesep)
|
||||
date = fmt.format_date(price.date)
|
||||
quote_amount = fmt.format_quote_amount(series.quote, price.amount)
|
||||
lines.append(f"P {date} {fmt.time} {series.base} {quote_amount}")
|
||||
return "\n".join(lines) + "\n"
|
||||
|
|
Loading…
Add table
Reference in a new issue