can you add some comments to describe the logic, may be with an example of the date formats that are being processed