Example #1
0
def unix_to_skyfield_time(unix_time):
    """Formats the Unix time into a time that can be interpreted by ephem.

    Parameters
    ----------
    unix_time : float or array of.
        Unix/POSIX time.

    Returns
    -------
    time : :class:`skyfield.timelib.Time`

    See Also
    --------
    :meth:`datetime.datetime.utcfromtimestamp`
    :func:`datetime_to_unix`

    """

    from skyfield import timelib
    ts = skyfield_wrapper.timescale

    days, seconds = divmod(unix_time, 24 * 3600.0)

    # Construct Julian day and convert to calendar day
    year, month, day = timelib.calendar_date(2440588 + days)

    # Construct Skyfield time. Cheat slightly by putting all of the time of day
    # in the `second` argument.
    t = ts.utc(year, month, day, second=seconds)

    return t
Example #2
0
def unix_to_skyfield_time(unix_time):
    """Formats the Unix time into a time that can be interpreted by ephem.

    Parameters
    ----------
    unix_time : float or array of.
        Unix/POSIX time.

    Returns
    -------
    time : :class:`skyfield.timelib.Time`

    See Also
    --------
    :meth:`datetime.datetime.utcfromtimestamp`
    :func:`datetime_to_unix`

    """

    from skyfield import timelib

    ts = skyfield_wrapper.timescale

    days, seconds = divmod(unix_time, 24 * 3600.0)

    # Construct Julian day and convert to calendar day
    year, month, day = timelib.calendar_date(2440588 + days)

    # Construct Skyfield time. Cheat slightly by putting all of the time of day
    # in the `second` argument.
    t = ts.utc(year, month, day, second=seconds)

    return t
Example #3
0
def test_cal_date():
    for jd in 0.0, 2414988.5, 2415020.31352, 2442249.5, 2456335.2428472:
        whole, fraction = divmod((jd + 0.5), 1.0)
        y, m, d = timelib.calendar_date(int(whole))
        assert c.cal_date(jd) == (y, m, d, 24.0 * fraction)