Skip to content

Instantly share code, notes, and snippets.

@RatoX
Last active September 11, 2018 14:58
Show Gist options
  • Save RatoX/971438c5d28be318ad6db61da963ee9c to your computer and use it in GitHub Desktop.
Save RatoX/971438c5d28be318ad6db61da963ee9c to your computer and use it in GitHub Desktop.
Aula FATEC LP01
# The MIT License (MIT)
#
# Copyright (c) 2018 RatoX
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
day = int(input('Digite o dia: '))
month = int(input('Digite o mes: '))
year = int(input('Digite o ano: '))
invalidDate = False
leadYear = False
_31DaysMonth = True
if day < 1 or day > 31:
invalidDate = True
if month < 1 or month > 12:
invalidDate = True
# tu pode usar a forma long tambem
# if month == 4 or month == 6
if month in [4, 6, 9, 11] and day == 31:
_31DaysMonth = False
invalidDate = True
elif month == 2:
_31DaysMonth = False
# Verificar ano bissexto
if ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0):
leadYear = True
if month == 2 and day > 29:
invalidDate = True
else:
if month == 2 and day > 28:
invalidDate = True
if invalidDate:
print "Data Invalida"
else:
new_day = -1
if _31DaysMonth:
new_day = ( ( 31 + day ) % 31) + 1
elif leadYear and month == 2:
new_day = ( ( 29 + day ) % 29) + 1
elif month == 2:
new_day = ( ( 28 + day ) % 28) + 1
else:
new_day = ( ( 30 + day ) % 30) + 1
new_month = month
if new_day < day:
new_month = ( ( 12 + month ) % 12) + 1
new_year = year
if new_month < month:
new_year = year + 1
print "{}-{}-{}".format(new_day, new_month, new_year)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment