-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
add getDate() method for #80 #82
Conversation
…m the Personnummer object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the pull request!
The code looks good, I'd just love a check on the actual output in the tests and I'll happily merge it :)
@Johannestegner The existing code with below test case sets the {
"integer": 0,
"long_format": "19090527 1474",
"short_format": "090527 1474",
"separated_format": "090527 1474",
"separated_long": "19090527 1474",
"valid": false,
"type": "ssn",
"isMale": true,
"isFemale": false
} I am currently using Integer expected = Integer.valueOf(ssn.longFormat.substring(0,4));
int actual = entry.getDate().getYear();
assertEquals(expected, actual, "expected = " + expected + "\n" + "Actual = " + actual); and can switch to the following if the existing logic is sure to be correct: Integer expected = Integer.valueOf(getFullYear());
int actual = entry.getDate().getYear();
assertEquals(expected, actual, "expected = " + expected + "\n" + "Actual = " + actual); |
When it comes to the short format, we always have to guess which century the number is for, so that one is expected. So the full year should be correct to use. Easiest way to handle this in the tests would be to just check on the decade value instead of the full year in the assert :) |
In the C# package, I format the value from the Date object as a |
Will not the short format also have a separator either of |
There are basically four formats we support as input: long: 198510033999 The There should be no space, and if the data downloaded from the meta repository by the tests contains that there must be an error. I'll double check that :) |
Aaah I double checked the meta (and then again looked at the code you shown) and that number is invalid (due to the space), so it should fail in the parse even :) |
src/test/java/PersonnummerTest.java
Outdated
// Integer expected = Integer.valueOf(ssn.longFormat.substring(0,4)); | ||
String actual = String.valueOf(entry.getDate().getYear()); | ||
|
||
assertEquals(expected, actual, "expected = " + expected + "\n" + "Actual = " + actual); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking checking all the four parts here, YY MM and DD.
Just against a simple format would work fine:
// something like...
assertEquals(ssn.longFormat.substring(2, 6), date.getYear() + date.getMonth() + date.getDay());
Although, I'd guess that the date object have some type of format function with a string value to pass (yyMMdd would do in that case I would imagine).
With that I'll happily merge the PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll add the dates and months. I totally forgot with this century issue popping up.
yeah, looks like an issue with regex, I added a space as an additional option, and it fails many other tests, I am not sure of the other possible patterns. Does the updated PR look fine to you? It passes the tests with |
Yes, looks good to me! :) Thank you for the pull request! |
…m the Personnummer object
Type of change
Description
Add the getDate method for #80
Related issue
Closes #80Motivation
All good.
Checklist