One common problem when dealing with vendor interoperability is the handling of
ID: 3792349 • Letter: O
Question
One common problem when dealing with vendor interoperability is the handling of dates. You may have a system that handles operations in Pacific Time (UTC -7 or UTC-8 depending on the day of the year), and you may have a system that handles dates based in UTC. Since 2007, daylight savings time is observed as follows in Pacific Time: Between the second Sunday in March and the first Sunday in November, Pacific Time is UTC -07:00 At all other times, Pacific Time is UTC -08:00. You can assume the following functions are available: A. dayofweek(date | datetime) = Indexed day of the week. Monday = 1, Sunday = 7 B. day(date | datetime) = day of the month C. month(date | datetime) = numeric month Given a date, write a program in Python hat can be used to calculate the UTC time that is the equivalent of midnight Pacific Time. Example inputs and outputs: A. 2016-04-04 -> 2016-04-04 07:00 UTC B. 2016-11-16 -> 2016-11-16 08:00 UTC
Explanation / Answer
def month(mydate):
if(mydate.strftime("%b") == "Mar"):
return 1
if(mydate.strftime("%b") == "Apr"):
return 2
if(mydate.strftime("%b") == "May"):
return 3
if(mydate.strftime("%b") == "Jun"):
return 4
if(mydate.strftime("%b") == "Jul"):
return 5
if(mydate.strftime("%b") == "Aug"):
return 6
if(mydate.strftime("%b") == "Sep"):
return 7
if(mydate.strftime("%b") == "Oct"):
return 8
if(mydate.strftime("%b") == "Mar"):
return 9
if(mydate.strftime("%b") == "Dec"):
return 10
if(mydate.strftime("%b") == "Jan"):
return 11
if(mydate.strftime("%b") == "Feb"):
return 12
def dow(date):
days=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
return date.weekday() + 1
def day(date):
if (month(my_date) > 9):
print( my_date + "08:00 UTC")
if (month(my_date) > 1 and month(my_date) < 9):
print( my_date + "07:00 UTC")
if (month(my_date) == 1):
if(my_date.day > 7 and my_date.day < 15 and dow < 7):
print( my_date + "08:00 UTC")
else print( my_date + "07:00 UTC")
if (month(my_date) == 9 and my_date.day < 7):
print( my_date + "07:00 UTC")
else print print( my_date + "08:00 UTC")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.