From e36db594cd97e8880ae6d0910a89ae6c62f98986 Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Mon, 10 Jun 2019 23:36:06 +0530 Subject: [PATCH 01/15] Day 2, Q1 Solution. Forked form PyLenin - Q1 solved. --- .gitignore | 7 +++++++ .../Q1_BeforeChristmas.py | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 .gitignore create mode 100644 Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bff4d70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ + +.idea/encodings.xml +.idea/misc.xml +.idea/modules.xml +.idea/Python30.iml +.idea/vcs.xml +.idea/workspace.xml diff --git a/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py b/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py new file mode 100644 index 0000000..e9bd1f3 --- /dev/null +++ b/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py @@ -0,0 +1,11 @@ +# 1. What date is 3 weeks and 4 days before Christmas? + + +from datetime import timedelta, date + + +christmas_date = date(year=2019, month=12, day=25) +three_weeks_before = timedelta(weeks=3, days=4) +output = (christmas_date - three_weeks_before) +print("3 weeks and 4 days before the christmast would be ", output) + From facb2e1dc0498446abecd0ff39b41f723b267cf0 Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Mon, 10 Jun 2019 23:56:52 +0530 Subject: [PATCH 02/15] Day 2, Q2 solutions. Day 2, Q2 solutions.. good understanding about date difference via timedelta type. --- .../Q2_TimeDifference.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py diff --git a/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py b/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py new file mode 100644 index 0000000..082cb92 --- /dev/null +++ b/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py @@ -0,0 +1,15 @@ +# 2. What is the time difference between January 1, 2019 11 AM +# and May 20, 2020 22.30 PM? Mention both the days and time +# in your solution. + +from datetime import datetime, timedelta + +future_date = datetime(year=2020, month=5, day=20, hour=22, minute=30) +old_date = datetime(year=2019, month=1, day=1, hour=11) + +time_difference = future_date - old_date + +print("Difference in days.. ", (time_difference.days*24 + time_difference.seconds/3600)/24) +# Question is - what is the time difference, therefore my answer would be.. +print("Difference in hours ", time_difference.days*24 + time_difference.seconds/3600) +print("Differene in seconds", time_difference.total_seconds()) From 2335a2b301c2cd257eb494975c6a651350eda1d5 Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Tue, 11 Jun 2019 00:26:34 +0530 Subject: [PATCH 03/15] Addressing comments. @pylenin, addressed the comments, expected output is obtained. seconds component is not included as of now, let me know if needed will update that as well. --- .../Q2_TimeDifference.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py b/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py index 082cb92..2fa2c64 100644 --- a/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py +++ b/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py @@ -13,3 +13,10 @@ # Question is - what is the time difference, therefore my answer would be.. print("Difference in hours ", time_difference.days*24 + time_difference.seconds/3600) print("Differene in seconds", time_difference.total_seconds()) + +days = time_difference.days +hours = divmod(time_difference.seconds, 3600) +minutes = hours[1]/60 + +# Expected Output. +print("Time difference is ", days, " days, " , hours[0] ,"hours and ", minutes , "mins") From 7a44156acf324b84ac319042cdf41ed6442c1033 Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Tue, 11 Jun 2019 22:59:21 +0530 Subject: [PATCH 04/15] #Day3 Exercise PR PR for two problems. @pylenin please review. --- Day 3 - Datetime strftime and strptime/Q1Solution.py | 9 +++++++++ .../Q2_Solution.py | 12 ++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 Day 3 - Datetime strftime and strptime/Q1Solution.py create mode 100644 Day 3 - Datetime strftime and strptime/Q2_Solution.py diff --git a/Day 3 - Datetime strftime and strptime/Q1Solution.py b/Day 3 - Datetime strftime and strptime/Q1Solution.py new file mode 100644 index 0000000..fc73ca1 --- /dev/null +++ b/Day 3 - Datetime strftime and strptime/Q1Solution.py @@ -0,0 +1,9 @@ + +# 1. Convert 9 AM of International Women's day of 2020 to the following format. +# --> "Sunday, 8 March 2020" + + +from datetime import datetime + +womens_day = datetime(year=2020, month=3, day=8) +print(datetime.strftime(womens_day, "%A, %d %B %Y")) \ No newline at end of file diff --git a/Day 3 - Datetime strftime and strptime/Q2_Solution.py b/Day 3 - Datetime strftime and strptime/Q2_Solution.py new file mode 100644 index 0000000..1591ec1 --- /dev/null +++ b/Day 3 - Datetime strftime and strptime/Q2_Solution.py @@ -0,0 +1,12 @@ +# 2. Convert the following date string to datetime object. +# --> "Jan 20, 2019 9:30 AM" + +from datetime import datetime + + + +inputDate = datetime(year=2019, day=20, month=1, hour=9, minute=30) +print(datetime.strftime(inputDate, "%b %d, %Y %-H:%M %p")) + +dateString = "Jan 20, 2019 9:30 AM" +print(type(datetime.strptime(dateString, "%b %d, %Y %H:%M %p"))) From 1ebfbec36492eaf0ca0203a0c5bac25141f5755d Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Wed, 12 Jun 2019 10:54:33 +0530 Subject: [PATCH 05/15] Addressing comments --- .gitignore | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index bff4d70..cabcc0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,2 @@ - -.idea/encodings.xml -.idea/misc.xml -.idea/modules.xml -.idea/Python30.iml -.idea/vcs.xml -.idea/workspace.xml +.idea/ .idea/misc.xml +.DS_Store/ \ No newline at end of file From 7241a0cbffa7fca831b0939a30d4a61da749270f Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Wed, 12 Jun 2019 11:00:52 +0530 Subject: [PATCH 06/15] Reverting back conflicted commits --- .gitignore | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index ad52715..cabcc0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,2 @@ -<<<<<<< HEAD .idea/ .idea/misc.xml -.DS_Store/ -======= -.idea/encodings.xml -.idea/misc.xml -.idea/modules.xml -.idea/Python30.iml -.idea/vcs.xml -.idea/workspace.xml ->>>>>>> c4d5289e9d6f56ccea91a608a0d0625836e9cb53 +.DS_Store/ \ No newline at end of file From cf91e3500ec1d8f2c5098db9c35d961f6b334c8e Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Wed, 12 Jun 2019 11:07:04 +0530 Subject: [PATCH 07/15] Resolving conflicts and addressing comments --- .../Q1_BeforeChristmas.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py b/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py index e9bd1f3..8b68bf1 100644 --- a/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py +++ b/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py @@ -1,5 +1,7 @@ -# 1. What date is 3 weeks and 4 days before Christmas? - +""" +1. What date is 3 weeks and 4 days before Christmas? +Solution provided by Sanjay Siddha +""" from datetime import timedelta, date From 3fac6e8d117781ce11b58bcb05605c6fcc16d8a0 Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Wed, 12 Jun 2019 11:07:45 +0530 Subject: [PATCH 08/15] Q2 - resolving conflicts and addressing comments --- .../Q2_TimeDifference.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py b/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py index 2fa2c64..f1047db 100644 --- a/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py +++ b/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py @@ -1,6 +1,8 @@ -# 2. What is the time difference between January 1, 2019 11 AM -# and May 20, 2020 22.30 PM? Mention both the days and time -# in your solution. +""" +2. What is the time difference between January 1, 2019 11 AM + and May 20, 2020 22.30 PM? Mention both the days and time + in your solution. +""" from datetime import datetime, timedelta From f9990bc4c55d68d8bd2012e25aaf4e32c1b7710a Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Date: Wed, 12 Jun 2019 11:08:36 +0530 Subject: [PATCH 09/15] Changing same as original. --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index cabcc0b..659dbca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ + .idea/ .idea/misc.xml -.DS_Store/ \ No newline at end of file +.DS_Store/ From 4fcd3614ec8272829f6cc6a6ec8666146231599d Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Date: Wed, 12 Jun 2019 11:09:01 +0530 Subject: [PATCH 10/15] Same as original --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 659dbca..3c3fa9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -.idea/ .idea/misc.xml +.idea/ .DS_Store/ From 487fb15d07f2bba334c4fd9f0137a8eb7daf40b7 Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Date: Wed, 12 Jun 2019 11:09:32 +0530 Subject: [PATCH 11/15] Removing unwanted strings. --- .../Q1_BeforeChristmas.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py b/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py index 8b68bf1..839c132 100644 --- a/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py +++ b/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py @@ -1,6 +1,5 @@ """ 1. What date is 3 weeks and 4 days before Christmas? -Solution provided by Sanjay Siddha """ from datetime import timedelta, date From 853dd8a9020003d4c6c3652222091b0122e38d08 Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Wed, 12 Jun 2019 11:25:30 +0530 Subject: [PATCH 12/15] Adding docs for the solutions. Adding doscs/explanation about the solution. Would be helpful for someone who reads the code. --- .../Q2_Solution.py | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Day 3 - Datetime strftime and strptime/Q2_Solution.py b/Day 3 - Datetime strftime and strptime/Q2_Solution.py index 1591ec1..0169f06 100644 --- a/Day 3 - Datetime strftime and strptime/Q2_Solution.py +++ b/Day 3 - Datetime strftime and strptime/Q2_Solution.py @@ -3,10 +3,36 @@ from datetime import datetime +# +inputDate = datetime(year=2019, + day=20, + month=1, + hour=9, + minute=30) +print(datetime.strftime(inputDate, "%b %d, %Y %-H:%M %p")) -inputDate = datetime(year=2019, day=20, month=1, hour=9, minute=30) -print(datetime.strftime(inputDate, "%b %d, %Y %-H:%M %p")) +# Explanation: +# 1. Given dateString format is like - month date, year hour:minute AM in a string format. +# 2. Whenever you need to convert a string to datetime, then all the component inside the string needs to be used for \ +# constructing datetime object + +# Example, +''' +sampleDateString = "2019/22/08" +print(datetime.strptime(sampleDateString, "%Y/%m/")) + +Output: +ValueError: unconverted data remains: 08 + +Working code: +print(datetime.strptime(sampleDateString, "%Y/%m/%d")) + +Output: +2019-08-22 00:00:00 + +if you see the above output, it also prints time as 00:00:00 +''' dateString = "Jan 20, 2019 9:30 AM" print(type(datetime.strptime(dateString, "%b %d, %Y %H:%M %p"))) From 6a52295f25b73936a3d594bde71724d50a32ae71 Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Wed, 12 Jun 2019 14:18:11 +0530 Subject: [PATCH 13/15] Addressing review comments. As discussed in the review, addressing those explained information. Thanks to @pylenin --- Day 3 - Datetime strftime and strptime/Q2_Solution.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Day 3 - Datetime strftime and strptime/Q2_Solution.py b/Day 3 - Datetime strftime and strptime/Q2_Solution.py index 0169f06..37dbff3 100644 --- a/Day 3 - Datetime strftime and strptime/Q2_Solution.py +++ b/Day 3 - Datetime strftime and strptime/Q2_Solution.py @@ -3,15 +3,6 @@ from datetime import datetime -# -inputDate = datetime(year=2019, - day=20, - month=1, - hour=9, - minute=30) -print(datetime.strftime(inputDate, "%b %d, %Y %-H:%M %p")) - - # Explanation: # 1. Given dateString format is like - month date, year hour:minute AM in a string format. # 2. Whenever you need to convert a string to datetime, then all the component inside the string needs to be used for \ @@ -35,4 +26,4 @@ ''' dateString = "Jan 20, 2019 9:30 AM" -print(type(datetime.strptime(dateString, "%b %d, %Y %H:%M %p"))) +print(type(datetime.strptime(dateString, "b %d, %Y %-I:%M %p"))) From e1e90874ebdf61e09050d2dce0c80e10be863cc6 Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Wed, 19 Jun 2019 15:42:18 +0530 Subject: [PATCH 14/15] Commit - program to conver the current unix timestamp to reaable date and time. Commit - program to conver the current unix timestamp to reaable date and time. --- .../Q1_ConvertUnixTimeStampToReadable.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py diff --git a/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py b/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py new file mode 100644 index 0000000..10b94e6 --- /dev/null +++ b/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py @@ -0,0 +1,10 @@ +# 1) Write a Python program to convert the current unix timestamp +# string to readable date and time in the below format +# +# Desired format - "June 15, 2019 7.30 PM" + +from datetime import datetime + +current_timestamp = datetime.now().timestamp() +readable_format = datetime.fromtimestamp(current_timestamp) +print(datetime.strftime(readable_format, "%B %d, %Y %-I:%M %p")) \ No newline at end of file From e3d8f318428b04caa16406a617cbace3a043534c Mon Sep 17 00:00:00 2001 From: Sanjay Pradeep Kumar Date: Wed, 3 Jul 2019 23:12:02 +0530 Subject: [PATCH 15/15] Update Q1_ConvertUnixTimeStampToReadable.py Just an update. --- .../Q1_ConvertUnixTimeStampToReadable.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py b/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py index 10b94e6..8795797 100644 --- a/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py +++ b/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py @@ -7,4 +7,5 @@ current_timestamp = datetime.now().timestamp() readable_format = datetime.fromtimestamp(current_timestamp) -print(datetime.strftime(readable_format, "%B %d, %Y %-I:%M %p")) \ No newline at end of file +print(datetime.strftime(readable_format, "%B %d, %Y %-I:%M %p")) +