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

import Time in function Import from CSV in case it is available #4555

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pyBlockDev
Copy link

Closes #4554

@pfalcon
Copy link
Contributor

pfalcon commented Feb 27, 2025

Normal time format is HH:mm:ss. This change adhocly applies some random time format instead.

@pyBlockDev
Copy link
Author

Hi @pfalcon,

yes you are right. In my usecase if I export the depot, then PP generates this:

image

This is now possible to read back with PP.
But if somebody has the T10:33:11 then we get an exception. If I use HH:mm:ss then my examples get an exception.
Maybe we could count the number of ":" and make a case decision.
What do you think?

@Nirus2000
Copy link
Member

Hello @pyBlockDev
Thank you for the pull request.
If you take your time again, it would be good to have a look at the Contributing rules and of course check the test case for your change in your branch or create a suitable one.

Regards
Alex 😀

@Nirus2000 Nirus2000 requested a review from buchen February 28, 2025 14:55
@Nirus2000 Nirus2000 added the ! Good first pull request ! First pull request !! Keep friendly :-) label Feb 28, 2025
@pyBlockDev
Copy link
Author

pyBlockDev commented Mar 1, 2025

Hi @Nirus2000,

thanks for your hint. I have added the testcases. Additional I have rechanged the code, used the existing structure and tried to simplify it.

Comment on lines +157 to +196
public void testTransferTransactionDateContainsTimeAndTimeColumn()
{
Client client = new Client();
Security security = new Security();
security.setTickerSymbol("SAP.DE");
client.addSecurity(security);

CSVExtractor extractor = new CSVPortfolioTransactionExtractor(client);

List<Exception> errors = new ArrayList<>();
List<Item> results = extractor.extract(0,
Arrays.<String[]>asList(new String[] { "2013-01-01T14:05", "10:07", "DE0007164600", "SAP", "",
"SAP SE", "100", "EUR", "11", "10", "", "", "", "1,2", "TRANSFER_IN",
"Notiz" }),
buildField2Column(extractor), errors);

assertThat(errors, empty());
assertThat(results.size(), is(1));
new AssertImportActions().check(results, CurrencyUnit.EUR);

PortfolioTransferEntry entry = (PortfolioTransferEntry) results.stream()
.filter(PortfolioTransferItem.class::isInstance).findAny()
.orElseThrow(IllegalArgumentException::new).getSubject();

PortfolioTransaction source = entry.getSourceTransaction();
assertThat(source.getType(), is(PortfolioTransaction.Type.TRANSFER_OUT));
assertThat(source.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
assertThat(source.getNote(), is("Notiz"));
assertThat(source.getDateTime(), is(LocalDateTime.parse("2013-01-01T10:07")));
assertThat(source.getShares(), is(Values.Share.factorize(1.2)));
assertThat(source.getSecurity(), is(security));
// security transfers do not support fees and taxes at the moment
assertThat(source.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 0)));
assertThat(source.getUnitSum(Unit.Type.TAX), is(Money.of("EUR", 0)));

PortfolioTransaction target = entry.getTargetTransaction();
assertThat(target.getType(), is(PortfolioTransaction.Type.TRANSFER_IN));
assertThat(target.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 0)));
assertThat(target.getUnitSum(Unit.Type.TAX), is(Money.of("EUR", 0)));
}
Copy link
Member

@Nirus2000 Nirus2000 Mar 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrays.<String[]>asList(new String[] { "2013-01-01T14:05", "10:07", "DE0007164600", "SAP", "",
                                        "SAP SE", "100", "EUR", "11", "10", "", "", "", "1,2", "TRANSFER_IN",
                                        "Notiz" }),

Test result

assertThat(source.getDateTime(), is(LocalDateTime.parse("2013-01-01T10:07")));
assertThat(target.getDateTime(), is(LocalDateTime.parse("2013-01-01T10:07")));

you set the time to "T14:05" but in the result is "10:07"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is right, the reason is the Time column has a higher priority then the (Date+T) column in the PR implementaion. I thought about the possibility that somebody

  1. defines a Time in the date column with the "THH:MM" notation and
  2. also in the Time column.

In my opinion this is an error in the csv file, but I thought maybe it is better to handle this with a priority of the Time column and the current beahvior of the PP. Because at the moment in PP if the Time column is defined then this is used.

The PR has the following new behavior:

  • if the Date column contains the "THH:mm" text and no Time column is defined, then the time is used from the Date
  • if the Date column contains the "THH:mm" text and Time column is defined, then the time is used from the Time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
! Good first pull request ! First pull request !! Keep friendly :-)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time is ignored in CSV Importer
4 participants