date


An os_date can represent a date between Jan 1, 4713 b.c. and Dec 31, 32766 a.d. You can compare, subtract, print, and query dates for a variety of useful information. The strings used when accepting or displaying date descriptions are loaded from the operating system when the program starts. If you need to represent a specific time on a specific day, use os_time_and_date instead.

Library

Time<ToolKit>

Declaration

#include <ospace/time/date.h>

class os_date

Enums

enum os_date::
  {
  invalid_weekday = 0,
  sunday,
  monday,
  tuesday,
  wednesday,
  thursday,
  friday,
  saturday
  }


enum os_date::
  {
  invalid_month = 0,
  january,
  february,
  march,
  april,
  may,
  june,
  july,
  august,
  september,
  october,
  november,
  december
  };


enum os_date::
  {
  min_month = january,
  max_month = december,
  min_day = 1,
  max_day = 31,
  min_year = -4713,
  max_year = 32766
  }
  

Interface

Constructor
os_date()
Constructs the date Jan 1, 1970.
Constructor
os_date( long julian_day )
Constructs a date with Julian value julian_day .

Throws: os_time_toolkit_error

Constructor
os_date( os_month_t month , os_day_t day , os_year_t year )
Constructs a date using month (1-12), day (1-31) and year (-4713 (b.c.)...+32766 (a.d.)).

Throws: os_time_toolkit_error

Constructor
os_date( const os_which_one& which , os_weekday_t weekday , os_month_t month , os_year_t year )
Constructs a date that is which weekday of month in year .

Throws: os_time_toolkit_error

Constructor
os_date( const os_date& date )
Constructs a copy of date .
!=
bool operator!=( const os_date& date ) const
Returns true if date is not equal to date .
+
os_date operator+( const os_time_period& period ) const
Returns a date with an added period .
++
os_date operator++( int )
Post-increments date by one day.
++
os_date& operator++()
Preincrements date by one day.
+=
os_date& operator+=( const os_time_period& period )
Adds period to date and returns the new value of date.
-
os_time_period operator-( const os_date& date ) const
Returns the period between date and date .
-
os_date operator-( const os_time_period& period ) const
Returns the period subtracted from date.
--
os_date& operator--()
Predecrements date by one day.
--
os_date operator--( int )
Postdecrements date by one day.
-=
os_date& operator-=( const os_time_period& period )
Subtracts period from date and returns the new value of date.
<
bool operator<( const os_date& date ) const
Returns true if date is earlier than date .
<=
bool operator<=( const os_date& date ) const
Returns true if date is earlier than or equal to date .
=
os_date& operator=( const os_date& date )
Assigns date to date.
==
bool operator==( const os_date& date ) const
Returns true if date has the same day, month, and year as date .
>
bool operator>( const os_date& date ) const
Returns true if date is later than date .
>=
bool operator>=( const os_date& date ) const
Returns true if date is later than or equal to date .
ad_name
/* static */ void ad_name( const string& name )
Changes the a.d. date string to name . [not MTSAFE]
ad_name
/* static */ const string& ad_name()
Returns the a.d. date string. [not MTSAFE]
bc_name
/* static */ const string& bc_name()
Returns the b.c. date string. [not MTSAFE]
bc_name
/* static */ void bc_name( const string& name )
Changes the b.c. date string to name . [not MTSAFE]
calc_calendar_date
/* static */ void calc_calendar_date( long julian_day , os_month_t* month_p , os_day_t* day_p , os_year_t* year_p )
Decodes the Julian day julian_day and places its corresponding date into month_p , day_p , and year_p .

Throws: os_time_toolkit_error

calc_julian_day
/* static */ long calc_julian_day( os_month_t month , os_day_t day , os_year_t year )
Returns the Julian day that encodes a date using month , day, and year .

Throws: os_time_toolkit_error

date
void date( os_month_t month , os_day_t day , os_year_t year )
Sets the date to month (1-12), day (1-31) and year (-4713 (b.c.)...+32766 (a.d.)).

Throws: os_time_toolkit_error

date
void date( const os_which_one& which , os_weekday_t weekday , os_month_t month , os_year_t year )
Sets the date to which weekday of month in year .

Throws: os_time_toolkit_error

day
os_day_t day() const
Returns the day of the month (1-31).
day_of_year
unsigned short day_of_year() const
Returns the day of the year (0-365).
days_in_month
/* static */ os_day_t days_in_month( os_month_t month , os_year_t year )
Returns the number of days in month of year (1-31).

Throws: os_time_toolkit_error

days_in_year
/* static */ unsigned short days_in_year( os_year_t year )
Returns the number of days in year (1-366).

Throws: os_time_toolkit_error

default_format
/* static */ void default_format( const string& format )
Sets default date format to format . [not MTSAFE
default_format
/* static */ string default_format()
Returns the current default date format. [not MTSAFE]
is_ad
bool is_ad() const
Returns true if date occurs on or after Jan 1, 1 a.d.
is_bc
bool is_bc() const
Returns true if date occurs on or before Dec. 31, 1 b.c.
is_day_in_month
/* static */ bool is_day_in_month( os_month_t month , os_day_t day , os_year_t year )
Returns true if day is a valid day in month of year .
is_julian_day
/* static */ bool is_julian_day( long julian_day )
Returns true if julian_day is a valid Julian Day number.
is_leap_year
bool is_leap_year() const
Returns true if date is a leap year.
is_leap_year
/* static */ bool is_leap_year( os_year_t year )
Returns true if year is a leap year.
is_month
/* static */ bool is_month( os_month_t month )
Returns true if month is valid (1-12).
is_weekday
/* static */ bool is_weekday( os_weekday_t weekday )
Returns true if weekday is valid (0-6)
is_year
/* static */ bool is_year( os_year_t year )
Returns true if year is valid (4713 b.c. - 32766 a.d.). Uses a negative value to indicate years b.c. Zero is not a year; 1 b.c. is followed by 1 a.d.
julian_day
long julian_day() const
Returns the Julian Day number (39-13688961).
max_date
/* static */ const os_date& max_date()
Returns the maximum date value.
min_date
/* static */ const os_date& min_date()
Returns the minimum date value.
month
os_month_t month() const
Returns the month index (1-12).
month_abbreviation

/* static */ const string& month_abbreviation( os_month_t
month )
Returns the abbreviated name of the month with index month (1...12).

Throws: os_time_toolkit_error

month_index
/* static */ os_month_t month_index( const string& month )
Returns a value from 1 to 12 if month is a string that matches either the abbreviation or full name of a month in the current locale. Returns invalid_month if the string is not recognized.
month_name
/* static */ const string& month_name( os_month_t month )
Returns the full name of the month with index month (1...12).

Throws: os_time_toolkit_error

next
os_date next( os_weekday_t weekday ) const
Returns the next date that is on weekday . If date is already on weekday , returns the day one week after the date.
previous
os_date previous( os_weekday_t weekday ) const
Returns the previous date that is on weekday . If date is already on weekday , returns the day one week prior to the date.
print
void print( ostream& stream ) const
Prints to stream .
to_string
string to_string() const
Returns date as a formatted string using the default format.
to_string
string to_string( const string& format ) const
Returns date as a formatted string using format .
today
/* static */ os_date today()
Returns the current local date.
week_of_year
os_week_t week_of_year() const
Returns the index of the week in the year.
week_of_year
os_week_t week_of_year( os_weekday_t start_of_week ) const
Returns the week of the year, with start_of_week as the first day of a week (0-53).
weekday
os_weekday_t weekday() const
Returns the weekday.
weekday_abbreviation
/* static */ const string& weekday_abbreviation( os_weekday_t weekday )
Returns the abbreviated name of the weekday with index weekday .

Throws: os_time_toolkit_error

weekday_index
/* static */ os_weekday_t weekday_index( const string& weekday )
Returns a value from 1 (Sunday) to 7 (Saturday) if weekday matches either the abbreviation or full name of a weekday in the current locale. Returns invalid_weekday if the string is not recognized.
weekday_name
/* static */ const string& weekday_name( os_weekday_t weekday )
Returns the full name of the weekday with index weekday .

Throws: os_time_toolkit_error

year
os_year_t year() const
Returns the year (-4713 (b.c.)... +32766 (a.d.)).

Non-Member Functions

+
os_date operator+( const os_time_period& period , const os_date& date )
Returns a date that is period time after date .
<<
ostream& operator<<( ostream& stream , const os_date& date )
Prints date to stream .

Universal Streaming Service

#include <ospace/uss/time.h>

<<
os_bstream& operator<<( os_bstream& stream , const os_date& date )
Writes date to stream .
>>
os_bstream& operator>>( os_bstream& stream , os_date& date )
Reads date from stream .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.