A Date (containing
yyyy). A date-object, or three separate integers are also valid as input.
Each part (
yyyy) individually reverted and than rounded to the nearest valid date.
For example (in the format
yyyyis valid, but the order and which separate-symbols you use is your own choice.
So these are some valid format examples:
yyyy MM dd;
And these are some invalid format examples:
dd MMM yyyy;
- You can also choose to just input a Date-object if your language supports it or three separate integer parameters, instead of the string representing a date.
- Please state which date-format you've used! (And the input and output must be in the same format.) It is also allowed to output a Date-object, as long as it can handle all test cases and the challenge rule below.
- The Julian to Gregorian Calendar transition is ignored for this challenge. So
1582is just a valid reversed year for
See Challenge info / tips for all valid years, months and days.
- Since you cannot have February as reversed of any other month, you don't have to worry about leap years.
All reversed years, months and days:
- The year can always be reversed without a problem, reaching from 0001 (reversed of
1000) to 9999 (remains
0000isn't a valid input, and there are also no test cases for it.)
- The only months you'll have reversed are: January (reversed from October /
10); October (reversed from January /
01); November (remains November /
11); and December (reversed from every other month /
- The only days you'll have reversed are: 01 (reversed from
10), 02 (reversed from
20), 03 (reversed from
30), 10 (reversed from
01), 11 (remains
11), 12 (reversed from
21), 13 (reversed from
31), 20 (reversed from
02), 21 (reversed from
12), 22 (remains
22), 30 (reversed from
03or the same as 31 for November!), 31 (reversed from
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return statements/output, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
Test cases (
dd-MM-yyyy as format):
21-07-2016 -> 12-12-6102 12-11-1991 -> 21-11-1991 01-01-2000 -> 10-10-0002 27-08-1875 -> 31-12-5781 18-12-2010 -> 31-12-0102 13-01-1981 -> 31-10-1891 04-11-1671 -> 30-11-1761 // Semi-tricky case, since November has 30 days 28-11-2036 -> 30-11-6302 // Semi-tricky case, since November has 30 days 14-06-1855 -> 31-12-5581 30-10-9999 -> 03-01-9999 01-01-2851 -> 10-10-1582