summaryrefslogtreecommitdiff
path: root/html/xbc15.htm
diff options
context:
space:
mode:
Diffstat (limited to 'html/xbc15.htm')
-rwxr-xr-xhtml/xbc15.htm338
1 files changed, 338 insertions, 0 deletions
diff --git a/html/xbc15.htm b/html/xbc15.htm
new file mode 100755
index 0000000..de01ec4
--- /dev/null
+++ b/html/xbc15.htm
@@ -0,0 +1,338 @@
+<!DOCTYPE HTML PUBLIC>
+<html>
+<title>Xbase DBMS Chapter 15</title>
+<body bgcolor=#FFFFFF>
+<h1><p align="center">xbDate Methods</p></h1>
+<p align="center">Chapter Updated 8/21/03</p><hr><br>
+
+This chapter lists the xbDate methods and provides an example program to demonstrate usage.<br>
+Xbase .DBF files and the xbDate class handle dates in the format of CCYYMMDD (Date8).<br><br><br>
+
+<center>
+<table border>
+<caption align=top><h3>xbDate Method List API</h3></caption>
+
+<tr><th align=left>Method<td>Description
+
+<tr><th align=left>xbDate( const char * Date8 )<br>xbDate( const xbString & Date8 )<br>xbDate()
+ <td>Class constructors. If no date provided, or invalid date provided, date is set to Sysdate().
+
+<tr><th align=left>~xbDate()<td>Class destructor
+
+<tr><th align=left>xbString & CharDayOf( const char *Date8 )<br>
+ xbString & CharDayOf( const xbString & Date8 )<br>xbString & CharDayOf()
+ <td>Returns <em>Sun - Sat</em> day of week for a given date
+
+<tr><th align=left>xbString & CharMonthOf( const char *Date8 )<br>xbString & CharMonthOf( const xbString & Date8 )<br>
+ xbString & CharMonthOf()<td>Returns <em>Jan - Dec</em> month of year for a given date
+
+<tr><th align=left>int DateIsValid( const char *Date8 ) const<br>int DateIsValid( const xbString & Date8 ) const
+ <td>Checks a date for validity, returns true (1) if date is valid
+
+<tr><th align=left>int DayOf( int Format, const char *Date8 ) const<br>int DayOf( int Format, const xbString &Date8 ) const<br>
+ int DayOf( int Format ) const<td>Returns day of WEEK, MONTH or YEAR from a given date where <em>Format</em> is one of<br>
+ <em>XB_FMT_WEEK</em> => Number of day in week 0-6 (sun-Sat)<br>
+ <em>XB_FMT_MONTH</em> => Number of day in month 1-31<br>
+ <em>XB_FMT_YEAR</em> => Number of day in year 1-366
+
+<tr><th align=left>xbString & Formatdate( const char * Format, const char * Date8 )<br>
+ xbString & FormatDate( const xbString & Format, const char * Date8 )<br>
+ xbString & FormatDate( const char * Format, const xbString & Date8 )<br>
+ xbString & FormatDate( const xbString & Format, const xbString & Date8 )<br>
+ xbString & FormatDate( const xbString & Format )<br>
+ xbString & FormatDate( const char * )<br>
+
+ <td>Return a formatted date.<br>
+
+ Format - A format specifier with the following paramaters:<br>
+
+ 1) YYDDD - A julian date format<br>
+
+ 2) YY or YYYY will print a 2 or 4 digit year<br>
+
+ 3) M,MM,MMM or MMMM<br>
+
+ M - one digit month if no leading zero<br>
+ MM - two digit month, contains leading zero<br>
+ MMM - Jan through Dec<br>
+ MMMM - January through December<br>
+
+ 4) D,DD,DDD or DDDD<br>
+
+ D - one digit dayif no leading zero<br>
+ DD - two digit day, contains leading zero <br>
+ DDD - Sun through Sat (or julian if YYDDD)<br>
+ DDDD - Sunday through Saturday<br>
+
+
+<tr><th align=left>const xbString & GetDate() const<br>xbString & GetDate()<td>Return date
+
+<tr><th align=left>const xbString & GetFormattedDate() const<br>xbString & GetFormattedDate()<td>
+ Returns formatted date. See notes on format paramaters.
+
+<tr><th align=left>int IsLeapYear( const char *Date8 ) const<br>int IsLeapYear( const xbString &Date8 ) const<br>
+ int IsLeapYear() const<td>Returns true if given date is a leap year
+
+<tr><th align=left>long JulianDays( const char *Date8 ) const<br>long JulianDays( const xbString & Date8 ) const<br>
+ long JulianDays() const<td>Returns number of days since 1/1/0100 to given date
+
+<tr><th align=left>xbString & JulToDate8( long )<td>Converts julian based date to CCYYMMDD format.
+
+<tr><th align=left>xbString & LastdayOfMonth( const char *Date8 )<br>xbString & LastDayOfMonth( const xbString & Date8 )<br>
+ xbString & LastDayOfMonth()<td>Returns the Date8 format of the last day of the month for a given date
+
+<tr><th align=left>int MonthOf( const char *Date8 ) const<br>int MonthOf( const xbString &Date8) const<br>
+int MonthOf() const<td>Returns month of a date
+
+<tr><th align=left>int SetDate( const char * Date8 )<br>int SetDate( const xbString & Date8 )<td>
+ Sets the xbDate to <em>Date8</em>. Return 1 on success, 0 on error.
+
+
+<tr><th align=left>xbString & Sysdate()<td>This method sets the class date and returns the system date
+
+<tr><th align=left>int YearOf( const char *Date8 ) const<br>int YearOf( const xbString &Date8 ) const<br>
+int YearOf() const<td>Returns century and year of a date
+
+<tr><th align=left>xbString &operator+=( int )<td>+= operator
+<tr><th align=left>xbString &operator-=( int )<td>-= operator
+<tr><th align=left>xbString &operator++( int )<td>++ operator
+<tr><th align=left>xbString &operator--( int )<td>-- operator
+<tr><th align=left>xbString &operator+( int )<td>+ operator
+<tr><th align=left>xbString &operator-( int )<td>- operator
+<tr><th align=left>long operator-( const xbDate & ) const<td>- operator
+<tr><th align=left>int operator==( const xbDate & ) const<td>== operator
+<tr><th align=left>int operator!=( const xbDate & ) const<td>!= operator
+<tr><th align=left>int operator<( const xbDate & ) const<td>< operator
+<tr><th align=left>int operator>( const xbDate & ) const<td>> operator
+<tr><th align=left>int operator<=( const xbDate & ) const<td><= operator
+<tr><th align=left>int operator>=( const xbDate & ) const<td>>= operator
+
+</table></center>
+<br><br><br>
+
+<h2>Sample program</h2><br>
+The source for this program is in the libtest directory. <br><br>
+
+<xmp>
+ Xbase project source code
+
+ This program tests the xdate routines
+
+ Copyright (C) 1997 Gary A. Kunkel
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Contact:
+
+ Mail:
+
+ Technology Associates, Inc.
+ XBase Project
+ 1455 Deming Way #11
+ Sparks, NV 89434
+ USA
+
+ Email:
+
+ xbase@techass.com
+ xdb-devel@lists.sourceforge.net
+ xdb-users@lists.sourceforge.net
+
+ Website:
+
+ xdb.sourceforge.net
+
+
+ This program tests and demonstrates usage of the various xbDate methods
+
+ Several of the tests pass either StringDate or Chardate to the method
+ being tested - this is done to test the class methods. In actual usage,
+ this may not be necessary due to the instance of the class already
+ containing a date value.
+*/
+
+#include "xbase.h"
+
+int main()
+{
+ xbString StringDate( "19601007" ); /* oct 7 1960 */
+ char CharDate[9] = "19611109"; /* nov 9 1961 */
+
+ xbDate d1; /* today is default */
+ xbDate d2( StringDate ); /* from string data */
+ xbDate d3( CharDate ); /* from char data */
+ xbDate d4; /* another date class */
+
+ std::cout << "This program tests the XDATE routines" << std::endl;
+ std::cout << "Date 1 (Sysdate) is " << d1.GetDate() << std::endl;
+ std::cout << "Date 2 (StringDate) is " << d2.GetDate() << std::endl;
+ std::cout << "Date 3 (CharDate) is " << d3.GetDate() << std::endl;
+
+ std::cout << "This year is " << d1.YearOf() << std::endl;
+ std::cout << "Year of xbString Date is " << d2.YearOf( StringDate )
+ << std::endl;
+ std::cout << "Year of char Date is " << d3.YearOf( CharDate )
+ << std::endl;
+
+ std::cout << "This Month is " << d1.MonthOf() << std::endl;
+ std::cout << "Month of xbString Date is " << d2.MonthOf( StringDate )
+ << std::endl;
+ std::cout << "Month of char Date is " << d3.MonthOf( CharDate )
+ << std::endl;
+
+ std::cout << "Today is day " << d1.DayOf( XB_FMT_WEEK ) << " of the week"
+ << std::endl;
+ std::cout << "StringDate is day " << d2.DayOf( XB_FMT_MONTH, StringDate )
+ << " of the month" << std::endl;
+ std::cout << "CharDate is day " << d3.DayOf( XB_FMT_YEAR, CharDate )
+ << " of the year" << std::endl;
+
+ if( d1.IsLeapYear())
+ std::cout << "This is a leapyear" << std::endl;
+ else
+ std::cout << "This is not a leap year." << std::endl;
+
+ if( d2.IsLeapYear( StringDate ))
+ std::cout << "StringDate is a leapyear" << std::endl;
+ else
+ std::cout << "StringDate is not a leap year." << std::endl;
+
+ if( d3.IsLeapYear( CharDate ))
+ std::cout << "CharDate is a leapyear" << std::endl;
+ else
+ std::cout << "CharDate is not a leap year." << std::endl;
+
+ std::cout << "Today is " << d1.Sysdate() << std::endl;
+
+ if( d1.DateIsValid( "19951301" ))
+ std::cout << "19951301 is a valid date" << std::endl;
+ else
+ std::cout << "19951301 is not a valid date" << std::endl;
+
+ if( d1.DateIsValid( "19920229" ))
+ std::cout << "19920229 is a valid date" << std::endl;
+ else
+ std::cout << "19920229 is not a valid date" << std::endl;
+
+ if( d2.DateIsValid( StringDate ))
+ std::cout << StringDate << " is a valid date" << std::endl;
+ else
+ std::cout << StringDate << " is not a valid date" << std::endl;
+
+ std::cout << "Today's Julian date " << d1.JulianDays() << std::endl;
+ std::cout << "StringDate Julian date " << d2.JulianDays( StringDate )
+ << std::endl;
+
+ std::cout << "There are "
+ << ( d1.JulianDays( "19951101" ) - d1.JulianDays( "19951001" ))
+ << " days between 10/1/95 and 11/1/95." << std::endl;
+
+ std::cout << "Todays Julian date (Number of days since Jan 1 0100):"
+ << d1.JulianDays() << std::endl;
+
+ d4 = d1; // set d4 class = to sysdate
+ std::cout << "Object d4 initialized to " << d4.GetDate() << std::endl;
+ std::cout << "This should be todays date: "
+ << d4.JulToDate8(d4.JulianDays()) << std::endl;
+ std::cout << "In 7 days it will be "
+ << d4.JulToDate8(d4.JulianDays() + 7L ) << std::endl;
+
+ std::cout << "Today is " << d1.CharDayOf() << std::endl;
+ std::cout << "StringDate day is " << d2.CharDayOf( StringDate )
+ << std::endl;
+ std::cout << "This month is " << d1.CharMonthOf() << std::endl;
+ std::cout << "StringDate month is " << d2.CharMonthOf() << std::endl;
+
+
+ /* various format routines using different formats, strings and chars */
+ xbString xbStFmt( "MM/DD/YY" );
+ std::cout << "Format (YYDDD) " << d1.FormatDate( "YYDDD" ) << std::endl;
+ std::cout << "Format (MM/DD/YY) " << d1.FormatDate( xbStFmt ) << std::endl;
+ xbStFmt = "DD/MM/YY";
+ std::cout << "Format (DD/MM/YY) " << d1.FormatDate(xbStFmt, "19730110")
+ << std::endl;
+ std::cout << "Format (MMMM DD,YYYY) "
+ << d1.FormatDate( "MMMM DD,YYYY", d1.GetDate()) << std::endl;
+ xbStFmt = "DDDD, MMMM DD YYYY";
+ std::cout << "Format (DDDD, MMMM DD YYYY) "
+ << d2.FormatDate( xbStFmt, d2.GetDate()) << std::endl;
+
+ std::cout << "Last day this month " << d1.LastDayOfMonth() << std::endl;
+ std::cout << "Last day of month for StringDate is "
+ << d2.LastDayOfMonth( d2.GetDate()) << std::endl;
+
+ std::cout << "Overloaded operators test..." << std::endl;
+
+ if( d1 == d2 )
+ std::cout << d1.GetDate() << " is equal to " << d2.GetDate()
+ << std::endl;
+ else
+ std::cout << d1.GetDate() << " is not equal to " << d2.GetDate()
+ << std::endl;
+
+ if( d1 != d3 )
+ std::cout << d1.GetDate() << " is not equal to " << d3.GetDate()
+ << std::endl;
+ else
+ std::cout << d1.GetDate() << " is equal to " << d3.GetDate()
+ << std::endl;
+
+ if( d1 < d2 )
+ std::cout << d1.GetDate() << " is less than " << d2.GetDate()
+ << std::endl;
+ else
+ std::cout << d1.GetDate() << " is not less than " << d2.GetDate()
+ << std::endl;
+
+ if( d1 > d2 )
+ std::cout << d1.GetDate() << " is greater than " << d2.GetDate()
+ << std::endl;
+ else
+ std::cout << d1.GetDate() << " is not greater than " << d2.GetDate()
+ << std::endl;
+
+ if( d1 <= d2 )
+ std::cout << d1.GetDate() << " is less than or equal to " << d2.GetDate()
+ << std::endl;
+ else
+ std::cout << d1.GetDate() << " is not less than or equal to "
+ << d2.GetDate() << std::endl;
+
+ if( d1 >= d2 )
+ std::cout << d1.GetDate() << " is greater than or equal to "
+ << d2.GetDate() << std::endl;
+ else
+ std::cout << d1.GetDate() << " is not greater than or equal to "
+ << d2.GetDate() << std::endl;
+
+ d1.Sysdate();
+ d1++;
+ std::cout << "Tomorrow is " << d1.GetDate() << std::endl;
+ d1-=2;
+ std::cout << "Yesterday was " << d1.GetDate() << std::endl;
+ std::cout << "There are " << d1 - d2 << " days between " << d1.GetDate()
+ << " and " << d2.GetDate() << std::endl;
+
+ return 0;
+}
+
+
+</xmp>
+<hr>
+<p><img src="xbase.jpg"><br><hr>
+</BODY>
+</HTML>
+
+