Julian
Julian/Gregorian date class
[Previous] [Main] [Next]


Description
The Julian class encapsulates and manipulates dates as Julian integers. Julian integers represent the day since the first day of Gregorian year zero. Julian dates are stored as long integers, making date arithmetic as easy as addition and subtraction.  
 
Methods are provided for determining the current system date, and for converting Julian date integers to and from their Gregorian day/month/year counterparts, as well as producing RFC 822-formatted text representations.  
 
This class is intended for use with the htmlCookie class to compute expiration dates for cookies, but is general-purpose in nature and suitable for other tasks as well.  
 
Declaration
#include <dcmicro/htmlpp/julian.h>  
 
Hierarchy
julian.gif  
 
See Also
htmlCookie  
 
Related Constants/Definitions
None.  
 
Constructors
Julian()  
Constructs a Julian date object, setting the value to today's date.  
 
Julian( long julian_date )  
Constructs a Julian date object, setting the value to julian_date.  
 
Destructors
virtual ~Julian()  
Destroys the object.  
 
Member Methods
JulianDatelong JulianDate()  
Returns the date value of the object as a Julian integer.  
 
Todaylong Today()  
Returns the current system date as a Julian integer.  
 
MDY   long MDY( short month, short day, short year )  
Converts Gregorian month (1-12), day (1-31), and year (0-9999) values to a Julian integer.  
 
MDY   void MDY( long julian_date,  
       short FAR * month,  
       short FAR * day,  
       short FAR * year )  
Converts julian_date to Gregorian month (1-12), day (1-31), and year (0-9999) values. If NULL is supplied for month, day, or year, the values will not be populated.  
 
Day   short Day( long julian_date = JULIAN_DEFAULT )  
Returns the Gregorian day of the month (1-31) for the specified julian_date. If no argument is supplied, the date value of the object will be used by default.  
 
Monthshort Month( long julian_date = JULIAN_DEFAULT )  
Returns the Gregorian month (1-12) for the specified julian_date. If no argument is supplied, the date value of the object will be used by default.  
 
Year   short Year( long julian_date = JULIAN_DEFAULT )  
Returns the Gregorian year for the specified julian_date. If no argument is supplied, the date value of the object will be used by default.  
 
DayOfWeekshort DayOfWeek( long julian_date = JULIAN_DEFAULT )  
Returns the day of the week (0=Sunday, 1=Monday, ..., 6=Saturday) for the specified julian_date. If no argument is supplied, the date value of the object will be used by default.  
 
RFC822String RFC822( long julian_date = JULIAN_DEFAULT )  
Returns an RFC 822-formatted text string representing the date specified by julian_date. A time of 12pm GMT is assumed. RFC 822 is an internet protocol document that specifies that dates should be of the form:  
 
Weekday, dd-Mon-yyyy hh:mm:ss GMT  
 
This method is intended for use with the htmlCookie::Expires() method. If no argument is supplied, the date value of the object will be used by default.  
 
=   Julian& operator= ( long julian_date )  
Assigns the value of the object to julian_date, and returns a reference to the object.  
 
+=   long operator += ( long days )  
Adds days to the julian date value of the object.  
 
-=   long operator -= ( long days )  
Subtracts days from the julian date value of the object.  
 
(long)operator long ( void )  
Casts the julian date value of the object as a long integer.  
 
Print   /* virtual */ void Print( ostream& os ) const  
Outputs the object to os.  
 
Example Use
 
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page( "html++ example application" ) ;  
 
   //  Create a new cookie for the page  
   htmlCookie   cookie ;  
   cookie.Domain( ".yourdomain.com" )  
         .Path( "/" ) ;  
 
   Julian j ;  //  today's date  
   j += 30 ;   //  add thirty days  
   cookie.Expires( j.RFC822() ) ;  
 
   //  Set the customer id as the cookie value  
   cookie.Value( "customerid""1234" ) ;  
 
   page << cookie ;  
 
   server << page ;  
   return 0 ;  
}  
 
Program Output
 
Content-Type: text/html  
Set-Cookie: customerid=1234; expires=Wednesday, 31-Dec-1997 12:00:00 GMT; path=/; domain=.yourdomain.com  
 
<HTML>  
<HEAD>  
<TITLE>html++ example application</TITLE>  
</HEAD>  
<BODY>  
</BODY>  
</HTML>  
 


©1998 DC Micro Development. All rights reserved.
No portion of this document may be c opied or reproduced without expressed written consent.
html++ is a trademark of DC Micro Development.