Take the date and time 4-tuples and return the time in seconds since
    the epoch as a floating point number.
493297
def datetime_to_time(date, time):
    """"""
    if (255 in date) or (255 in time):
        raise RuntimeError("specific date and time required")

    time_tuple = (
        date[0]+1900, date[1], date[2],
        time[0], time[1], time[2],
        0, 0, -1,
        )
    return _mktime(time_tuple)
355522
def to_epoch(t_str):
    
    try:
        t = float(t_str)
        return t
    except ValueError:
        for format in constants.TIMESTAMP_STR_FORMATS:
            try:
                t = datetime.datetime.strptime(t_str, format)
                return float(time.mktime(t.utctimetuple()) * 1000.0 + t.microsecond / 1000.0)
            except ValueError:
                pass
    raise exceptions.InvalidDataFormat
1017959
def to_epoch(t):
    """"""
    if isinstance(t, str):
        if '+' not in t:
            t = t + '+00:00'
        t = parser.parse(t)
    elif t.tzinfo is None or t.tzinfo.utcoffset(t) is None:
        t = t.replace(tzinfo=pytz.timezone('utc'))

    t0 = datetime.datetime(1970, 1, 1, 0, 0, 0, 0, pytz.timezone('utc'))
    delta = t - t0
    return int(delta.total_seconds())
1348084
def _gmtime(timestamp):
    
    try:
        return time.gmtime(timestamp)
    except OSError:
        dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=timestamp)
        dst = int(_isdst(dt))
        return time.struct_time(dt.timetuple()[:8] + tuple([dst]))
176602
def _get_datetimes(self, timestep=1):
        """"""
        start_moy = DateTime(self._month, self._day_of_month).moy
        if timestep == 1:
            start_moy = start_moy + 30
        num_moys = 24 * timestep
        return tuple(
            DateTime.from_moy(start_moy + (i * (1 / timestep) * 60))
            for i in xrange(num_moys)
        )
601783
def convert_timeval(seconds_since_epoch):
    """"""
    frac, whole = math.modf(seconds_since_epoch)
    microseconds = math.floor(frac * 1000000)
    seconds = math.floor(whole)
    return seconds, microseconds
307112
def CopyToDateTimeString(self):
    
    if self._number_of_seconds is None:
      return None

    return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'.format(
        self._time_elements_tuple[0], self._time_elements_tuple[1],
        self._time_elements_tuple[2], self._time_elements_tuple[3],
        self._time_elements_tuple[4], self._time_elements_tuple[5])
368592
def dt2ts(dt):
    """"""
    # Note: no assertion to really keep this fast
    assert isinstance(dt, (datetime.datetime, datetime.date))
    ret = time.mktime(dt.timetuple())
    if isinstance(dt, datetime.datetime):
        ret += 1e-6 * dt.microsecond
    return ret
267433
def toDatetime(value, format=None):
    
    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
935128
def _hours(t0, t):
		
		if not isinstance(t, Iterable):
			return Tide._hours(t0, [t])[0]
		elif isinstance(t[0], datetime):
			return np.array([(ti-t0).total_seconds() / 3600.0 for ti in t])
		else:
			return t
18711
def get_datetime(timestamp):
    
    timestamp_is_float = False
    try:
        float(timestamp)
        timestamp_is_float = True
    except (ValueError, TypeError):
        pass

    if timestamp_is_float == True:
        raise ValueError("Timestamp %s is a float"%(timestamp,))

    #First try to use date util. Failing that, continue
    try:
        parsed_dt = parse(timestamp, dayfirst=False)
        if parsed_dt.tzinfo is None:
            return parsed_dt
        else:

            return parsed_dt.replace(tzinfo=None)
    except:
        pass

    if isinstance(timestamp, datetime):
        return timestamp

    fmt = guess_timefmt(timestamp)
    if fmt is None:
        fmt = FORMAT

    # and proceed as usual
    try:
        ts_time = datetime.strptime(timestamp, fmt)
    except ValueError as e:
        if e.message.split(' ', 1)[0].strip() == 'unconverted':
            utcoffset = e.message.split()[3].strip()
            timestamp = timestamp.replace(utcoffset, '')
            ts_time = datetime.strptime(timestamp, fmt)
            # Apply offset
            tzoffset = timedelta(hours=int(utcoffset[0:3]),
                                          minutes=int(utcoffset[3:5]))
            ts_time -= tzoffset
        else:
            raise e

    return ts_time
1045962
def asdatetime(self, naive=True):
    
    args = list(self.timetuple()[0:6])+[self.microsecond]
    if not naive:
      args.append(self.tzinfo)
    return datetime.datetime(*args)
412377
def datetime_to_timestamp(dt):
    

    epoch = datetime.utcfromtimestamp(0).replace(tzinfo=UTC)
    return (dt - epoch).total_seconds()
1231546
def _dt_to_epoch(self, dt):
        
        if PY2:
            # The input datetime is from botocore unmarshalling and it is
            # offset-aware so the timedelta of subtracting this time
            # to 01/01/1970 using the same tzinfo gives us
            # Unix Time (also known as POSIX Time).
            time_delta = dt - datetime(1970, 1, 1).replace(tzinfo=dt.tzinfo)
            return int(time_delta.total_seconds())
        else:
            # Added in python 3.3+ and directly returns POSIX time.
            return int(dt.timestamp())
342177
def timetuple(self):
        ""
        dst = self.dst()
        if dst is None:
            dst = -1
        elif dst:
            dst = 1
        else:
            dst = 0
        return _build_struct_time(self.year, self.month, self.day,
                                  self.hour, self.minute, self.second,
                                  dst)
1187322
def _datetime_to_epoch(self, dt):
        """"""
        if dt:
            td = (dt - datetime.datetime.fromtimestamp(0, tzutc()))
            # don't use total_seconds(), that's only available in 2.7
            total_secs = int((td.microseconds +
                              (td.seconds + td.days * 24 * 3600) *
                              10**6) / 10**6)
            return total_secs
        else:
            return 0
483783
def unixtimestamp(datetime):
    
    epoch = UTC.localize(datetime.utcfromtimestamp(0))
    if not datetime.tzinfo:
        dt = UTC.localize(datetime)
    else:
        dt = UTC.normalize(datetime)
    delta = dt - epoch
    return total_seconds(delta)