Input:
A Date (containing dd
, MM
and yyyy
). A date-object, or three separate integers are also valid as input.
Output:
Each part (dd
, MM
and yyyy
) individually reverted and than rounded to the nearest valid date.
For example (in the format dd-MM-yyyy
):
21-10-2016
becomes 12-01-6102
Challenge rules:
- Only
dd
,MM
,yyyy
is valid, but the order and which separate-symbols you use is your own choice.
So these are some valid format examples:dd-MM-yyyy
;MM/dd/yyyy
;yyyy MM dd
;ddMMyyyy
, etc.
And these are some invalid format examples:dd MMM yyyy
;dd-MM-'yy
; etc. - 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
1582
is just a valid reversed year for2851
.
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 (remains9999
). (So0000
isn'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 /02
-09
,12
). - The only days you'll have reversed are: 01 (reversed from
10
), 02 (reversed from20
), 03 (reversed from30
), 10 (reversed from01
), 11 (remains11
), 12 (reversed from21
), 13 (reversed from31
), 20 (reversed from02
), 21 (reversed from12
), 22 (remains22
), 30 (reversed from03
or the same as 31 for November!), 31 (reversed from04
-09
/13
-19
/23
-29
).
General rules:
- 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
21-07-2016
is reverted12-70-6102
which is rounded to12-12-6102
. Not sure how you get the result##-10-6107
.. \$\endgroup\$70
wrapped around, with the year incrementing. \$\endgroup\$10-10-2
valid output in the third case? \$\endgroup\$