DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
No more ctime(3C) errors - Time(3C++)

Julian date operations

Julian dates offer a more natural way to iterate over the days of a year. A Julian date consists of a year number and a day number within that year; day number 1 is always January 1, while day number 365 is December 30 in a leap year and December 31 in a non-leap year. The static member function Time::julian() allows clients to create Time values from dates given in Julian form. Moreover, Time::julian() accepts day numbers outside the range [1,366], `normalizing' them by adjusting the year. The following code shows how to loop over a two-year period using Julian dates:

       #include <Time.h>
       main(){
           // loop over all days in 1988 and 1989
           // (doesn't raise Time::date_objection)
           for(int i=1;
               i<=days_in_year(1988)+days_in_year(1989);
               i++){
               Time t = Time::julian(1988,i);
               ...
           }
       }

The member function julian_day_no() can be used to obtain the Julian day number of an existing Time:

       cout << Time t(1948,Time::march,21).julian_day_no()
            << endl;

which prints 81, since March 21 was the 81st day of 1948.


Next topic: Component extractors
Previous topic: Constructors

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004