#include <rwsf/core/TimeSpan.h>
rwsf::TimeSpan represents a period as defined by ISO8601. The serialized version of this type takes the format PnYnMnDTnHnMnS, where nY represents the number of years, nM the number of months, nD the number of days, T is the date/time separator, nH the number of hours, nM the number of minutes, and nS the number of seconds. The number of seconds can include decimal digits.
This class provides constructors to create a timespan instance, and convenience methods to access its different parts. An instance of this class can be constructed either from a valid duration string, or by providing values for each of the parts of a duration. This class also provides operators and methods to add a duration to an rwsf::DateTime instance, and to determine the ordering relationship between two durations
An instance of this class validates the data it contains whenever the data changes. If the string is valid, the object marks itself valid. If the string is invalid, the object marks itself invalid.
TimeSpan(unsigned long years = 0, unsigned long months = 0, unsigned long days = 0, unsigned long hours = 0, unsigned long minutes = 0, double seconds = 0.0 );
Constructs an instance of rwsf::TimeSpan based on the values given. The default constructor creates a valid object representing a duration of 0.
TimeSpan(const std::string& duration);
Constructs an instance of rwsf::TimeSpan representing the string duration. Calls extract() to extract the contents. If the string provided is not in the format PnYnMnDTnHnMnS, constructs an invalid object.
TimeSpan(const TimeSpan& other);
Copy constructor. Constructs a deep copy of other.
virtual ~TimeSpan();
Destructor.
virtual std::string asString() const;
Returns a string representation of self, formatted according to the XML Schema specification for the duration simple type. Returns an empty string if self is invalid.
virtual int compareTo(const TimeSpan& rhs);
Returns -1, 0 or 1 depending on whether self is less than, equal to, or greater than rhs, respectively. The comparison is based on value semantics. The duration is converted into a single unit to determine equality, based on the fixed mapping scheme:
1Y == 12M == 365D 1M == 365/12 days 1D == 24H 1H == 60M 1M == 60Seconds
virtual void extract(const std::string& duration);
Extracts duration into self. If the string provided is not in the format PnYnMnDTnHnMnS, marks self as invalid.
unsigned long getDays() const;
Returns the number of days represented by self.
unsigned long getHours() const;
Returns the number of hours represented by self.
unsigned long getMinutes() const;
Returns the number of minutes represented by self.
unsigned long getMonths() const;
Returns the number of months represented by self.
double getSeconds() const;
Returns the number of seconds represented by self.
unsigned long getYears() const;
Returns the number of years represented by self.
virtual bool isEqual(const TimeSpan& rhs);
Equality based on value semantics. Returns true if compareTo(rhs) returns 0.
bool isNegative() const;
Returns true if self is a negative duration.
bool isValid() const;
Returns true if self if valid. Parsing an invalid duration string will lead to an invalid rwsf::TimeSpan instance. The values for years, months, days, and so on are undefined for an invalid instance, as are the return values of all other methods.
void setDays(unsigned long days);
Sets the number of days represented by self to days.
void setHours(unsigned long hours);
Sets the number of hours represented by self to hours.
void setMinutes(unsigned long minutes);
Sets the number of minutes represented by self to minutes.
void setMonths(unsigned long months);
Sets the number of months represented by self to months.
void setSeconds(double seconds);
Sets the number of seconds represented by self to seconds.
void setYears(unsigned long years);
Sets the number of years represented by self to years.
DateTime operator+(const rwsf::DateTime& aDateTime ) const;
Implements addition as defined by Appendix E of the XML Schema - Part 2: Datatypes specification. Given an rwsf::DateTime aDateTime, the addition operator computes an rwsf::DateTime at the end of the time period with start aDateTime and duration represented by self. Note that according to the specified algorithm, the order of addition is significant. For example, there could be cases where
(( aDateTime + aTimespan1 ) + aTimespan2) != (( aDateTime + aTimespan2 ) + aTimespan1 ));
TimeSpan& operator=(const TimeSpan& rhs);
Assignment operator.
TimeSpan& operator-();
Unary negation of self. Changes self to a negative duration if self is positive. Self is changed to a positive duration if self is already a negative duration.
©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks and HydraSDO is a trademark of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.