Add a starting year by using SimpleDateFormat.set2DigitYearStart, the exact year will be calculated be a threshold number.
Example:
Birth Date: Start date will be 99 years ago from the present year e.g. 2023 - 99 = 1924. It means the lowest year will be 1924 and highest will be 2023.
240101 -> 01/01/1924
230101 -> 01/01/2023
Expiry Date: Start date will be 49 years ago from the present year e.g. 2023-49 = 1974.
740101 -> 01/01/1974
730101 -> 01/01/2073
You can quick check the logic here in this online editor link
Changes
Add new func stringToDate2DigitsYear to handle 2 digits year.
Add threshold number for birth date and expiry date.
Add new param to where it's using the default format yyMMdd
Issue
Date parsing for 2 digits when using SimpleDateFormat returns unexpected birth date Example:
yyMMdd 420101 -> dd/MM/yyyy 01/01/2042
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
Solution:
Add a starting year by using
SimpleDateFormat.set2DigitYearStart
, the exact year will be calculated be a threshold number.Example:
You can quick check the logic here in this online editor link
Changes