Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

SimDate Class Reference
[Data classes]

Class for representing dates and times within the simulation. More...

#include <Date.h>

Inheritance diagram for SimDate:

DateZulu BaseType Date Zulu List of all members.

Public Types

typedef sint32 julian_t
typedef uint08 day_t
typedef uint08 weekday_t
typedef uint08 month_t
typedef sint16 year_t
enum  WEEKDAY {
  MONDAY = 1, TUESDAY = 2, WEDNESDAY = 3, THURSDAY = 4,
  FRIDAY = 5, SATURDAY = 6, SUNDAY = 7
}
enum  MONTH {
  JANUARY = 1, FEBRUARY = 2, MARCH = 3, APRIL = 4,
  MAY = 5, JUNE = 6, JULY = 7, AUGUST = 8,
  SEPTEMBER = 9, OCTOBER = 10, NOVEMBER = 11, DECEMBER = 12
}
typedef double time_t

Public Methods

 SimDate ()
 Construct a default SimDate.

 SimDate (year_t year, month_t month, day_t day, int hour, int minute, time_t second)
 Construct a new SimDate.

 SimDate (julian_t julian, int hour, int minute, time_t second)
 Construct a new SimDate.

 SimDate (const SimDate &d)
 Copy constructor.

const SimDate & operator= (const SimDate &d)
 Assignment operator from another SimDate.

virtual std::string asString () const
 Return a string representation of the date and time.

virtual std::string typeString () const
 Return a string representation of the type.

double update ()
 Update the current simulation time.

virtual int compare (const SimDate &other) const
 Compare with another SimDate.

void setReferenceTime (SimTime target)
 Set the time reference to produce the desired target time.

void pause ()
 Pause further time updates.

void unpause ()
 Restore time updates.

bool isPaused () const
 Test if the simulation time is currently paused.

int addTime (time_t dt)
 Increment the current time, with date rollover and reference fixup.

int setTime (time_t t)
 Set the current time, with date rollover and reference fixup.

virtual void serialize (Archive &)
 Serialize the date and time to or from a data archive.

virtual void parseXML (const char *cdata)
 Parse date/time string from XML cdata.

void convert (struct tm *tm, bool local=false) const
 Store the time into a standard time structure.

void convert (struct tm *tm) const
 Convert the date to a struct tm (time fields are set to zero).

std::string formatString (const char *format, bool local=false) const
 Format the date and time to a string.

std::string formatString (const char *format) const
 Convert the date to a string using strftime formatting.

int setTime (time_t t, bool local=false)
 Set the time.

double getJulianDate () const
 Get the real-valued Julian date.

double getAccurateMST (radian_t longitude=0.0L) const
 Get the (accurate) Mean Sidereal time.

double getMST (radian_t longitude=0.0L) const
 Get the Mean Sidereal time.

bool isLeap () const
 Returns true if this is a leap year.

weekday_t getWeekday () const
 Get the day of the week as an integer (1=MONDAY..7=SUNDAY).

month_t getMonth () const
 Get the month of the year as an integer (1..12).

month_t getDay () const
 Get the day of the month (1..).

year_t getYear () const
 Get the year.

julian_t getJulian () const
 Get the Julian day (as an integer).

const char * getMonthName () const
 Get the full month name (e.g.

const char * getMonthShortName () const
 Get the abbreviated month name (e.g.

const char * getWeekdayName () const
 Get the full day of the week name (e.g.

const char * getWeekdayShortName () const
 Get the abbreviated day of the week name (e.g.

void setJulian (julian_t j)
 Set the Julian day.

int getDayOfYear () const
 Get the day of the year (1..).

int getMondayWeekOfYear () const
 Get the week of the year for weeks starting on Monday.

int getSundayWeekOfYear () const
 Get the week of the year for weeks starting on Sunday.

bool isFirstOfMonth () const
 Returns true if it is the first day of the month (i.e.

bool isLastOfMonth () const
 Returns true if it is the last day of the month.

void addDays (int ndays)
 Add a number of days to the date.

void subtractDays (int ndays)
 Subtract a number of days from the date.

void addMonths (int nmonths)
 Add a number of months to the date.

void subtractMonths (int nmonths)
 Subtract a number of months to the date.

void addYears (int nyears)
 Add a number of years to the date.

void subtractYears (int nyears)
 Subtract a number of years to the date.

virtual int compare (const Date &other) const
 Compare with another Date.

void setTZ (int tz)
 Set the timezone (only effects the local time).

int getTZ () const
 Get the timezone.

int reduce ()
 Wrap time to 24 hour period.

time_t getTime (bool local=false) const
 Get the curret time in seconds since midnight.

bool overflow () const
 Test if the time accumulator exceeds 24 hours.

int getHour (bool local=false) const
 Get the hour.

int getMinute () const
 Get the minute.

int getSecond () const
 Get the second.

int rollover ()
 Adjust the time to fit into the range 0-86400.

virtual void convertXML ()
 Convert XML data to internal format prior to serialization.


Static Public Methods

SimTime interval (SimTime a, SimTime b)
 The difference between two times.

SimTime getSystemTime ()
 Return the current system clock.

bool validYMD (year_t year, month_t month, day_t day)
 Check if a given (year, month, day) exists.

bool isLeap (year_t year)
 Returns true if the year is a leap year.

int getDaysInMonth (month_t month, year_t year)
 Get the number of days in a month.

int getWeeksInYear (year_t year)
 Get the number of weeks in a year (for weeks starting on Monday).

int getSundayWeeksInYear (year_t year)
 Get the number of weeks in a year (for weeks starting on Sunday).

int compare (const Date &a, const Date &b)
 Compare two dates.


Detailed Description

Class for representing dates and times within the simulation.

Author:
Mark Rose <mrose@stm.lbl.gov>


Member Typedef Documentation

typedef uint08 Date::day_t [inherited]
 

typedef sint32 Date::julian_t [inherited]
 

typedef uint08 Date::month_t [inherited]
 

typedef double Zulu::time_t [inherited]
 

typedef uint08 Date::weekday_t [inherited]
 

typedef sint16 Date::year_t [inherited]
 


Member Enumeration Documentation

enum Date::MONTH [inherited]
 

Enumeration values:
JANUARY 
FEBRUARY 
MARCH 
APRIL 
MAY 
JUNE 
JULY 
AUGUST 
SEPTEMBER 
OCTOBER 
NOVEMBER 
DECEMBER 

enum Date::WEEKDAY [inherited]
 

Enumeration values:
MONDAY 
TUESDAY 
WEDNESDAY 
THURSDAY 
FRIDAY 
SATURDAY 
SUNDAY 


Constructor & Destructor Documentation

SimDate::SimDate   [inline]
 

Construct a default SimDate.

See also:
DateZulu()

SimDate::SimDate year_t    year,
month_t    month,
day_t    day,
int    hour,
int    minute,
time_t    second
[inline]
 

Construct a new SimDate.

Parameters:
year  the year (e.g. 2000)
month  the month (1-12)
day  the day (1-31)
hour  the hour (0-23)
minute  the minute (0-59)
second  the second (0.0-60.0)

SimDate::SimDate julian_t    julian,
int    hour,
int    minute,
time_t    second
[inline]
 

Construct a new SimDate.

Parameters:
julian  the Julian day.
hour  the hour (0-23)
minute  the minute (0-59)
second  the second (0.0-60.0)

SimDate::SimDate const SimDate &    d [inline]
 

Copy constructor.

The new SimDate will be unpaused, regardless of the paused state of the source SimDate.


Member Function Documentation

void Date::addDays int    ndays [inline, inherited]
 

Add a number of days to the date.

void Date::addMonths int    nmonths [inherited]
 

Add a number of months to the date.

The day will be truncated to fit within the new month.

int SimDate::addTime time_t    dt [inline]
 

Increment the current time, with date rollover and reference fixup.

Parameters:
dt  The time interval (in seconds)

Reimplemented from DateZulu.

void Date::addYears int    nyears [inherited]
 

Add a number of years to the date.

February 29 change to February 28 for non-leap years.

virtual std::string SimDate::asString   const [inline, virtual]
 

Return a string representation of the date and time.

Returns:
a string of the form "YYYY/MM/DD HH:MM::SSz"

Implements BaseType.

virtual int Date::compare const Date   other const [inline, virtual, inherited]
 

Compare with another Date.

Returns:
+1 if this > other, -1 if this < other, and 0 if the dates are equal.

int Date::compare const Date   a,
const Date   b
[static, inherited]
 

Compare two dates.

Returns:
+1 if a > b, -1 if a < b, or 0 if a == b.

virtual int SimDate::compare const SimDate &    other const [inline, virtual]
 

Compare with another SimDate.

Returns:
+1 if this > other, -1 if this < other, and 0 if the dates and times are equal.

void Date::convert struct tm *    tm const [inherited]
 

Convert the date to a struct tm (time fields are set to zero).

void DateZulu::convert struct tm *    tm,
bool    local = false
const [inherited]
 

Store the time into a standard time structure.

Parameters:
tm  The time structure to set (see <time.h>)
local  Optionally adjust the time for the local timezone.

Reimplemented from Zulu.

void BaseType::convertXML   [virtual, inherited]
 

Convert XML data to internal format prior to serialization.

This method is currently only called by the XML parser for Object classes. If another BaseType class requires this method, a call must be added to the appropriate XML handler in the parser.

std::string Date::formatString const char *    format const [inherited]
 

Convert the date to a string using strftime formatting.

std::string DateZulu::formatString const char *    format,
bool    local = false
const [inherited]
 

Format the date and time to a string.

Parameters:
format  Identical to the format string used by strftime() (Google: strftime)
local  Optionally adjust the time for the local timezone.
Returns:
The formatted date/time string.

Reimplemented from Zulu.

double DateZulu::getAccurateMST radian_t    longitude = 0.0L const [inherited]
 

Get the (accurate) Mean Sidereal time.

Deprecated:
This routine now calls getMST and remains only for backwards compatibility. It may be removed in a future version of SimData.

month_t Date::getDay   const [inline, inherited]
 

Get the day of the month (1..).

int Date::getDayOfYear   const [inline, inherited]
 

Get the day of the year (1..).

int Date::getDaysInMonth month_t    month,
year_t    year
[static, inherited]
 

Get the number of days in a month.

int Zulu::getHour bool    local = false const [inline, inherited]
 

Get the hour.

Parameters:
local  adjust the result to reflect the timezone.

julian_t Date::getJulian   const [inline, inherited]
 

Get the Julian day (as an integer).

double DateZulu::getJulianDate   const [inline, inherited]
 

Get the real-valued Julian date.

Returns:
The Julian date and time as a real value, with the whole part of the result equal to the Julian day, and the fractional part of the result encoding the time of day.

int Zulu::getMinute   const [inline, inherited]
 

Get the minute.

int Date::getMondayWeekOfYear   [inherited]
 

Get the week of the year for weeks starting on Monday.

month_t Date::getMonth   const [inline, inherited]
 

Get the month of the year as an integer (1..12).

const char * Date::getMonthName   [inherited]
 

Get the full month name (e.g.

"January").

const char * Date::getMonthShortName   [inherited]
 

Get the abbreviated month name (e.g.

"Jan").

double DateZulu::getMST radian_t    longitude = 0.0L const [inherited]
 

Get the Mean Sidereal time.

Parameters:
longitude  The local longitude in radians.
Returns:
The mean sidereal time (in radians) for the specified latitude using a third-order polynomial approximation.

int Zulu::getSecond   const [inline, inherited]
 

Get the second.

int Date::getSundayWeekOfYear   [inherited]
 

Get the week of the year for weeks starting on Sunday.

int Date::getSundayWeeksInYear year_t    year [static, inherited]
 

Get the number of weeks in a year (for weeks starting on Sunday).

SimTime SimDate::getSystemTime   [inline, static]
 

Return the current system clock.

Returns:
the system time in seconds (~ 3 millisecond accuracy).

time_t Zulu::getTime bool    local = false const [inline, inherited]
 

Get the curret time in seconds since midnight.

Parameters:
local  adjust the result to reflect the timezone.

int Zulu::getTZ   const [inline, inherited]
 

Get the timezone.

weekday_t Date::getWeekday   const [inline, inherited]
 

Get the day of the week as an integer (1=MONDAY..7=SUNDAY).

const char * Date::getWeekdayName   [inherited]
 

Get the full day of the week name (e.g.

"Monday").

const char * Date::getWeekdayShortName   [inherited]
 

Get the abbreviated day of the week name (e.g.

"Mon").

int Date::getWeeksInYear year_t    year [static, inherited]
 

Get the number of weeks in a year (for weeks starting on Monday).

year_t Date::getYear   const [inline, inherited]
 

Get the year.

SimTime SimDate::interval SimTime    a,
SimTime    b
[inline, static]
 

The difference between two times.

Both times should be in the range [0, 86400).

Parameters:
a  A time value.
b  A time value.

bool Date::isFirstOfMonth   const [inline, inherited]
 

Returns true if it is the first day of the month (i.e.

day == 1).

bool Date::isLastOfMonth   const [inline, inherited]
 

Returns true if it is the last day of the month.

bool Date::isLeap year_t    year [inline, static, inherited]
 

Returns true if the year is a leap year.

bool Date::isLeap   const [inline, inherited]
 

Returns true if this is a leap year.

bool SimDate::isPaused   const [inline]
 

Test if the simulation time is currently paused.

const SimDate & SimDate::operator= const SimDate &    d
 

Assignment operator from another SimDate.

bool Zulu::overflow   const [inline, inherited]
 

Test if the time accumulator exceeds 24 hours.

void SimDate::parseXML const char *    cdata [virtual]
 

Parse date/time string from XML cdata.

The format is either: <Date name='...'>yyyy-mm-dd hh-mm-ss.ms</Date> where '.ms' is optional, or: <Date name='...'>yyyy-mm-dd</Date> in which case the time is set to zero.

Reimplemented from BaseType.

void SimDate::pause   [inline]
 

Pause further time updates.

Subsequent calls to update will not increment the time until unpause() is called.

int Zulu::reduce   [inherited]
 

Wrap time to 24 hour period.

Reduces the seconds since midnight to the range 0-86400.

Returns:
the number of days subtracted to bring the time into range.

int Zulu::rollover   [inline, inherited]
 

Adjust the time to fit into the range 0-86400.

Returns:
the number of days added or subtracted.

void SimDate::serialize Archive   [virtual]
 

Serialize the date and time to or from a data archive.

Reimplemented from BaseType.

void Date::setJulian julian_t    j [inline, inherited]
 

Set the Julian day.

void SimDate::setReferenceTime SimTime    target [inline]
 

Set the time reference to produce the desired target time.

Parameters:
target  The desired simulation time, right NOW! (seconds: 0-86400)

int Zulu::setTime time_t    t,
bool    local = false
[inline, inherited]
 

Set the time.

Parameters:
t  the number of seconds since midnight.
local  if true, t represents the local time (not zulu).

int SimDate::setTime time_t    t [inline]
 

Set the current time, with date rollover and reference fixup.

Parameters:
t  The current time of day (in seconds).

Reimplemented from DateZulu.

void Zulu::setTZ int    tz [inline, inherited]
 

Set the timezone (only effects the local time).

Parameters:
tz  timezone (hour offset from Greenwich mean)

void Date::subtractDays int    ndays [inline, inherited]
 

Subtract a number of days from the date.

void Date::subtractMonths int    nmonths [inherited]
 

Subtract a number of months to the date.

The day will be truncated to fit within the new month.

void Date::subtractYears int    nyears [inherited]
 

Subtract a number of years to the date.

February 29 change to February 28 for non-leap years.

virtual std::string SimDate::typeString   const [inline, virtual]
 

Return a string representation of the type.

Implements BaseType.

void SimDate::unpause   [inline]
 

Restore time updates.

Subsequent calls to update() will advance the time starting from the point at which setPause() was called.

double SimDate::update  
 

Update the current simulation time.

Called by the simulation loop to update the current simulation time using the system clock. Time rolls over past midnight and updates the date. Don't go for more than 24 hrs without calling this or you may lose a day of simulation time.

Returns:
the elapsed time since the last call in seconds.

bool Date::validYMD year_t    year,
month_t    month,
day_t    day
[inline, static, inherited]
 

Check if a given (year, month, day) exists.


The documentation for this class was generated from the following files:
SimData version pre-0.4.0. For more information on SimData, visit the SimData Homepage.

Generated on Tue Oct 14 12:06:42 2003, using Doxygen 1.2.18.

[SF.net]