Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import calendar
- import math
- class Date(object):
- def __init__(self, day, month, year, hour, minute, second, zone):
- self.day = day
- self.month = month
- self.year = year
- self.hour = hour
- self.minute = minute
- self.second = second
- self.zone = zone
- def print(self):
- print(self.hour, self.minute, self.second)
- def from_start(self):
- monthDate = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- if calendar.isleap(self.year):
- monthDate[1] += 1
- days = 0;
- for i in range(1, self.year):
- days += 365
- if calendar.isleap(i):
- days += 1
- for i in range(1, self.month):
- days += monthDate[i - 1];
- days += self.day - 1;
- return days
- def __sub__(self, date2):
- result = abs(self.from_start() - date2.from_start()) * 86400
- print(result)
- result -= date2.hour * 3600 + date2.minute * 60 + date2.second;
- result += self.hour * 3600 + self.minute * 60 + self.second;
- return result
- def get_days_of_month(self, month, year):
- monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- if calendar.isleap(year):
- monthDays[1] += 1
- return monthDays[month - 1]
- def get_tomorrow(self):
- self.hour -= 24
- days = self.get_days_of_month(self.month, self.year)
- self.day += 1
- if self.day > days:
- self.day = 1
- self.month += 1
- if self.month > 12:
- self.year += 1
- self.month = 1
- def get_yesterday(self):
- self.hour += 24
- self.day -= 1
- if self.day < 1:
- self.month -= 1
- if self.month < 1:
- self.month = 12
- self.year -= 1
- self.day = self.get_days_of_month(self.month, self.year)
- def to_GMT(self):
- if self.zone.startswith("-"):
- self.hour += int(self.zone[1:3])
- self.minute += int(self.zone[3:5])
- if self.minute >= 60:
- self.hour += 1
- self.minute -= 60
- if self.hour >= 24:
- self.get_tomorrow()
- else:
- self.hour -= int(self.zone[1:3])
- self.minute -= int(self.zone[3:5])
- if self.minute < 0:
- self.hour -= 1
- self.minute += 60
- if self.hour < 0:
- self.get_yesterday()
- def change(arr):
- # Sun 10 May 2015 13:54:36 -0700
- # 0 1 2 3 4 5
- month = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
- arr[1] = int(arr[1])
- arr[2] = month.index(arr[2])
- arr[3] = int(arr[3])
- zone = arr.pop()
- time = map(int, arr.pop().split(":"))
- for item in time:
- arr.append(item)
- arr.append(zone)
- arr = arr[1:]
- return arr
- def is_later(date1, date2):
- if (date1.year > date2.year):
- return 2
- elif (date1.year < date2.year):
- return 0
- else:
- if (date1.month > date2.month):
- return 2
- elif (date1.month < date2.month):
- return 0
- else:
- if (date1.day > date2.day):
- return 2
- elif (date1.day < date2.day):
- return 0
- else:
- if (date1.hour > date2.hour):
- return 2
- elif (date1.hour < date2.hour):
- return 0
- else:
- if (date1.minute > date2.minute):
- return 2
- elif (date1.minute < date2.minute):
- return 0
- if (date1.second > date2.second):
- return 2
- elif (date1.second < date2.second):
- return 0
- else:
- return 1
- s1 = change(input().split())
- s2 = change(input().split())
- date1 = Date(*s1)
- date2 = Date(*s2)
- date1.to_GMT()
- date2.to_GMT()
- if is_later(date2, date1):
- sec = (date2 - date1)
- else:
- sec = (date1 - date2)
- print(sec)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement