Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ddleap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- ddnleap = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- class MyDate:
- def __init__(self, dd, mm, yy):
- self.day = dd
- self.month = mm
- self.year = yy
- def setleap(year):
- '''calcola la bisestilità dell'anno'''
- if not (year % 400) or (not (year % 4) and year % 100):
- self.leap = True
- else:
- self.leap = False
- setleap(yy)
- if self.leap:
- self.mmdays = ddleap
- else:
- self.mmdays = ddnleap
- def setesimo(leap):
- '''calcola il numero ordinale del giorno nell'anno inserito tenendo conto della bisestilitò'''
- ddth = 0
- for index, ai in enumerate(self.mmdays):
- if index >= self.month - 1:
- ddth += self.day
- break
- else:
- ddth += ai
- self.ordinale = ddth
- setesimo(self.leap)
- def sumdate(self, num):
- '''calcola la nuova data sommando il num'''
- month = self.month - 1
- year = self.year
- mmdays = self.mmdays
- def myupdate(month, year):
- month += 1
- if not month % 12:
- month = 0
- year += 1
- distance = mmdays[month] - self.day
- if num <= distance:
- return str(str(self.day + num) + "/" + str(month + 1) + "/" + str(year))
- num -= distance
- month += 1
- if not month % 12:
- month = 0
- year += 1
- while num > mmdays[month]:
- if not (year % 400) or (not (year % 4) and year % 100):
- leap = True
- else:
- leap = False
- if leap:
- mmdays = ddleap
- else:
- mmdays = ddnleap
- num -= mmdays[month]
- month += 1
- if not month % 12:
- month = 0
- year += 1
- return str(str(num) + "/" + str(month + 1) + "/" + str(year))
- a = MyDate(5, 8, 2021)
- if __name__ == '__main__':
- print(a.day, a.month, a.year, "\n" + a.sumdate(5000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement