<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def toDatetime(value, format=None):
 """ Returns a datetime object from the specified value. Parameters: value (str):
 value to return as a datetime format (str):
 Format to pass strftime (optional; if value is a str). """

    if value and value is not None:
        if format:
            value = datetime.strptime(value, format)
        else:
            # https://bugs.python.org/issue30684
            # And platform support for before epoch seems to be flaky.
            # TODO check for others errors too.
            if int(value) == 0:
                value = 86400
            value = datetime.fromtimestamp(int(value))
    return value