Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong year when using the --input-date-format "%F" option with the register command #1775

Closed
fturco opened this Issue Mar 17, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@fturco
Copy link

fturco commented Mar 17, 2019

I'm running app-office/ledger-3.1.1-r2 on a Gentoo Linux system.

Ledger incorrectly shows transactions in the future even when in the source file they are set in the past. Day and month are the same, but the year is different.

Example of source file (~/tmp/xxx.dat):

payee yyy

account Risorse:Intesa
account Entrate:XXX

commodity €

2018-03-30 yyy
 Risorse:Intesa  2,88 €
 Entrate:XXX

On the command line:

$ ledger --file ~/tmp/xxx.dat register --input-date-format "%F"
19-Mar-30 yyy                                           Risorse:Intesa                                                            2,88 €                      2,88 €
                                                        Entrate:XXX                                                              -2,88 €                           0

As you can see, ledger displays 19-Mar-30 instead of 18-Mar-30.

If you drop the --input-date-format "%F" option everything is OK:

$ ledger --file ~/tmp/xxx.dat register 
18-Mar-30 yyy                                           Risorse:Intesa                                                            2,88 €                      2,88 €
                                                        Entrate:XXX                                                              -2,88 €                           0

@tbm tbm added the bug label Mar 18, 2019

@tbm

This comment has been minimized.

Copy link
Contributor

tbm commented Mar 18, 2019

Interestingly --input-date-format "%Y-%m-%d" works as expected, but %F doesn't.

@tbm

This comment has been minimized.

Copy link
Contributor

tbm commented Mar 18, 2019

It seems the year is ignored with %F since all of the following lead to 2019:

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

Hmm, this is weird. When I add --now "2030-04-03", the years become 2018 instead of 2030.

@tbm

This comment has been minimized.

Copy link
Contributor

tbm commented Mar 18, 2019

This is weird. --debug time shows the right dates:

    5ms  [DEBUG] Passed date string:  2017-02-28
    5ms  [DEBUG] Parsed date string:  2017-02-28
    5ms  [DEBUG] Parsed result is:    2017-Feb-28
    5ms  [DEBUG] Formatted result is: 2017-02-28
    6ms  [DEBUG] Passed date string:  2017-03-30
    6ms  [DEBUG] Parsed date string:  2017-03-30
    7ms  [DEBUG] Parsed result is:    2017-Mar-30
    7ms  [DEBUG] Formatted result is: 2017-03-30
    7ms  [DEBUG] Passed date string:  2018-03-30
    7ms  [DEBUG] Parsed date string:  2018-03-30
    7ms  [DEBUG] Parsed result is:    2018-Mar-30
    7ms  [DEBUG] Formatted result is: 2018-03-30

@mbudde any idea?

@tbm

This comment has been minimized.

Copy link
Contributor

tbm commented Mar 18, 2019

  108ms  [DEBUG]   format_date(date) => Releasing 0x5655029e2060, refc now 3
  108ms  [DEBUG] "2019-02-28"
@tbm

This comment has been minimized.

Copy link
Contributor

tbm commented Mar 18, 2019

@mbudde is on vacation.

@jwiegley can you look at this?

mbudde added a commit to mbudde/ledger that referenced this issue Mar 31, 2019

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 ledger#1775

@tbm tbm closed this in c4eab00 Apr 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.