Michael Sims
Paul Clapham wrote:So then you have two choices: you can manipulate your date strings to conform with that DateFormat object, or you can create a different DateFormat object which does match those strings.
Michael Sims
Paul wrote: isn't consistent with the strings you're trying to parse. If you write some code which formats a date (e.g. now) and examine the output, you should see the difference.
So then you have two choices: you can manipulate your date strings to conform with that DateFormat object, or you can create a different DateFormat object which does match those strings.
Michael Sims
Stefan Evans wrote:1: When you post code, post a fully contained sample that can compiled.
Stefan Evans wrote:2: Give an indication of the input for your program.
Stefan Evans wrote:3: Possibly also break up your code into modules.
Stefan Evans wrote:My suggestion would be to use the java.text.SimpleDateFormat class to try and parse the input date.
Michael Sims
Stefan Evans wrote:Ok just to point this out: Carey has spotted that you have a tab separated file that you're reading in with a predictable format.
Stefan Evans wrote:You could even go a step further and define a java object to represent each line. Once you have the data out of String form, and in memory, manipulating becomes a lot easier.
Michael Sims
Carey Brown wrote:Here's my stab at your problem.
Michael Sims
Carey Brown wrote:Eee gads! What a mess you've inherited.
Carey Brown wrote:This might be a good time to implement test-driven-development and write a slew of JUnit tests for as many possible permutations as you can come up with. That will be the only way I can see to have any confidence that you've got the bases covered. Only then would I tackle regular expressions, state machines, or whatever.
Carey Brown wrote:P.S. I hate "midnight", it is very ambiguous as far as human interpretation goes. Midnight == 00:00:00 am == first instant of the new day.
Michael Sims
Michael D Sims wrote:For example, the way that you have read in the data using an input formatter and simultaneously wrote it back out to the string in one line via the LocalDateTime.parse method is something I didn't even know was possible. I use IntelliJ to write code with, and when I type in LocalDateTime.parse and the context sensitive help pops up with all of the various uses for parse, nothing in that help speaks to me the ability to do string, inputFormatter).format(outputFormatter) ... so how is a novice supposed to figure this stuff out on his own?
Michael D Sims wrote:
Carey Brown wrote:This might be a good time to implement test-driven-development and write a slew of JUnit tests for as many possible permutations as you can come up with. That will be the only way I can see to have any confidence that you've got the bases covered. Only then would I tackle regular expressions, state machines, or whatever.
Can you elaborate on this for me? "JUnit tests"??
Carey Brown wrote:
In test-driven-development the idea is to write the tests first, which of course, will fail. And one by one add the necessary additions to your business logic until all test cases pass.Michael D Sims wrote:
Can you elaborate on this for me? "JUnit tests"??Carey Brown wrote:This might be a good time to implement test-driven-development and write a slew of JUnit tests
Michael Sims
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|