From 8fb2ea7ebab16bbb093882fdf08328d819dfe1fc Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Thu, 20 Oct 2022 19:28:46 +0100 Subject: - Added guest contributions by Eric Cheung. --- challenge-187/eric-cheung/python/ch-1.py | 79 ++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 challenge-187/eric-cheung/python/ch-1.py (limited to 'challenge-187/eric-cheung/python/ch-1.py') diff --git a/challenge-187/eric-cheung/python/ch-1.py b/challenge-187/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..8e0a62a969 --- /dev/null +++ b/challenge-187/eric-cheung/python/ch-1.py @@ -0,0 +1,79 @@ + +import datetime + +nYear = 2022 + +## DD-MM + +## Example 1 +strFooStartDate = "12-01" +strFooEndDate = "20-01" + +strBarStartDate = "15-01" +strBarEndDate = "18-01" + + +## Example 2 +# # strFooStartDate = "02-03" +# # strFooEndDate = "12-03" + +# # strBarStartDate = "13-03" +# # strBarEndDate = "14-03" + + +## Example 3 +# # strFooStartDate = "02-03" +# # strFooEndDate = "12-03" + +# # strBarStartDate = "11-03" +# # strBarEndDate = "15-03" + + +## Example 4 +# # strFooStartDate = "30-03" +# # strFooEndDate = "05-04" + +# # strBarStartDate = "28-03" +# # strBarEndDate = "02-04" + + +def GetConvDate(strInputDate): + + arrInputDate = strInputDate.split("-") + return datetime.datetime(nYear, int(arrInputDate[1]), int(arrInputDate[0])) + + +objFooStartDate = GetConvDate(strFooStartDate) +objFooEndDate = GetConvDate(strFooEndDate) +objBarStartDate = GetConvDate(strBarStartDate) +objBarEndDate = GetConvDate(strBarEndDate) + + +bFlag = False + + +if objFooStartDate < objBarStartDate: + if objFooEndDate >= objBarStartDate: + objStartDate = objBarStartDate + bFlag = True +else: + if objBarEndDate >= objFooStartDate: + objStartDate = objFooStartDate + bFlag = True + + +if bFlag: + if objFooEndDate < objBarEndDate: + objEndDate = objFooEndDate + else: + objEndDate = objBarEndDate + + objDay = objEndDate - objStartDate + nDay = objDay.days + 1 + + if nDay > 1: + print(str(nDay) + " days") + else: + print(str(nDay) + " day") +else: + print ("0 day") -- cgit