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

lfc::Time Class Reference

represents an encapsulated representation of date & time. More...

Inheritance diagram for lfc::Time::

lfc::Object lfc::_Serializable lfc::_Formatable lfc::_Scanable List of all members.

Public Types

enum  Month {
  January, February, March, April,
  May, June, July, August,
  September, October, November, December
}
 months constants. More...


Public Methods

 Time () throw ()
 Time (const Time &t) throw ()
 Time (int year, Month month, int day, int hour=0, int min=0, int sec=0)
virtual ~Time () throw ()
virtual short year () const throw ()
 
Returns:
the current year inside the object.
More...


virtual short month () const throw ()
 
Returns:
the current month inside the object.
More...


virtual short day () const throw ()
 
Returns:
a value in (1..31), representing the current day of the month inside the object.
More...


virtual short hour () const throw ()
 
Returns:
a value in (0..23), representing the current hour after midnight, inside the object.
More...


virtual short minute () const throw ()
 
Returns:
a value in (0..59), representing the current minute after hour, inside the object.
More...


virtual short second () const throw ()
 
Returns:
a value in (0..59), representing the current second after minute, inside the object.
More...


virtual short dayOfTheWeek () const throw ()
 
Returns:
the current day of the week inside the object.
More...


virtual short dayOfTheYear () const throw ()
 
Returns:
the current day of the year inside the object.
More...


virtual void setYear (int year)
 sets the current year inside the object, if valid. More...

virtual void setMonth (Month month)
 sets the current month inside the object, if valid. More...

virtual void setDay (int day)
 sets the current day of the month inside the object, if valid. More...

virtual void setHour (int hour)
 sets the current hour inside the object, if valid. More...

virtual void setMinute (int min)
 sets the current minute inside the object, if valid. More...

virtual void setSecond (int sec)
 sets the current second inside the object, if valid. More...

virtual const string monthName (short monthIndex) const
 
Returns:
a string representing the name of the month.
More...


virtual const string dayName (short dayIndex) const
 
Returns:
a string representing the name of the day of the week.
More...


virtual bool operator== (const Time &t) const throw ()
virtual bool operator< (const Time &t) const throw ()
virtual const Time & operator= (const Time &t) throw ()
virtual const TimeSpan operator- (const Time &t) const
virtual const Time operator+ (const TimeSpan &ts) const
virtual const Time operator- (const TimeSpan &ts) const
virtual void update () throw ()
 updates the current object to the system's current date/time. More...

virtual void writeObject (BinaryOutput &stream) const
 platform independent serialization. More...

virtual void readObject (BinaryInput &stream)
 platform independent deserialization. More...

virtual void formatObject (TextOutput &stream, string format="") const
 formatting based on a certain format. More...

virtual void scanObject (TextInput &stream, string format="")
 scanning based on a certain format. More...


Protected Methods

virtual short monthIndex (const string &monthName) const

Protected Attributes

time_t m_time

Static Protected Attributes

const time_t NULL_TIME = time_t(-1)
 a representation of an invalid date/time value. More...


Detailed Description

represents an encapsulated representation of date & time.

Here's a small sample of how to use Time:

    Time t(2016, Time::December, 25);
    Console console;
    TextOutput to(console);

    to << "In 2016, Christmas will be on a "
       << t.dayName(t.dayOfTheWeek()) << ".\n"
       << "Unfortunately, 'till then we'll have to wait for:\n"
       << formattedOut(t - Time(),
        "-d 'days', -h 'hours', -m 'minutes and' -s 'seconds'")
       << ENDL
       << "That's a pretty long time, isn't it ? :)" << ENDL;

Todo:
make this thread safe

See also:
TimeSpan


Member Enumeration Documentation

enum lfc::Time::Month
 

months constants.

Enumeration values:
January 
February 
March 
April 
May 
June 
July 
August 
September 
October 
November 
December 


Constructor & Destructor Documentation

lfc::Time::Time   throw () [inline]
 

lfc::Time::Time const Time &    t throw () [inline]
 

lfc::Time::Time int    year,
Month    month,
int    day,
int    hour = 0,
int    min = 0,
int    sec = 0
 

You must provide valid values, otherwise an TimeException will be thrown.

Parameters:
month  must be in (0..11) or you can use the Month constants
day  must be in (1..31)
hour  must be in (0..23)
minute  must be in (0..59)
second  must be in (0..59)
The same rule applies to the "setXXX" methods.

virtual lfc::Time::~Time   throw () [inline, virtual]
 


Member Function Documentation

virtual short lfc::Time::year   const throw () [inline, virtual]
 

Returns:
the current year inside the object.

virtual short lfc::Time::month   const throw () [inline, virtual]
 

Returns:
the current month inside the object.

    -  0 = January
    -  1 = February
    ...
    - 11 = December
    

virtual short lfc::Time::day   const throw () [inline, virtual]
 

Returns:
a value in (1..31), representing the current day of the month inside the object.

virtual short lfc::Time::hour   const throw () [inline, virtual]
 

Returns:
a value in (0..23), representing the current hour after midnight, inside the object.

virtual short lfc::Time::minute   const throw () [inline, virtual]
 

Returns:
a value in (0..59), representing the current minute after hour, inside the object.

virtual short lfc::Time::second   const throw () [inline, virtual]
 

Returns:
a value in (0..59), representing the current second after minute, inside the object.

virtual short lfc::Time::dayOfTheWeek   const throw () [inline, virtual]
 

Returns:
the current day of the week inside the object.

    - 0 = Sunday
    - 1 = Monday
    ...
    - 6 = Saturday
    

virtual short lfc::Time::dayOfTheYear   const throw () [inline, virtual]
 

Returns:
the current day of the year inside the object.

    -   0 = January 1
    -   1 = January 2
    ...
    - 365 = December 31
    

void lfc::Time::setYear int    year [virtual]
 

sets the current year inside the object, if valid.

void lfc::Time::setMonth Month    month [virtual]
 

sets the current month inside the object, if valid.

void lfc::Time::setDay int    day [virtual]
 

sets the current day of the month inside the object, if valid.

void lfc::Time::setHour int    hour [virtual]
 

sets the current hour inside the object, if valid.

void lfc::Time::setMinute int    min [virtual]
 

sets the current minute inside the object, if valid.

void lfc::Time::setSecond int    sec [virtual]
 

sets the current second inside the object, if valid.

const string lfc::Time::monthName short    monthIndex const [virtual]
 

Returns:
a string representing the name of the month.

Parameters:
month  must be in (0..11; 0 = January), otherwise the returned value will be an empty string

const string lfc::Time::dayName short    dayIndex const [virtual]
 

Returns:
a string representing the name of the day of the week.

Parameters:
day  must be in (0..6; 0 = Sunday), otherwise the returned value will be an empty string

virtual bool lfc::Time::operator== const Time &    t const throw () [inline, virtual]
 

virtual bool lfc::Time::operator< const Time &    t const throw () [inline, virtual]
 

virtual const Time& lfc::Time::operator= const Time &    t throw () [inline, virtual]
 

virtual const TimeSpan lfc::Time::operator- const Time &    t const [inline, virtual]
 

virtual const Time lfc::Time::operator+ const TimeSpan   ts const [inline, virtual]
 

virtual const Time lfc::Time::operator- const TimeSpan   ts const [inline, virtual]
 

virtual void lfc::Time::update   throw () [inline, virtual]
 

updates the current object to the system's current date/time.

void lfc::Time::writeObject BinaryOutput   stream const [virtual]
 

platform independent serialization.

Reimplemented from lfc::_Serializable.

void lfc::Time::readObject BinaryInput   stream [virtual]
 

platform independent deserialization.

Reimplemented from lfc::_Serializable.

void lfc::Time::formatObject TextOutput   stream,
string    format = ""
const [virtual]
 

formatting based on a certain format.

The format must be as follows:

    Symbol      Meaning                 Presentation       Example
    ------      -------                 ------------       -------
    y           year                    Number             1996
    yy          abbreviated year        Number             96
    M           month in year           Number             07
    MM          month in year           Text               July
    d           day in month            Number             10
    h           hour in am/pm (1~12)    Number             12
    H           hour in day (0~23)      Number             0
    m           minute in hour          Number             30
    s           second in minute        Number             55
    S           millisecond             Number             978
    E           day in week             Text               Tuesday
    a           am marker               Text               AM
    p           pm marker               Text               PM
    '           escape for text         Text               'seconds'
    ''          single quote            Text               '
    

Any characters in the pattern that are not in this formatting list will be treated as quoted text. For instance, characters like ':', ',', '.', ' ', '#' and '@' will appear in the resulting time text even they are not embraced within single quotes.

Examples:

    Format Pattern               Result
    --------------               ------
    "y.M.d 'at' H:m:s"    ->>    "1996.07.10 at 15:08:56"
    "E, MM d, ''yy"       ->>    "Wed, July 10, '96"
    "h:m p"               ->>    "11:08 PM"
    "h 'o''''clock' a"    ->>    "11 o'clock AM"
    "y.MM.d h:m a"        ->>    "1996.July.10 11:08 AM"
    

Reimplemented from lfc::_Formatable.

void lfc::Time::scanObject TextInput   stream,
string    format = ""
[virtual]
 

scanning based on a certain format.

The format used for scanning is identical to that used for formatting and if the format or the data coming from the stream are invalid, an TimeException will be thrown.

If you wonder how an valid scanning format for Time looks like, here goes:

  • the format should contain at least the Day, the Month and the Year (the "yy" symbol will be ignored, so be careful to use "y"), which should be read once and only once. Unless specified, time will be considered to be the midnight of the already provided date;
  • if you use the symbol 'h', for hour in am/pm, you must also provide an a/p symbol in the format (which stands for am/pm), anywhere inside it.

Reimplemented from lfc::_Scanable.

short lfc::Time::monthIndex const string &    monthName const [protected, virtual]
 


Member Data Documentation

const time_t lfc::Time::NULL_TIME = time_t(-1) [static, protected]
 

a representation of an invalid date/time value.

time_t lfc::Time::m_time [protected]
 


The documentation for this class was generated from the following files:
Generated on Fri Jan 25 03:14:05 2002 for LFC2 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001