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

Use date separator from file #48

Closed
bradyt opened this issue Oct 17, 2019 · 26 comments
Closed

Use date separator from file #48

bradyt opened this issue Oct 17, 2019 · 26 comments
Labels
formatting Issues related to how cone formats the transactions written to disk

Comments

@bradyt
Copy link
Owner

bradyt commented Oct 17, 2019

An IRC user suggests they prefer "/" to "-" as date separator. It might be easy to just parse the date separator from the first transaction in the file, and use that for new transactions.

@delexi
Copy link

delexi commented Oct 30, 2019

What about the case where there is no transaction in the file?

@bradyt
Copy link
Owner Author

bradyt commented Oct 30, 2019

How about "-"?

@delexi
Copy link

delexi commented Nov 3, 2019

You mean, just hard code a fall back?

Let me explain where I am coming from, maybe that is a use case worth considering: I use cone as an inbox where I enter transactions while I am on the go. Every one or two weeks I import those transactions into my ledger file, clear the inbox file written to by cone and start over. The first transaction would now use "/" as a separator, as cone is faced with an empty file. For whatever reason (I cannot remember), I use "/" as a date separator. Hard coding a fallback will always choose the wrong separator in my use case. The only solution to my problem would be a setting in cone, as far as I can see.

At the moment, I am just replacing the "-" with "/" in my import script, so I have a working setup. I just wanted to give you one more data point to consider.

@bradyt
Copy link
Owner Author

bradyt commented Nov 3, 2019

Thank you for expanding on the scenario.

I don't think beancount even allows "/". Hledger has an open issue (933) to move from "/" to "-". I think the reasoning for both is that "-" is suggested by ISO 8601.

What breakage do you see if your import does not convert "-" to "/"?

Should we get date separator from most recently added transaction, instead of the first?

In general, I think a good goal is to reduce and minimize how many settings need to be done in cone's settings page.

Potentially we could have a second auxiliary journal file, that could hold lists of accounts, commodity directives, etc. Maybe we could search that file for date formats, even if it's in comments.

@ghost
Copy link

ghost commented Nov 3, 2019

I think this issue spans more than just date formatting, in general, how cone formats entries might be different from how the user does (e.g. it's wildly different for me).

If this were desktop I'd have suggested some script to format the output, but I doubt that's appropriate for Android. Perhaps an alternate solution is one akin to what I've done in some of my python software

A solution like that knocks out two birds in one stone: it consists of a single option and makes for a highly flexible formatter

@bradyt
Copy link
Owner Author

bradyt commented Nov 4, 2019

@w1d3m0d3 There's an existing issue for indentation of postings and alignment of amounts, at #33. Are there other differences in how cone formats entries from how the user might? Specifics would make the discussion easier for me.

@bradyt bradyt added the formatting Issues related to how cone formats the transactions written to disk label Nov 4, 2019
@justinjk007
Copy link
Contributor

justinjk007 commented Jan 11, 2020

Mmmm this problem annoys me too much. Can I start working on parsing the file to find the separator and falling back to '-' like @bradyt says lol?

Hi, I was doing some research before making a ledger entry app myself and I stumbled upon, I was surprised again when I saw this was written in flutter. I was surprised again when I saw the guy who wrote the dart server mode wrote this. I've been using the app for couple of weeks now and so far so good.

@bradyt
Copy link
Owner Author

bradyt commented Jan 12, 2020

Greetings @justinjk007,

Can I start working on parsing the file to find the separator and falling back to '-' like @bradyt says lol?

Yes, that sounds great!

I was surprised again when I saw the guy who wrote the dart server mode wrote this.

Hrm. I wouldn't take much credit. But let's spare other readers from trying to clarify this further, perhaps it is off-topic enough. There are the git histories, if anyone is curious.

I've been using the app for couple of weeks now and so far so good.

Great to hear!

@justinjk007
Copy link
Contributor

justinjk007 commented Jan 12, 2020

Well, I've been jumping around the source for an hour now, I have came to the conclusion to add a new date format variable in file_model.dart and then fill the format after inspecting the code from the refreshContents function. Will that be alright ?

When I messed with flutter in the past I didn't pay much attention to managing state so having a set of model files to manage state is new to me ? Is this what you call scoped model or is this bloc ? IF I want to look into any of those.

Edit: I've done this checkout my PR #55

@bradyt
Copy link
Owner Author

bradyt commented Jan 12, 2020

Hmm. Unfortunately I would like to take one step backwards in this conversation. I was being too brief in my original reply.

Why aren't you using '-' for date separator? Are you using an older hledger? At this point, all the popular plaint text ledger apps are preferring '-'.

When I messed with flutter in the past I didn't pay much attention to managing state so having a set of model files to manage state is new to me ? Is this what you call scoped model or is this bloc ? IF I want to look into any of those.

I'm just using Provider. Strictly speaking, I'm not using a state management framework. My interpretation is, we are using Provider to lift the state and logic out of the presentation code, so that it can be organized independently. Beyond that, state and logic are just organized according to my humble intuition.

@justinjk007
Copy link
Contributor

justinjk007 commented Jan 12, 2020

I use ledger cli, not even hledger. Also the code I wrote checks if the
user uses / or then fall backs to - for default. Do we not want that
anymore? / is what ledger-cli uses by default.

@bradyt
Copy link
Owner Author

bradyt commented Jan 12, 2020

Ah, I see, from https://www.ledger-cli.org/3.0/doc/ledger3.html,

The default uses a date like ‘2004/08/01’, which represents the default date format of %Y/%m/%d.

I just filed an issue at ledger, at ledger/ledger#1853. Let's see how that goes.

Note that hledger just merged a pull request in the last two weeks, regarding the date separator, at simonmichael/hledger#1157.

@justinjk007
Copy link
Contributor

I'm sure many people will have this problem for the time being, why not support both ?

@bradyt
Copy link
Owner Author

bradyt commented Jan 12, 2020

Unfortunately, with my current schedule, this is not at the top of my priority list, so I can't immediately consider all facets of this.

This might help in the mean time, provided by a user on IRC Freenode's #ledger.

I have this in my .ledgerrc:

; Use ISO 8601 dates and times.
--date-format %Y-%m-%d
--datetime-format %Y-%m-%dT%H:%M:%S

@justinjk007
Copy link
Contributor

justinjk007 commented Jan 12, 2020 via email

@bradyt
Copy link
Owner Author

bradyt commented Jan 13, 2020

I will try to merge this either way.

But let's try to introduce as few features as possible. Potentially, if this is in cone forever, we could take a few steps to avoid breaking someone's workflow by a future change.

Can we limit to beginning of line? In other words, might we replace

r'[0-9]{4}/[0-9]{2}/[0-9]{2}'

with the following?

r'^[0-9]{4}/[0-9]{2}/[0-9]{2}'

I think even r'^[0-9]+/' could suffice. But one might consider that less readable.

@justinjk007
Copy link
Contributor

justinjk007 commented Jan 13, 2020 via email

@bradyt bradyt added the partially done For example, if the most commonly experienced aspect of issue has been treated label Jan 13, 2020
@bradyt
Copy link
Owner Author

bradyt commented Jan 15, 2020

@justinjk007 's solution is available at https://github.com/bradyt/cone/tree/629445b7c3098fb91874b559ebab99408adaf1f9, and on Google Play as version 0.2.19. Hoping to push to F-Droid soon.

As the issue is raised, I think this solution is complete enough. We have omitted the case of other date separator's, such as '.', but I presume this is very rare. I think if someone comments here, we could quickly fix.

As for the other issues, I think they are very good ideas and questions. But I think they can be raised as new issues, for focussed discussion.

In particular, I would like it if we found a neat idea, for how GUI applications can be configured to work with plain text data files. Would we pass cli-like args in an auxiliary file? I would like to minimize the amount of configuration occurring in the cone app,

If you feel this needs to be reopened, let me know. Given the open-ended aspect of this thread, I think it's okay to comment here as well, if you prefer.

Thanks all, for the ideas and solutions!

@bradyt bradyt closed this as completed Jan 15, 2020
@Anachron
Copy link

Anachron commented Feb 20, 2020

We have omitted the case of other date separator's, such as '.', but I presume this is very rare.

I'm from Europe and actually use ., like any other country here. Not sure why you say its rare. https://en.wikipedia.org/wiki/Date_format_by_country

--input-date-format %d.%m.%Y
--date-format %d.%m.%Y

@bradyt
Copy link
Owner Author

bradyt commented Feb 20, 2020

@Anachron I haven't reviewed the code completely, but I think I've moved that logic to this:

  (List<Transaction> transactions) => (transactions.last.date.contains('/'))
      ? DateFormat('yyyy/MM/dd')
      : DateFormat('yyyy-MM-dd'),

So then we could add one more test and potentially output DateFormat('yyyy.MM.dd')?

@bradyt bradyt reopened this Feb 20, 2020
@Anachron
Copy link

You mean DateFormat('dd.MM.yyyy'), right?

Yeah, sure, go ahead. :)

@bradyt
Copy link
Owner Author

bradyt commented Feb 20, 2020

You mean DateFormat('dd.MM.yyyy'), right?

No.

If you would like a feature added, can you file a new issue, with a title like, "Write dates as day month year", little-endian dates or whatever?

Yeah, sure, go ahead. :)

I don't know when I'll get around to adding period as date separator, FYI. Pull requests welcome.

@bradyt
Copy link
Owner Author

bradyt commented Feb 20, 2020

The good news is, I think we could avoid adding a feature to the Settings page. hledger author points out to me, the option can be in file.

> cat blah.dat
; -*- ledger -*-

--date-format %d.%m.%Y
--input-date-format %d.%m.%Y

18.02.2020 hello world
    expenses:blah         30.00 USD
    assets:checking      -30.00 USD
> ledger -f blah.dat print
18.02.2020 hello world
    expenses:blah                          30.00 USD
    assets:checking

@bradyt
Copy link
Owner Author

bradyt commented Feb 23, 2020

Presumably fixed at 519be58.

@bradyt bradyt closed this as completed Feb 23, 2020
@justinjk007
Copy link
Contributor

justinjk007 commented Feb 23, 2020 via email

@bradyt
Copy link
Owner Author

bradyt commented Feb 23, 2020

The format requested is dd.MM.yyyy, year comes last which is different from the format you added. I think just looking into the date separator is not enough anymore. We gotta look for the whole format and use that instead.
[…]

@justinjk007 I feel I replied to this aspect with the following:

If you would like a feature added, can you file a new issue, with a title like, "Write dates as day month year", little-endian dates or whatever?

In other words, I feel this issue deserves its own thread. Anyone is welcome to start that thread.

@bradyt bradyt removed the partially done For example, if the most commonly experienced aspect of issue has been treated label Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatting Issues related to how cone formats the transactions written to disk
Projects
None yet
Development

No branches or pull requests

4 participants