I have a field that has dates in different formats, called "Completion Week".
From that field, I want to make another field called "Year", where it just shows the year of the date.
So the "problematic" format, is the one that shows the date in weeks without expressing the year, for example: 1022-1028.
The weeks always go from Sunday to Saturday. So in this case, the year is 2017.
The rule that I made in the following lines, checks if the first part of that string ('1022', in the previous case) corresponds to a Sunday in the current year. If it isn't, check the same for 2016. If it isn't, checks the same for 2015, and so on, until finding a year where this condition is reached, and assigns that Year for that week.
The code works fine, but the problem is that I find it too long and not proper.
I would like to know if there's a more efficient way to carry out this script. Some piece of code with less lines, so that is more efficient and proper.