jdt
index
/Users/amos/Documents/Database/Mental/Programming/python/lib/avatar/Personal2/www.amos/Python/lib/date/jdt.py

These classes translate between date tuples and Julian Day numbers.
 
There are two types of applications for Julian Days. In the first, each day in
history is assigned a unique integer, such that the days follow each other in
the same order the integers do. A day is described by a triple (yr, mo, da).
Times of day are not an issue; neither are time zones. For this kind of date,
use the JulianDay class (tag jd).
 
Other applications need Julian Days to be floating point numbers, with fractions
of a day. On the date side, the tuple extends into hours, minutes and seconds.
For this kind of date, use the JulianDayTime class (tag jdt). Instances of both
of these classes are called "jd objects".
 
The zero point of all jd objects is adopted from astronomical convention:
January 1, -4712; specifically noon of that day. Astronomers wanted a
positive date number for all reasonable dates, and they didn't want that number
changing at midnight, in the middle of prime observing time.
 
>>> JulianDay(0).getDt()
(-4712, 1, 1)
>>> JulianDayTime(0.).getDt()
(-4712, 1, 1, 12, 0, 0, 0.0)
 
Note how the tuple returned by JulianDateTime.getDt() has 7 components: the 6
standard ones plus a floating point number representing fractions of a second.                                                                                                                                                                                                                                                        
 
>>> JulianDayTime(2451545).getDt()
(2000, 1, 1, 12, 0, 0, 0.0)
>>> JulianDayTime(2451545+2.33e-10).getDt()    # resolution is  2.33e-10 days
(2000, 1, 1, 12, 0, 0, 4.0233135223388672e-05)
>>> (JulianDayTime((2000,1,1,12,0,2.02e-5))-2451545).getJd() # or 2.02e-5 sec
4.6566128730773926e-10
 
You can add a number to a jd object (or a jd object to a number) to get a new jd
object, you can subtract two jd objects to get a number, and subtract a number
from a jd object to get another jd object. These numbers' units are all days.
You can, given one type of jd object, get an equivalent one of the other type
using ToJd() or ToJdt() as appropriate.
 
US Presidential inauguration plus 100 days -- the end of the "honeymoon":
>>> (100 + JulianDay((2009,1,20))).getDt()
(2009, 4, 30)
 
Length of John F. Kennedy administration (sometimes called "1000 days"):
>>> JulianDay((1963,11,22)) - JulianDay((1961,1,20))
1036
 
Note the absence of a 12 hour offset if you don't use JulianDay():
>>> (JulianDayTime((2008,3,1)) - 1).getDt()
(2008, 2, 29, 0, 0, 0, 0.0)
 
The algorithms are from Jan Meeus, _Astronomical Algorithms_, chapter 7.
Willmann-Bell: Richmond, VA. ISBN 0-943396-35-2.

 
Classes
       
JulianDay
JulianDayTime

 
class JulianDay
    The class for integer dates, without time of day.
 
  Methods defined here:
JdToTuple(self, nJd, isGregorian=None)
ToDateTuple(self)
ToJd(self)
ToJdt(self)
TupleToJd(self, dt, isGregorian=None)
Weekday(self, nDay=None)
__add__(self, other)
__cmp__(self, other)
__float__(self)
__init__(self, D, isGregorian=None)
D is either a numeric Julian Day, or a date tuple or list.
__int__(self)
__radd__(self, other)
__str__(self)
__sub__(self, other)
getDt(self)
getJd(self)
setDt(self, D)
setJd(self, D)

 
class JulianDayTime(JulianDay)
    The class for fractional dates, and times of day.
 
It's subclassed because it starts with the same integer calculations, then
grafts the time of day onto that.
 
  Methods defined here:
JdToTuple(self, xJd, isGregorian=None)
Produce a 7-tuple: (yr, mo, da, hr, min, sec, F), where sec is made
an integer and F stores its fractional part.
 
noon - (.001 day = 86.4 sec = 1:26.4) = 11:58:33.6
>>> '%d.%d.%d %d:%02d:%02d+%.5f' % JulianDayTime(-0.001).getDt()
'-4712.1.1 11:58:33+0.60000'
JdToTz(self, secTz)
ToDateTuple(self, isLocalized=True)
ToJd(self)
ToJdt(self)
ToLocal(self)
TupleToJd(self, dt, isGregorian=None)
Given a tuple which is a prefix of (yr, mo, da, hr, min, sec, F),
produce a (float) Julian Day number.
Weekday(self, xDay=None)
__float__(self)
__int__(self)
getJd(self)
setJd(self, D)

Methods inherited from JulianDay:
__add__(self, other)
__cmp__(self, other)
__init__(self, D, isGregorian=None)
D is either a numeric Julian Day, or a date tuple or list.
__radd__(self, other)
__str__(self)
__sub__(self, other)
getDt(self)
setDt(self, D)

 
Functions
       
Localize(dt)
Try to get daylight savings information from the operating system clock,
safely.
 
Only works in the Unix date range: 1901.12.13T20:45:52Z ...
2038.01.19T3:14:07Z; other date tuples are returned unchanged.
floor(...)
floor(x)
 
Return the floor of x as a float.
This is the largest integral value <= x.
localtime(...)
localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst)
 
Convert seconds since the Epoch to a time tuple expressing local time.
When 'seconds' is not passed in, convert the current time instead.
mktime(...)
mktime(tuple) -> floating point number
 
Convert a time tuple in local time to seconds since the Epoch.
modf(...)
modf(x)
 
Return the fractional and integer parts of x.  Both results carry the sign
of x.  The integer part is returned as a real.

 
Data
        altzone = 14400
timezone = 18000