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

look::LookDateTimeReader Class Reference

Converts strings to date/times. More...

#include <lkdatetimereader.h>

List of all members.

Public Types

enum  DatePartOrder {
  AnyPreferDMY = 1, AnyPreferMDY, DMY, MDY,
  YMD
}
 What order will the date parts be in? More...

enum  DateTimeOrder { AnyPreferDT = 1, AnyPreferTD, DT, TD }
 What order will the date and time be in? More...


Static Public Methods

bool ReadDate (const LookString &theString, LookDate &theDate, DatePartOrder partOrder=AnyPreferDMY)
 Try to parse a date. More...

bool ReadTime (const LookString &theString, LookTime &theTime)
 Try to parse a time. More...

bool ReadDateTime (const LookString &theString, LookDateTime &theDateTime, DateTimeOrder dtOrder=AnyPreferDT, DatePartOrder partOrder=AnyPreferDMY)
 Try to parse a date/time. More...


Static Protected Methods

bool FindYearPart (const LookString &theString, bool &yearIsAtBegin)
void SplitToParts (LookStringList &theParts, const LookString &theString)
LookString GetAlphaOnly (LookString theString)
bool FindMonthString (LookStringList &theParts, int &monthIndex)
bool IsNumeric (const LookString &theString)
void CombineSplitStrings (const LookStringList &theParts, long theSplitPos, LookString &beforeString, LookString &afterString)
void GuessDTOrder (const LookString &theString, DateTimeOrder &dtOrder)
void SplitToPartsFindSeps (LookStringList &theParts, LongValList &theDateSepPositions, LongValList &theTimeSepPositions, const LookString &theString)
void CheckForSepsAndAddIfValid (LookString theString, LookStringList &theParts, LongValList &theDateSepPositions, LongValList &theTimeSepPositions)


Detailed Description

Converts strings to date/times.

This tries quite hard to convert a string (eg user input) into a date and time.

It can cope with spelled months of the form January and Jan, and also roman numerals (eg "IX"). This is of course case-insensitive.

You can specify the order the date parts should be in. Eg "20012012" could be 20 Dec 2001 or 20 Jan 2012. If you leave it to guess if will give up, but if you know the format it will use that.

Similarly you can specify the order date and time parts should be in. Eg "20-12-09 13-05-12" could be 13:05:12 on 20 December 2009 or the other way round.

Times are always Hours Minutes Seconds.

It treats any non-digit characters as spacing the date/time parts, and it will also cope with non-split strings (eg 20010531 (which will be guessed as ymd)). (however time and date must be split)

It uses the fact that some dates/times are impossible to help it tell which it actually is. Eg 05312001 is MDY

With date/time, it knows that : and . tend to seperate time parts, and / and - do dates, and uses that to help.

I have found it copes with most sensible input and quite a lot of less sensible input too. If used in a user interface it is recommended to show the results it managed to convert in a non-ambiguous form so the user can see it understood.

If it fails to convert, DbError is set appropriately.


Member Enumeration Documentation

enum look::LookDateTimeReader::DatePartOrder
 

What order will the date parts be in?

Enumeration values:
AnyPreferDMY   Any, but if it comes to a choice between DMY and MDY it chooses DMY (UK)
AnyPreferMDY   Any, but if it comes to a choice between DMY and MDY it chooses MDY (US)
DMY   Forces DMY. Eg 2001-31-05 will be rejected
MDY   Forces MDY.
YMD   Forces YMD.

enum look::LookDateTimeReader::DateTimeOrder
 

What order will the date and time be in?

Enumeration values:
AnyPreferDT   Any but given the choice use date then time
AnyPreferTD   Any but given the choice use time then date
DT   Date then time
TD   Time then date


Member Function Documentation

bool look::LookDateTimeReader::ReadDate ( const LookString & theString,
LookDate & theDate,
DatePartOrder partOrder = AnyPreferDMY ) [static]
 

Try to parse a date.

Parameters:
theString   String to parse
theDate   Date to put result in
partOrder   Hint to the parser
Returns:
true for success. If false, DbError will be set.

bool look::LookDateTimeReader::ReadDateTime ( const LookString & theString,
LookDateTime & theDateTime,
DateTimeOrder dtOrder = AnyPreferDT,
DatePartOrder partOrder = AnyPreferDMY ) [static]
 

Try to parse a date/time.

Parameters:
theString   String to parse
theDateTime   Datetime to put result in
dtOrder   Hint to parser
partOrder   Hint to parser
Returns:
true for success. If false, DbError will be set.

bool look::LookDateTimeReader::ReadTime ( const LookString & theString,
LookTime & theTime ) [static]
 

Try to parse a time.

Parameters:
theString   String to parse
theTime   Time to put result in
Returns:
true for success. If false, DbError will be set.


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