Skip to content
Permalink
Browse files

Add support for '%F' date format specifier

'%F' is equivalent to '%Y-%m-%d'. Using the '%F' format without this
change this would not give any hard errors but instead give dates with
wrong years because the 'has_year' trait would not be correctly
detected and thus parsed dates would get set to the current year.

Fixes #1775
  • Loading branch information...
mbudde authored and tbm committed Mar 31, 2019
1 parent 928fe50 commit c4eab0007a788703bc63db82fd995ef646820529
Showing with 31 additions and 7 deletions.
  1. +4 −0 doc/NEWS.md
  2. +7 −7 src/times.cc
  3. +20 −0 test/regress/1775.test
@@ -1,5 +1,9 @@
# Ledger NEWS

## 3.1.4 (unreleased)

- Add support for '%F' date format specifier (bug #1775)

## 3.1.3 (2019-03-31)

- Properly reject postings with a comment right after the flag (bug #1753)
@@ -55,18 +55,18 @@ namespace {

temporal_io_t(const char * _fmt_str, bool _input)
: fmt_str(_fmt_str),
traits(icontains(fmt_str, "%y"),
icontains(fmt_str, "%m") || icontains(fmt_str, "%b"),
icontains(fmt_str, "%d")),
traits(icontains(fmt_str, "%F") || icontains(fmt_str, "%y"),
icontains(fmt_str, "%F") || icontains(fmt_str, "%m") || icontains(fmt_str, "%b"),
icontains(fmt_str, "%F") || icontains(fmt_str, "%d")),
input(_input) {
}

void set_format(const char * fmt) {
fmt_str = fmt;
traits = date_traits_t(icontains(fmt_str, "%y"),
icontains(fmt_str, "%m") ||
icontains(fmt_str, "%b"),
icontains(fmt_str, "%d"));
traits = date_traits_t(icontains(fmt_str, "%F") || icontains(fmt_str, "%y"),
icontains(fmt_str, "%F") ||
icontains(fmt_str, "%m") || icontains(fmt_str, "%b"),
icontains(fmt_str, "%F") || icontains(fmt_str, "%d"));
}

T parse(const char *) {}
@@ -0,0 +1,20 @@
2017-02-28 * Test
Assets:A 10.00 EUR
Assets:B -10.00 EUR

2017-03-30 * Test
Assets:A 10.00 EUR
Assets:B -10.00 EUR

2018-03-30 * Test
Assets:A 10.00 EUR
Assets:B -10.00 EUR

test reg --input-date-format %F
17-Feb-28 Test Assets:A 10.00 EUR 10.00 EUR
Assets:B -10.00 EUR 0
17-Mar-30 Test Assets:A 10.00 EUR 10.00 EUR
Assets:B -10.00 EUR 0
18-Mar-30 Test Assets:A 10.00 EUR 10.00 EUR
Assets:B -10.00 EUR 0
end test

0 comments on commit c4eab00

Please sign in to comment.
You can’t perform that action at this time.