Question: Having this error: The call daytime ( datetime . datetime ( 2 0 1 5 , 1 0 , 3 1 , 6 , 0
Having this error:
The call daytimedatetimedatetime tzinfodaycycle returns False, not True.
def daytimetimedaycycle:
Returns True if the time takes place during the day, False otherwise and
returns None if a key does not exist in the dictionary
A time is during the day if it is after sunrise but before sunset, as
indicated by the daycycle dictionary.
A daycycle dictionary has keys for several years as strings The value for
each year is also a dictionary, taking strings of the form mmdd The
value for that key is a THIRD dictionary, with two keys "sunrise" and
"sunset". The value for each of those two keys is a string in hour
time format.
For example, here is what part of a daycycle dictionary might look like:
:
:
"sunrise": :
"sunset": :
:
"sunrise": :
"sunset": :
In addition, the daycycle dictionary has a key 'timezone' that expresses the
timezone as a string. This function uses that timezone when constructing
datetime objects using data from the daycycle dictionary. Also, if the time
parameter does not have a timezone, we assume that it is in the same timezone
as the daycycle dictionary.
Parameter time: The time to check
Precondition: time is a datetime object
Parameter daycycle: The daycycle dictionary
Precondition: daycycle is a valid daycycle dictionary, as described above
# HINT: Use the code from the previous exercise to get sunset AND sunrise
# Add a timezone to time if one is missing the one from the daycycle
year time.year
monthday time.strftimemd
dayinfo daycyclestryearmonthday
sunrisestr dayinfosunrise
sunsetstr dayinfosunset
if time.tzinfo is None:
tz pytztimezonedaycycletimezone
time tzlocalizetime
else:
tz time.tzinfo
sunrise datetime.datetime.combinetimedate datetime.datetime.strptimesunrisestrH:Mtime tzinfotz
sunset datetime.datetime.combinetimedate datetime.datetime.strptimesunsetstrH:Mtime tzinfotz
return sunrise time sunset
these are the test cases
def testdaytime:
Tests the function utils.daytime
fcn 'utils.daytime'
parent ospath.splitfile
fpath ospath.joinparent'daycycle.json'
cycle utils.readjsonfpath
times T::True,TrueT::True,True
T::False,TrueT::True,False
T::True,TrueT::False,False
T::False,TrueT::True,True
T::True,TrueT::False,False
T::False,TrueT::False,False
T::True,TrueT::True,True
T::True,TrueT::False,False
T::True,TrueT::False,False
# CHECK THE TEST CASES
for time in times:
act utils.strtotimetime"AmericaNewYork"
day utils.daytimeactcycle
data fcnrepract'daycycle',reprdayreprtime
assertequalstime day,sss returned s but should have returned s data
act utils.strtotimetime"AmericaChicago
day utils.daytimeactcycle
data fcnrepract'daycycle',reprdayreprtime
assertequalstime day,sss returned s but should have returned s data
# Test the case of no time zone Same result as first test aboveEdited by STT
act utils.strtotimetime
day utils.daytimeactcycle
data fcnrepract'daycycle',reprdayreprtime
assertequalstime day,sss returned s but should have returned s data
prints passed all tests' fcn
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
