Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

look::LookTime Class Reference

Time. More...

#include <lkdatetime.h>

Inheritance diagram for look::LookTime::

look::LookTypeBase List of all members.

Public Methods

 LookTime (unsigned int theTime=0)
 Constructor. More...

 LookTime (unsigned int theHours, unsigned int theMinutes, unsigned int theSeconds=0)
 Constructor from hours, minutes, seconds. More...

 LookTime (bool isPM, unsigned int theHours, unsigned int theMinutes=0, unsigned int theSeconds=0)
 Constructor from 12 hour clock hours, minutes, seconds. More...

 LookTime (const LookTime &theOther)
 Copy constructor.

 ~LookTime ()
 Destructor.

LookTypeBaseGetNewCopy (void) const
 Get a new copy. More...

long GetTypeID (void) const
 Get Type ID. More...

LookTime& operator= (const LookTime &theOther)
 Assignment op.

bool operator== (const LookTime &theOther) const
 Equal.

bool operator!= (const LookTime &theOther) const
 Not equal.

bool operator< (const LookTime &theOther) const
 Less than.

bool operator> (const LookTime &theOther) const
 Greater than.

bool operator<= (const LookTime &theOther) const
 Less than or equal.

bool operator>= (const LookTime &theOther) const
 Greater than or equal.

LookTime& operator+= (int theChange)
 Add seconds.

LookTime operator+ (int theChange) const
 Add seconds.

int operator- (LookTime &theOther) const
 Seconds between this and theOther. More...

LookTime operator- (int theChange) const
 Subtract seconds.

LookTime& operator-= (int theChange)
 Subtract seconds.

int Normalise (void)
 Normalise. More...

bool Set (LookString theTimeString)
 Set from a string. More...

LookString GetString (const LookString &theSeparator=":", int thePrecision=3, bool hours24=true) const
 Convert to a string. More...

unsigned int Hours (void) const
 Hours (24H clock). More...

unsigned int Hours12 (void) const
 Hours (12H clock). More...

unsigned int Minutes (void) const
 Minutes (0-59).

unsigned int Seconds (void) const
 Seconds (0-59).

bool isPM (void) const
 Is PM? More...

void SetTime (unsigned int theTime)
unsigned int GetTime (void) const

Static Public Methods

LookTime Now (void)
 Get current time (localtime).


Protected Attributes

int itsTime
 Time in seconds since midnight.


Detailed Description

Time.

This class represents a time.

It stores its value as the number of seconds since midnight (integral).


Constructor & Destructor Documentation

look::LookTime::LookTime ( unsigned int theTime = 0 )
 

Constructor.

The default value of 0 is midnight.

Parameters:
theTime   Seconds since midnight

look::LookTime::LookTime ( unsigned int theHours,
unsigned int theMinutes,
unsigned int theSeconds = 0 )
 

Constructor from hours, minutes, seconds.

The time is actually calculated as the sum of the hours, minutes and seconds, ie if you give 26 hours, 70 minutes and 90 seconds it will store 97890 seconds since midnight. Hours() will return 27, Minutes() 11, Seconds() 30 and isPM() true (!). Calling Normalise() will fix hours to 3 and isPM() to false, and return the extra day.

Parameters:
theHours   Hours, 24 hour clock, ie 0-23 (midnight - 11pm)
theMinutes   Minutes 0-59
theSeconds   Seconds 0-59

look::LookTime::LookTime ( bool isPM,
unsigned int theHours,
unsigned int theMinutes = 0,
unsigned int theSeconds = 0 )
 

Constructor from 12 hour clock hours, minutes, seconds.

Parameters:
isPM   true for PM, false for AM
theHours   Hours, 12 hour clock, ie 1-12
theMinutes   Minutes - 0-59
theSeconds   Seconds - 0-59


Member Function Documentation

LookTypeBase * look::LookTime::GetNewCopy ( void ) const [virtual]
 

Get a new copy.

Virtual copy constructor, aka clone.

Returns:
A new copy of this. (You are responsible for deleting it).

Reimplemented from look::LookTypeBase.

LookString look::LookTime::GetString ( const LookString & theSeparator = ":",
int thePrecision = 3,
bool hours24 = true ) const
 

Convert to a string.

If the time is not normalised (Normalise()) the results could look odd.

Parameters:
theSeparator   String to go between h, m and s
thePrecision   3 for hms, 2 for hm, 1 for hours only.
hours24   true for 24 hour clock, ie "23:12:45". False also appends am/pm, ie "11:12:45pm".

long look::LookTime::GetTypeID ( void ) const [virtual]
 

Get Type ID.

Pseudo-rtti, or isA.

Returns:
LookTimeID

Reimplemented from look::LookTypeBase.

unsigned int look::LookTime::Hours ( void ) const
 

Hours (24H clock).

If the time is not normalised (Normalise()), this could be < 0 or > 23.

Returns:
Hours since midnight

unsigned int look::LookTime::Hours12 ( void ) const
 

Hours (12H clock).

This will always return 1-12

Returns:
Hours

int look::LookTime::Normalise ( void )
 

Normalise.

If the time is constructed with a time outside 00:00:00 - 23:59:59, ie negative seconds or greater than 86400 seconds, or a change has been made to make the time wrap over a day, this converts the time back to within a day.

However you don't need to call this after Set() or if you construct with sensible times.

Returns:
Days changed. Eg add 1000 seconds to 23:50:50 gives you 00:07:30 the next day. Normalise after this will give you +1 day.

bool look::LookTime::Set ( LookString theTimeString )
 

Set from a string.

This can cope with a variety of formats. See LookDateTimeReader for a more general converter.

It extracts the first three numbers from theTimeString as hours, minutes and seconds, with numbers being delimited by non-decimal characters. It also finds the last AM and PM (case insensitive). If less than three numbers are found, it uses 0 for the missing ones.

Sensible examples of times which will be successfully converted:

  • 23:45:23
  • 11:45pm
Failures:
  • 23:45:23pm
  • 123:444:21
A coupe of pathological examples (these will succeed!):
  • "11 amps" (= 11:00:00)
  • "11 milliamperes is enough to give the PM a shock." (= 23:00:00. Notice the PM overrides the am.
Parameters:
theTimeString   The string.
Returns:
true for success

bool look::LookTime::isPM ( void ) const
 

Is PM?

It returns true if the time is >= 12 noon. If the time is not normalised (Normalise()), this could return misleading results.

Returns:
true for PM

int look::LookTime::operator- ( LookTime & theOther ) const
 

Seconds between this and theOther.

This is negative if theOther is later than this.

Parameters:
theOther   Other time
Returns:
Difference in seconds.


The documentation for this class was generated from the following files:
Generated at Thu Jan 17 12:53:09 2002 for liblookdb by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001