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 your operating system when the program starts. The following public enumerators are in os_date .

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

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

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

The os_date class has several basic features, such as comparing two dates, accessing a date's attributes, and performing arithmetic on a date. The following example determines the period between two dates: today and the day a person named Mike was born. The output of this example varies with time.

Example <ospace/time/examples/date1.cpp>
#include <iostream>
#include <ospace/time.h>

void
main()
  {
  os_time_toolkit initialize;

  os_date born( os_date::april, 8, 1970 ); // Mike's birth date.
  os_date today = os_date::today(); // Current date.

  // One day.
  os_date tomorrow = today + os_time_period( 1, 0, 0, 0, 0 );
  cout << "born = " << born << " today = " << today << endl;
  cout << "tomorrow = " << tomorrow << endl;
  cout << "today > born = " << (today > born) << endl; // Compare
  cout << "born.year() = " << born.year() << endl;
  cout << "born.is_leap_year() = " << born.is_leap_year() << endl;
  cout << "born month = ";
  cout << os_date::month_name( born.month () ) << endl;
  cout << "born weekday = ";
  cout << os_date::weekday_name( born.weekday () ) << endl;
  cout << "days in 1970 = " << os_date::days_in_year( 1970 ) << endl;

  // Convert to days.
  os_time_period period = today - born; // Subtract.
  cout << "days alive = " << period.to_days() << endl;
  }

born = 04/08/70 today = 08/05/96
tomorrow = 08/06/96
today > born = 1
born.year() = 1970
born.is_leap_year() = 0
born month = April
born weekday = Wednesday
days in 1970 = 365
days alive = 9616

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