A very easy task for you!

You have to create a method, that corrects a given date string.
There was a problem in addition, so many of the date strings are broken.
Date-Format is european. That means "DD.MM.YYYY".


Some examples:

"30.02.2016" -> "01.03.2016"
"40.06.2015" -> "10.07.2015"
"11.13.2014" -> "11.01.2015"
"99.11.2010" -> "07.02.2011"

If the input-string is null or empty return exactly this value!
If the date-string-format is invalid, return null.

Hint: Correct first the month and then the day!

Have fun coding it and please don't forget to vote and rank this kata! :-) 

I have created other katas. Have a look if you like coding and challenges.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def date_correct(date):
	

Solutions:
import re
from datetime import date, timedelta

def date_correct(text):
	if not text:
		return text
	try:
		(d, m, y) = map(int, re.match('^(\\d{2})\\.(\\d{2})\\.(\\d{4})$', text).groups())
		(mo, m) = divmod(m - 1, 12)
		return (date(y + mo, m + 1, 1) + timedelta(days=d - 1)).strftime('%d.%m.%Y')
	except AttributeError:
		return None


import datetime as dt
import re

def date_correct(date):
	if isinstance(date, str) and re.fullmatch('\\d\\d\\.\\d\\d\\.\\d{4}', date):
		(d, m, y) = map(int, date.split('.'))
		(nM, m) = divmod(m - 1, 12)
		y += nM
		m += 1
		d = dt.date(y, m, 1) + dt.timedelta(days=d - 1)
		return f'{d.day:02}.{d.month:02}.{d.year:02}'
	if date == '':
		return ''


from datetime import date, timedelta
get_date = __import__('re').compile('(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)').search

def date_correct(my_date):
	if not my_date:
		return my_date
	try:
		(d, m, y) = map(int, get_date(my_date).groups())
	except AttributeError:
		return
	return (date(y + (m - 1) // 12, (m - 1) % 12 + 1, 1) + timedelta(d - 1)).strftime('%d.%m.%Y')


import datetime
import re

def date_correct(date):
	if not date:
		return date
	if not re.fullmatch('(\\d\\d\\.){2}\\d{4}', date):
		return None
	(d, m, y) = [int(x) for x in date.split('.')]
	if m > 12:
		y += m // 12
		m %= 12
		if not m:
			m = 12
			y -= 1
	return (datetime.datetime(year=y, month=m, day=1) + datetime.timedelta(days=d - 1)).strftime('%d.%m.%Y')


from datetime import date, timedelta
import re

def date_correct(s):
	if s == '':
		return ''
	try:
		m = re.match('\\A(\\d{2})\\.(\\d{2})\\.(\\d{4})\\Z', s)
	except:
		return None
	if not m:
		return None
	(d, m, y) = map(int, m.groups())
	d -= 1
	(cy, m) = divmod(m - 1, 12)
	return (date(y + cy, m + 1, 1) + timedelta(d)).strftime('%d.%m.%Y')


def date_correct(date):
	if date in ('', 0, None):
		return date
	from re import findall
	date = findall('\\A(\\d{2})\\.(\\d{2})\\.(\\d{4})\\Z', date)
	if len(date) == 0:
		return None
	import datetime
	date = [int(x) for x in date[0][::-1]]
	date[0] += (date[1] - 1) // 12
	date[1] = (date[1] - 1) % 12 + 1
	newdate = datetime.date(date[0], date[1], 1)
	newdate += datetime.timedelta(days=date[2] - 1)
	return '{0:02d}.{1:02d}.{2}'.format(newdate.day, newdate.month, newdate.year)


from re import match
from datetime import date as ymd, timedelta
date_correct = lambda date: '' if date == '' else None if date == None or not match('\\d\\d\\.\\d\\d\\.\\d{4}', date or '') else (lambda d, m, y: (ymd(y + (m - 1) // 12, (m - 1) % 12 + 1, 1) + timedelta(d - 1)).strftime('%d.%m.%Y'))(*map(int, date.split('.')))


from datetime import datetime, timedelta
from re import fullmatch

def date_correct(date):
	if isinstance(date, str):
		if not date:
			return ''
		if fullmatch('\\d{2}\\.\\d{2}\\.\\d{4}', date):
			(day, month, year) = map(int, date.split('.'))
			(extra_year, month) = divmod(month - 1, 12)
			return (datetime(year + extra_year, month + 1, 1) + timedelta(day - 1)).strftime('%d.%m.%Y')


import datetime

def date_correct(date):
	print(date)
	if date is None or date is '':
		return date
	try:
		(day, month, year) = date.split('.')
		if len(day) is not 2 or len(month) is not 2:
			return None
		day = int(day)
		month = int(month)
		year = int(year)
	except:
		return None
	extra_years = month // 12
	if month >= 12 and month % 12 == 0:
		extra_years -= 1
	year = year + extra_years
	correct_months = month % 12
	if correct_months == 0:
		correct_months = 12
	print(date, year, correct_months)
	result = datetime.datetime(year=year, month=correct_months, day=1)
	result += datetime.timedelta(days=day - 1)
	print(result)
	return '.'.join([str(value).zfill(2) for value in [result.day, result.month, result.year]])


import re

def date_correct(date):
	if not date:
		return date
	days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
	if not bool(re.match('\\d{2}\\.\\d{2}\\.\\d{4}', date)):
		return None
	(d, m, y) = list(map(int, date.split('.')))
	while m > 12 or d > days[m - 1]:
		y += (m - 1) // 12
		m = (m - 1) % 12 + 1
		if y % 4 == 0 and y % 100 != 0 or y % 400 == 0:
			days[1] = 29
		else:
			days[1] = 28
		if d > days[m - 1]:
			d -= days[m - 1]
			m += 1
	return '{:02}.{:02}.{}'.format(d, m, y)