We have a requirement in java to validate the local time before it is passed to scheduler like quartz. System receives London local time say 01:30 AM but this time in not valid on March 26 2017 (daylight savings). How do I write a code to output below results?
Input
12:30, 01:30, 02:30
Output
Mar 26 2017 12:30 -> Valid, GMT
Mar 26 2017 01:30 -> Invalid, NA
Mar 26 2017 02:30 -> Valid, BST
Assuming that you start with a LocalDateTime then you can test to see if it's valid for scheduling by seeing if a given timezone reports that there are valid offsets for the time. This info is available in the ZoneRules class.
Here's some sample code:
If the list of validOffsets is empty then it's not a valid time. If there is more than 1 entry then the time occurs multiple times in that zone (the case of putting the clocks back). If there's a single entry, then it's a regular time.
You'd probably want to fail on an empty list and warn on a list with multiple entries.