Xbase64 4.0.1
C++ Library for handling Xbase (DBF) format type files
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Attributes
xb::xbDate Class Reference

xbDate class. More...

#include <xbdate.h>

Inheritance diagram for xb::xbDate:
xb::xbSsv

Public Member Functions

 xbDate ()
 Constructor. More...
 
 xbDate (const char *Date8)
 Constructor. More...
 
 xbDate (const xbString &Date8)
 Constructor. More...
 
 xbDate (xbInt32 lJulDate)
 Constructor. More...
 
 ~xbDate ()
 Destructor. More...
 
void operator= (const xbDate &d)
 Set operator=. More...
 
void operator+= (xbInt32 i)
 operator += More...
 
void operator-= (xbInt32 i)
 operator -= More...
 
void operator++ (xbInt32 i)
 operator ++ More...
 
void operator-- (xbInt32 i)
 operator – More...
 
xbInt32 operator- (const xbDate &) const
 operator - More...
 
const char * operator- (xbInt32 i)
 operator - More...
 
const char * operator+ (xbInt32 i)
 operator + More...
 
xbBool operator== (const xbDate &) const
 operator == More...
 
xbBool operator!= (const xbDate &) const
 operator != More...
 
xbBool operator< (const xbDate &) const
 operator < More...
 
xbBool operator> (const xbDate &) const
 > More...
 
xbBool operator<= (const xbDate &) const
 operator <= More...
 
xbBool operator>= (const xbDate &) const
 operator >= More...
 
xbInt16 CalcRollingCenturyForYear (xbInt16 year) const
 Calculate century for a given year. More...
 
xbInt16 CenturyOf () const
 Get century for date. More...
 
xbInt16 CharDayOf (xbString &sOutCharDay)
 Get the day of the week. More...
 
xbInt16 CharMonthOf (xbString &sOutCharMonth)
 Get the month from the date. More...
 
xbBool DateIsValid (const xbString &sDate8) const
 Check a date for valid data. More...
 
xbInt16 DayOf (xbInt16 iFormat) const
 
xbInt16 CTOD (const xbString &sCtodInDate)
 Format MM/DD/YY date. More...
 
xbInt16 FormatDate (const xbString &sFmtIn, xbString &sFmtOut)
 
const char * Str () const
 Return the date value. More...
 
xbBool IsLeapYear (xbInt16 iYear) const
 Determine if date is a leap year. More...
 
xbBool IsLeapYear () const
 Determine if date is a leap year. More...
 
xbInt32 JulianDays () const
 Calculate julian days for a given date. More...
 
xbInt16 JulToDate8 (xbInt32 lJulDate)
 Convert the number of julian days to gregorian date. More...
 
xbInt16 LastDayOfMonth ()
 Set the date to the last day of month for a given date. More...
 
xbInt16 MonthOf () const
 Return the month for the date. More...
 
xbInt16 Set (const xbString &Date8)
 Set the date. More...
 
xbInt16 Sysdate ()
 Set the date equal to the system date. More...
 
xbInt16 YearOf () const
 Returns the year of the date. More...
 
void DisplayError (xbInt16 ErrorCode) const
 Display error message on console for a given error number. More...
 
xbStringGetDefaultDateFormat () const
 Get the default date format. More...
 
xbStringGetDataDirectory () const
 Get the current data directory. More...
 
xbInt16 GetEndianType () const
 Get the Endian type. More...
 
const char * GetErrorMessage (xbInt16 ErrorCode) const
 Get an error message. More...
 
void SetDataDirectory (const xbString &sDataDirectory)
 Set the data directory. More...
 
void SetDefaultDateFormat (const xbString &sDefaultDateFormat)
 Set the default date format. More...
 
xbBool BitSet (unsigned char c, xbInt16 iBitNo) const
 Check a bit in a one byte field and see if it is set. More...
 
xbBool GetDefaultAutoCommit () const
 Get the default auto commit setting. More...
 
void SetDefaultAutoCommit (xbBool bDefaultAutoCommit)
 Set the default auto commit. More...
 
xbStringGetDefaultLogDirectory () const
 
xbStringGetDefaultLogFileName () const
 
void SetDefaultLogDirectory (const xbString &sDefaultLogDirectory)
 
xbBool GetMultiUser () const
 Get the multi user setting. More...
 
void SetMultiUser (xbBool bMultiUser)
 Get the multi user setting. More...
 

Static Public Attributes

static const char * ErrorCodeText []
 

Protected Member Functions

void SetEndianType ()
 Set the endian type. More...
 

Static Protected Attributes

static xbInt16 iEndianType = 0
 
static xbString sNullString = ""
 

Detailed Description

xbDate class.

This xbDate class handles two type of date values:

1) Gregorian dates with a format of CCYYMMDD. This is how dates are stored in dbf files.
2) Julian dates calculated as the number of days since 1901-01-01 + 1721425.

Leap Years: The routines in the class support both leap years (one every four years) and leap centuries (one every four hundred years.)

A leap year is a year having 366 days, which can be evenly divisible by 4 and not by 100.
Leap centuries are years which are evenly divisible by 400.

From a programming perspective, Julian dates are useful for date arithmetic, determining the difference between two dates or calculating a future or past date.

To determine the difference between two dates, convert both dates to a Julian date and subtract one from the other.

To calculate a future or past date, convert the base date to a Julian date, add (or subtract) the number of days necessary to (from) it and convert the julian date back to a Gregorian date.

Constructor & Destructor Documentation

◆ xbDate() [1/4]

xb::xbDate::xbDate ( )

Constructor.

◆ xbDate() [2/4]

xb::xbDate::xbDate ( const char *  sDate8In)

Constructor.

Parameters
sDate8In- Input date.

◆ xbDate() [3/4]

xb::xbDate::xbDate ( const xbString sDate8In)

Constructor.

Parameters
sDate8In- Input date.

◆ xbDate() [4/4]

xb::xbDate::xbDate ( xbInt32  lJulDate)

Constructor.

Parameters
lJulDate- Input julian date.

◆ ~xbDate()

xb::xbDate::~xbDate ( )

Destructor.

Member Function Documentation

◆ BitSet()

xbBool xb::xbSsv::BitSet ( unsigned char  c,
xbInt16  iBitNo 
) const
inherited

Check a bit in a one byte field and see if it is set.

Parameters
cOne byte char field to examine.
iBitNowhich bit to examine.
Returns
xbTrue Bit is set
xbFalse Bit is not set

◆ CalcRollingCenturyForYear()

xbInt16 xb::xbDate::CalcRollingCenturyForYear ( xbInt16  iCalcYear) const

Calculate century for a given year.

This routine calculates a century for a given year. It uses an 80/20 rolling date window to calculate the century.

Parameters
iCalcYear- Two digit year to calculate a century for.
Returns
Century calculated for the two digit year.

◆ CenturyOf()

xbInt16 xb::xbDate::CenturyOf ( ) const

Get century for date.

Returns
This routine returns the century from the date.

◆ CharDayOf()

xbInt16 xb::xbDate::CharDayOf ( xbString sOutCharDay)

Get the day of the week.

Parameters
sOutCharDay- Output character day of week (Sun-Sat).
Returns
XB_INVALID_DATE
XB_NO_ERROR

◆ CharMonthOf()

xbInt16 xb::xbDate::CharMonthOf ( xbString sOutCharMonth)

Get the month from the date.

Parameters
sOutCharMonth- Output character month.
Returns
XB_INVALID_DATE
XB_NO_ERROR

◆ CTOD()

xbInt16 xb::xbDate::CTOD ( const xbString sCtodInDate)

Format MM/DD/YY date.

This routine takes an MM/DD/YY format date as input and populates a date class with the appropriate YYYYMMDD data.

Parameters
sCtodInDate- MM/DD/YY formatted date as input.
Returns
XB_INVALID_OPTION
XB_NO_ERROR

◆ DateIsValid()

xbBool xb::xbDate::DateIsValid ( const xbString sDateIn) const

Check a date for valid data.

Parameters
sDateIn- Date to check for valid formaat of CCYYMMDD.
Returns
xbTrue - Valid date.
xbFalse - Not a valid date.

◆ DayOf()

xbInt16 xb::xbDate::DayOf ( xbInt16  iFormat) const

This routine returns the numeric day.

Parameters
iFormatXB_FMT_WEEK Number of day in WEEK 0-6 ( Sat - Fri )
XB_FMT_MONTH Number of day in MONTH 1-31
XB_FMT_YEAR Number of day in YEAR 1-366
Returns
XB_INVALID_OPTION
XB_NO_ERROR

◆ DisplayError()

void xb::xbSsv::DisplayError ( xbInt16  iErrorCode) const
inherited

Display error message on console for a given error number.

Parameters
iErrorCodeError number to reference

◆ FormatDate()

xbInt16 xb::xbDate::FormatDate ( const xbString sFmtIn,
xbString sOutFmtDate 
)

This routine will reformat a date based on the format specifiers entered in sFmtIn. If no input format is specified, the routine will use the system default date format.

Parameters
sFmtIn- A format specifier with the following paramaters:
  1) YYDDD    -  A julian date format
  2) YY or YYYY will print a 2 or 4 digit year
  3) M,MM,MMM or MMMM
     M    - one digit month if no leading zero
     MM   - two digit month, contains leading zero
     MMM  - Jan through Dec
     MMMM - January through December
  4) D,DD,DDD or DDDD
     D    - one digit dayif no leading zero
     DD   - two digit day, contains leading zero
     DDD  - Sun through Sat (or julian if YYDDD)
     DDDD - Sunday through Saturday
sOutFmtDate- Reformatted output date.
Returns
XB_NO_ERROR

Format Examples:
MM/DD/YY
YYYY-MM-DD
DDDDDDDDDDD MMMMMMMMMMM DD,YYYY

◆ GetDataDirectory()

xbString & xb::xbSsv::GetDataDirectory ( ) const
inherited

Get the current data directory.

Returns
xbString containing the current data directory where the database files are stored.

◆ GetDefaultAutoCommit()

xbBool xb::xbSsv::GetDefaultAutoCommit ( ) const
inherited

Get the default auto commit setting.

When auto commit is enabled, the library will automatically post any updates when moving off an updated record or closing files. If auto commit is disabled, the application program will need to explicitly update the tables using using dbf->Put() and dbf->AppendRecord().

Returns
xbTrue if auto commit is turned on
xbFalse is auto commit is turned off

◆ GetDefaultDateFormat()

xbString & xb::xbSsv::GetDefaultDateFormat ( ) const
inherited

Get the default date format.

Returns
xbString containing the default date format.

◆ GetDefaultLogDirectory()

xbString & xb::xbSsv::GetDefaultLogDirectory ( ) const
inherited

◆ GetDefaultLogFileName()

xbString & xb::xbSsv::GetDefaultLogFileName ( ) const
inherited

◆ GetEndianType()

xbInt16 xb::xbSsv::GetEndianType ( ) const
inherited

Get the Endian type.

Returns
B - Big endian
L - Little endian

◆ GetErrorMessage()

const char * xb::xbSsv::GetErrorMessage ( xbInt16  iErrorCode) const
inherited

Get an error message.

Parameters
iErrorCodeErrorCode is the error number of description to be returned.
Returns
Returns a pointer to a string containing a text description for the error code.

◆ GetMultiUser()

xbBool xb::xbSsv::GetMultiUser ( ) const
inherited

Get the multi user setting.

Returns
xbTrue - Multi user mode turned on.
xbFalse - Multi user mode turned off.

◆ IsLeapYear() [1/2]

xbBool xb::xbDate::IsLeapYear ( ) const

Determine if date is a leap year.

Returns
xbTrue - Is leapyear.
xbFalse - Not a leap year.

◆ IsLeapYear() [2/2]

xbBool xb::xbDate::IsLeapYear ( xbInt16  iYear) const

Determine if date is a leap year.

Parameters
iYear- Year to check for leap year status.
Returns
xbTrue - Is leapyear.
xbFalse - Not a leap year.

◆ JulianDays()

xbInt32 xb::xbDate::JulianDays ( ) const

Calculate julian days for a given date.

Returns
The number of days since 01/01/0001 + JUL_OFFSET.

◆ JulToDate8()

xbInt16 xb::xbDate::JulToDate8 ( xbInt32  lJulDays)

Convert the number of julian days to gregorian date.

Parameters
lJulDays- Julian days.
Returns
XB_NO_ERROR

◆ LastDayOfMonth()

xbInt16 xb::xbDate::LastDayOfMonth ( )

Set the date to the last day of month for a given date.

This routine sets the last date of the month.

Returns
XB_NO_ERROR

◆ MonthOf()

xbInt16 xb::xbDate::MonthOf ( ) const

Return the month for the date.

Returns
The month of the date.

◆ operator!=()

xbBool xb::xbDate::operator!= ( const xbDate dt) const

operator !=

This routine compares two dates for inequality.

Parameters
dt- Date to compare.
Returns
xbTrue - Dates don't match.
xbFalse - Dates match.

◆ operator+()

const char * xb::xbDate::operator+ ( xbInt32  lCount)

operator +

This routine adds additional days to a date field.

Parameters
lCount- Number of days to add.
Returns
New date in CCYYMMDD format.

◆ operator++()

void xb::xbDate::operator++ ( xbInt32  i)

operator ++

This routine adds one day to the date field.

◆ operator+=()

void xb::xbDate::operator+= ( xbInt32  lDays)

operator +=

This routine adds lDays to the date

Parameters
lDays- Number of days to add to the date.

◆ operator-() [1/2]

xbInt32 xb::xbDate::operator- ( const xbDate dt) const

operator -

This routine subtracts one date from another date returning the difference.

Parameters
dt- Date to subtract.
Returns
Number of days

◆ operator-() [2/2]

const char * xb::xbDate::operator- ( xbInt32  lCount)

operator -

This routine subtracts days from a date field.

Parameters
lCount- Number of days to subtract.
Returns
New date in CCYYMMDD format.

◆ operator--()

void xb::xbDate::operator-- ( xbInt32  i)

operator –

This routine subtracts one day from the date field.

◆ operator-=()

void xb::xbDate::operator-= ( xbInt32  lDays)

operator -=

This routine subtracts lDays from the date.

Parameters
lDays- Number of days to subtract from the date.

◆ operator<()

xbBool xb::xbDate::operator< ( const xbDate dt) const

operator <

This routine compares two dates

Parameters
dt- Date to compare.
Returns
xbTrue - Left date is less than right date.
xbFalse - Left date is not less than right date.

◆ operator<=()

xbBool xb::xbDate::operator<= ( const xbDate dt) const

operator <=

This routine compares two dates

Parameters
dt- Date to compare.
Returns
xbTrue - Left date is less than or equal to right date.
xbFalse - Left date is not less than or equal to right date.

◆ operator=()

void xb::xbDate::operator= ( const xbDate dt)

Set operator=.

Parameters
dt- Date value for set operation.

◆ operator==()

xbBool xb::xbDate::operator== ( const xbDate dt) const

operator ==

This routine compares two dates for equality.

Parameters
dt- Date to compare.
Returns
xbTrue - Dates match.
xbFalse - Dates don't match.

◆ operator>()

xbBool xb::xbDate::operator> ( const xbDate dt) const

>

This routine compares two dates

Parameters
dt- Date to compare.
Returns
xbTrue - Left date is greater than right date.
xbFalse - Left date is not greater than right date.

◆ operator>=()

xbBool xb::xbDate::operator>= ( const xbDate dt) const

operator >=

This routine compares two dates

Parameters
dt- Date to compare.
Returns
xbTrue - Left date is greater than or equal to right date.
xbFalse - Left date is not greater than or equal to right date.

◆ Set()

xbInt16 xb::xbDate::Set ( const xbString sDateIn)

Set the date.

Parameters
sDateIn- Input date.
Returns
XB_NO_ERROR
XB_INVALID_DATE

◆ SetDataDirectory()

void xb::xbSsv::SetDataDirectory ( const xbString sDataDirectory)
inherited

Set the data directory.

Parameters
sDataDirectorySet the data direcroty.

◆ SetDefaultAutoCommit()

void xb::xbSsv::SetDefaultAutoCommit ( xbBool  bDefaultAutoCommit)
inherited

Set the default auto commit.

Disabling auto commit requires the application execute explicit updates using dbf->Put() and dbf->AppendRecord(). With auto commit on, the library posts updates automatically when moving off the current record or closing a file.

Parameters
bDefaultAutoCommitxbTrue - Enable default auto commit.
xbFalse - Disable default auto commit.

◆ SetDefaultDateFormat()

void xb::xbSsv::SetDefaultDateFormat ( const xbString sDefaultDateFormat)
inherited

Set the default date format.

Parameters
sDefaultDateFormatSet the default date format.

◆ SetDefaultLogDirectory()

void xb::xbSsv::SetDefaultLogDirectory ( const xbString sDefaultLogDirectory)
inherited

◆ SetEndianType()

void xb::xbSsv::SetEndianType ( )
protectedinherited

Set the endian type.

This routine determines the Endian-ness at run time instead of compile time as some processers (ie; Sparc,ARM) can be switched either way. This routine is called automatically by the library at startup and does not need to be called in an application program.

◆ SetMultiUser()

void xb::xbSsv::SetMultiUser ( xbBool  bMultiUser)
inherited

Get the multi user setting.

Parameters
bMultiUserxbTrue - Turn on Multi user mode.
xbFalse - Turn off Multi user mode.

◆ Str()

const char * xb::xbDate::Str ( ) const

Return the date value.

Returns
char ptr to date value.

◆ Sysdate()

xbInt16 xb::xbDate::Sysdate ( )

Set the date equal to the system date.

Returns
XB_NO_ERROR

◆ YearOf()

xbInt16 xb::xbDate::YearOf ( ) const

Returns the year of the date.

Returns
The year of the date.

Field Documentation

◆ ErrorCodeText

const char* xb::xbSsv::ErrorCodeText[]
staticinherited

◆ iEndianType

xbInt16 xb::xbSsv::iEndianType = 0
staticprotectedinherited

◆ sNullString

xbString xb::xbSsv::sNullString = ""
staticprotectedinherited

The documentation for this class was generated from the following files: