Question
def str_to_time(timestamp,tz=None): Returns the datetime object for the given timestamp (or None if stamp is invalid) This function should just use the parse function
def str_to_time(timestamp,tz=None):
"""
Returns the datetime object for the given timestamp (or None if stamp is invalid)
This function should just use the parse function in dateutil.parser to
convert the timestamp to a datetime object. If it is not a valid date (so
the parser crashes), this function should return None.
If the timestamp has a timezone, then it should keep that timezone even if
the value for tz is not None. Otherwise, if timestamp has no timezone and
tz if not None, this this function will assign that timezone to the datetime
object.
The value for tz can either be a string or a time OFFSET. If it is a string,
it will be the name of a timezone, and it should localize the timestamp. If
it is an offset, that offset should be assigned to the datetime object.
Parameter timestamp: The time stamp to convert
Precondition: timestamp is a string
Parameter tz: The timezone to use (OPTIONAL)
Precondition: tz is either None, a string naming a valid time zone,
or a time zone OFFSET.
"""
# HINT: Use the code from the previous exercise and update the timezone
# Use localize if timezone is a string; otherwise replace the timezone if not None
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started