Trying to convert between standard python datetime routine datetime.datetime and Pyphem routine ephem.Date sometimes there are (except the expected truncation) peculiar differences in the range of one second.
Try the example code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ephem
import datetime
now_datetime = datetime.datetime.now()
now_ephem = ephem.Date(now_datetime)
print "Datetime: ", now_datetime
print "Ephem : ", now_ephem
Repeated calls give an output similar to:
thl@thl-lap-001:$ ./timedifference.py
Datetime: 2013-12-20 08:28:11.536814
Ephem : 2013/12/20 08:28:11
thl@thl-lap-001:$ ./timedifference.py
Datetime: 2013-12-20 08:28:16.088484
Ephem : 2013/12/20 08:28:15
The last two lines show 16.somethig seconds in Datetim that converts to 15 Seconds to ephem.Date.
Is there an explanation?
From the PyEphem home page:
Floating-point precision always brings some level of approximation. I think that is what you are seeing in your example.
EDIT
Upon more digging, the reason it doesn't catch tenths of seconds in this case is that ephem ignores the microseconds when creating a ephem.Date from a datetime. Looks like there is a fix for this coming in version 3.7.5.2
To answer the question
Most definitely!