def GetTimeStampFromDateTime(dt): """Returns the float UNIX timestamp (with microseconds) for dt. Args: dt: The datetime object to convert from. Returns: The float UNIX timestamp (with microseconds) for dt. """ tzinfo = UTC if dt.tzinfo else None delta = dt - datetime.datetime.fromtimestamp(0, tzinfo) return iso_duration.GetTotalSecondsFromTimeDelta(delta)
def GetTimeStampFromDateTime(dt, tzinfo=LOCAL): """Returns the float UNIX timestamp (with microseconds) for dt. Args: dt: The datetime object to convert from. tzinfo: Use this tzinfo if dt is naiive. Returns: The float UNIX timestamp (with microseconds) for dt. """ if not dt.tzinfo and tzinfo: dt = dt.replace(tzinfo=tzinfo) delta = dt - datetime.datetime.fromtimestamp(0, UTC) return iso_duration.GetTotalSecondsFromTimeDelta(delta)