PDate Class Reference

Detailed Description

The PDate class provides a calendar date (year, month, and day numbers) in the Gregorian calendar; PDate instances are immutable (thread-safe).

Definition at line 27 of file PDate.h.

#include <PDate.h>

Constructor & Destructor Documentation

◆ PDate() [1/4]

PDate::PDate ( )

Constructs an empty (invalid) date.

See also
IsValid()

◆ PDate() [2/4]

PDate::PDate ( const PDate other)

Constructs a shared copy of other.

◆ PDate() [3/4]

PDate::PDate ( papillon::int32  y,
papillon::int32  m,
papillon::int32  d 
)
explicit

Constructs a date with year y, month m and day d.

If the specified date is invalid, the date is not set and IsValid() returns false.

◆ PDate() [4/4]

PDate::PDate ( const PString ISOdate)
explicit

Constructs a date represented by the specified string.

Assume ISO 8601 extended format: either YYYY-MM-DD for dates or YYYY-MM-DDTHH:MM:SS, YYYY-MM-DDTHH:MM:SSTZD (e.g., 1997-07-16T19:20:30+01:00) for combined dates and times. If the specified date is invalid, the date is not set and IsValid() returns false.

◆ ~PDate()

virtual PDate::~PDate ( )
virtual

Destroys this object.

Member Function Documentation

◆ AddDays()

PDate PDate::AddDays ( papillon::int32  ndays) const

Returns a PDate object containing a date ndays later than the date of this object (or earlier if ndays is negative).

Returns an invalid date if the current date is invalid or the new date is out of range.

◆ AddMonths()

PDate PDate::AddMonths ( papillon::int32  nmonths) const

Returns a PDate object containing a date nmonths later than the date of this object (or earlier if ndays is negative).

Returns an invalid date if the current date is invalid or the new date is out of range.

◆ AddYears()

PDate PDate::AddYears ( papillon::int32  nyears) const

Returns a PDate object containing a date nyears later than the date of this object (or earlier if ndays is negative).

Returns an invalid date if the current date is invalid or the new date is out of range.

◆ Compare()

papillon::int32 PDate::Compare ( const PDate other) const

Compares this date with another one, then returns 0 if equal, a negative number if this date is earlier than other, a positive number if this date is later than other.

◆ Current()

static PDate PDate::Current ( )
static

Returns the current date, as reported by the system clock.

◆ GetDate()

void PDate::GetDate ( papillon::int32 *  year,
papillon::int32 *  month,
papillon::int32 *  day 
)

Extracts the date's year, month, and day, and assigns them to *year, month, and *day.

The pointers may be null.

◆ GetDay()

papillon::int32 PDate::GetDay ( ) const

Returns the day of the month (1 to 31) of this date or returns 0 if the date is invalid.

◆ GetDaysTo()

papillon::int32 PDate::GetDaysTo ( const PDate d) const

Returns the number of days from this date to d (which is negative if d is earlier than this date).

Returns 0 if either this date or d is invalid.

◆ GetMonth()

papillon::int32 PDate::GetMonth ( ) const

Returns the number corresponding to the month of this date, using the following convention: 1 = "January", ..., 12 = "December" or returns 0 if the date is invalid.

◆ GetYear()

papillon::int32 PDate::GetYear ( ) const

Returns the year of this date or returns 0 if the date is invalid.

Negative numbers indicate years before 1 CE, such that year -62 is 62 BCE

◆ IsValid()

bool PDate::IsValid ( ) const

Returns true if this date is valid; otherwise returns false.

◆ operator!=()

bool PDate::operator!= ( const PDate d) const

Returns true if this date is different from d; otherwise returns false.

◆ operator<()

bool PDate::operator< ( const PDate d) const

Returns true if this date is earlier than d; otherwise returns false.

◆ operator<=()

bool PDate::operator<= ( const PDate d) const

Returns true if this date is earlier than or equal to d; otherwise returns false.

◆ operator=()

PDate& PDate::operator= ( const PDate other)

Performs a shared copy of other to this object.

◆ operator==()

bool PDate::operator== ( const PDate d) const

Returns true if this date is equal to d; otherwise returns false.

◆ operator>()

bool PDate::operator> ( const PDate d) const

Returns true if this date is later than d; otherwise returns false.

◆ operator>=()

bool PDate::operator>= ( const PDate d) const

Returns true if this date is later than or equal to d; otherwise returns false.

◆ ToString()

PString PDate::ToString ( const PString format = PString("yyyy-MM-dd")) const

Returns the date as a string.

The format parameter determines the format of the result string; use "yyyy-MM-dd" by default.

These expressions may be used:

  • d: the day as number without a leading zero (1 to 31)
  • dd: the day as number with a leading zero (01 to 31)
  • ddd: the abbreviated localized day name (e.g 'Mon' to 'Sun')
  • dddd: the long localized day name (e.g 'Monday' to 'Sunday')
  • M: the month as number without a leading zero (1 to 12)
  • MM: the month as number with a leading zero (01 to 12)
  • MMM: the abbreviated localized month name (e.g 'Jan' to 'Dec')
  • MMMM: the long localized month name (e.g 'January' to 'December')
  • yy: the year as two digit number (00 to 99)
  • yyyy: the year as four digit number. If the year is negative, a minus sign is prepended in addition

All other input characters will be ignored. Any sequence of characters that are enclosed in single quotes will be treated as text and not be used as an expression. Two consecutive single quotes ("''") are replaced by a single quote in the output. Formats without separators (e.g&#x2e; "ddMM") are currently not supported. If the date is invalid, an empty string will be returned.

◆ ToStringISO()

PString PDate::ToStringISO ( ) const

Returns the date as a string; the format corresponds to the ISO 8601 extended specification for representations of dates and times, taking the form YYYY-MM-DD, where YYYY is the year, MM is the month of the year (between 01 and 12), and DD is the day of the month between 01 and 31.

If the date is invalid, an empty string will be returned.