Next / Previous / Contents / TCC Help System / NM Tech homepage

13.4. JulianDate.offset(): Move a time by some number of days

For a JulianDate instance JD, this method returns a new JulianDate instance that differs by delta days.

sidereal.py
# - - -   J u l i a n D a t e . o f f s e t

    def offset ( self, delta ):
        """Return a new JulianDate for self+(delta days)

          [ delta is a number of days as a float ->
              return a new JulianDate (delta) days in the
              future, or past if negative ]
        """

To preserve the precision, we'll perform the addition directly on the internal value that is biased by JULIAN_BIAS, then separate the sum into whole part and fraction, and then un-bias the whole part and pass both to the class constructor.

sidereal.py
        #-- 1 --
        newJ  =  self.j + delta

        #-- 2 --
        # [ newWhole  :=  whole part of newJ
        #   newFrac   :=  fractional part of newJ ]
        newWhole, newFrac  =  divmod ( newJ )

        #-- 3 --
        return  JulianDate ( newWhole+JULIAN_BIAS, newFrac )