On 28/11/2018 23:22, Daniele Nicolodi wrote: > On 28/11/2018 23:17, Martin Blais wrote: >> On Thu, Nov 29, 2018 at 1:14 AM Oon-Ee Ng <[email protected] >> >> That was my impression as well, but after testing it out I found >> this was not the case. The returned ordered list of transactions is >> then sorted by date and line number. >> >> >> Yes. Sorted by date. > > Is that documented? > > Would it be a possibility to accept a datetime object instead that a > date object for the date field (and do not serialize the time part into > the written file) be enough to obtain sorting by date and time? > > Actually, datetime objects are already accepted building metadata > instances and I guess the sorting does not strip the time away, thus > only the serialization would need to be changed. I guess I can prepare a > patch for this.
The patch is easy enough and attached, although it is largely untested. Cheers, Dan -- You received this message because you are subscribed to the Google Groups "Beancount" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/a09ce977-0045-1394-c6a3-b9b45df84e47%40grinta.net. For more options, visit https://groups.google.com/d/optout.
# HG changeset patch # User Daniele Nicolodi <[email protected]> # Date 1543473857 25200 # Wed Nov 28 23:44:17 2018 -0700 # Node ID d68ef24bb77662602c70097295f186cef0093558 # Parent 4c79f94e085880bb1d4b469c931435eb246855bf Make date format explicit in printer Other than making the date format stable, this allows to specify datetime objects as date fields when importing transactions. This has the benefit that when transactions are sorter before being serialized, transaction time is also taken into account. Time information is however lost in the serialization process. diff -r 4c79f94e0858 -r d68ef24bb776 beancount/parser/printer.py --- a/beancount/parser/printer.py Fri Nov 16 21:02:18 2018 -0500 +++ b/beancount/parser/printer.py Wed Nov 28 23:44:17 2018 -0700 @@ -162,7 +162,7 @@ for link in sorted(entry.links): strings.append('^{}'.format(link)) - oss.write('{e.date} {e.flag} {}\n'.format(' '.join(strings), e=entry)) + oss.write('{e.date:%Y-%m-%d} {e.flag} {}\n'.format(' '.join(strings), e=entry)) self.write_metadata(entry.meta, oss) rows = [self.render_posting_strings(posting) @@ -249,18 +249,18 @@ def Balance(self, entry, oss): comment = ' ; Diff: {}'.format(entry.diff_amount) if entry.diff_amount else '' - oss.write(('{e.date} balance {e.account:47} {amount}' + oss.write(('{e.date:%Y-%m-%d} balance {e.account:47} {amount}' '{comment}\n').format(e=entry, amount=entry.amount.to_string(self.dformat), comment=comment)) self.write_metadata(entry.meta, oss) def Note(self, entry, oss): - oss.write('{e.date} note {e.account} "{e.comment}"\n'.format(e=entry)) + oss.write('{e.date:%Y-%m-%d} note {e.account} "{e.comment}"\n'.format(e=entry)) self.write_metadata(entry.meta, oss) def Document(self, entry, oss): - oss.write('{e.date} document {e.account} "{e.filename}"'.format(e=entry)) + oss.write('{e.date:%Y-%m-%d} document {e.account} "{e.filename}"'.format(e=entry)) if entry.tags or entry.links: oss.write(' ') for tag in sorted(entry.tags): @@ -271,11 +271,11 @@ self.write_metadata(entry.meta, oss) def Pad(self, entry, oss): - oss.write('{e.date} pad {e.account} {e.source_account}\n'.format(e=entry)) + oss.write('{e.date:%Y-%m-%d} pad {e.account} {e.source_account}\n'.format(e=entry)) self.write_metadata(entry.meta, oss) def Open(self, entry, oss): - oss.write('{e.date} open {e.account:47} {currencies} {booking}'.format( + oss.write('{e.date:%Y-%m-%d} open {e.account:47} {currencies} {booking}'.format( e=entry, currencies=','.join(entry.currencies or []), booking=('"{}"'.format(entry.booking.name) @@ -285,24 +285,24 @@ self.write_metadata(entry.meta, oss) def Close(self, entry, oss): - oss.write('{e.date} close {e.account}\n'.format(e=entry)) + oss.write('{e.date:%Y-%m-%d} close {e.account}\n'.format(e=entry)) self.write_metadata(entry.meta, oss) def Commodity(self, entry, oss): - oss.write('{e.date} commodity {e.currency}\n'.format(e=entry)) + oss.write('{e.date:%Y-%m-%d} commodity {e.currency}\n'.format(e=entry)) self.write_metadata(entry.meta, oss) def Price(self, entry, oss): - oss.write('{e.date} price {e.currency:<22} {amount:>22}\n'.format( + oss.write('{e.date:%Y-%m-%d} price {e.currency:<22} {amount:>22}\n'.format( e=entry, amount=entry.amount.to_string(self.dformat_max))) self.write_metadata(entry.meta, oss) def Event(self, entry, oss): - oss.write('{e.date} event "{e.type}" "{e.description}"\n'.format(e=entry)) + oss.write('{e.date:%Y-%m-%d} event "{e.type}" "{e.description}"\n'.format(e=entry)) self.write_metadata(entry.meta, oss) def Query(self, entry, oss): - oss.write('{e.date} query "{e.name}" "{e.query_string}"\n'.format(e=entry)) + oss.write('{e.date:%Y-%m-%d} query "{e.name}" "{e.query_string}"\n'.format(e=entry)) self.write_metadata(entry.meta, oss) def Custom(self, entry, oss): @@ -321,7 +321,7 @@ elif isinstance(value, amount.Amount): value = value.to_string() custom_values.append(value) - oss.write('{e.date} custom "{e.type}" {}\n'.format(" ".join(custom_values), + oss.write('{e.date:%Y-%m-%d} custom "{e.type}" {}\n'.format(" ".join(custom_values), e=entry)) self.write_metadata(entry.meta, oss)
