MFC Grid manual

CLongDateFormat Class Reference

Transforms time represented by 32-bit value that is a number of seconds elapsed since midnight, January 1, 1970. More...

#include <Dapfor/Common/LongDateFormat.h>

Inheritance diagram for CLongDateFormat:

CFormat

List of all members.


Public Types

enum  Style {
  year = 0x1, short_year = 0x2, month = 0x4, day = 0x8,
  hour = 0x10, minute = 0x20, second = 0x40, date = day | month | year,
  short_date = day | month | short_year, time = hour | minute | second, datetime = date | time, short_datetime = short_date | time
}
 Format style. More...

Public Member Functions

 CLongDateFormat (unsigned long nType)
 Constructor.
 CLongDateFormat (const CLongDateFormat &)
 Copy constructor.
 ~CLongDateFormat ()
 Virtual destructor.
virtual TString FormatStl (long val, const CDataObject *pDO) const
 The function converts a non-formatted value of long type to the string which presents the formatted date.
virtual bool ParseStl (const TString &, long &val, const CDataObject *pDO) const
 The function converts the string which presents the formatted date to the non-formatted value of long type.
virtual CString FormatMfc (long val, const CDataObject *pDO) const
 The function converts non-formatted value of long type to the formatted MFC string.
virtual bool ParseMfc (const CString &str, long &val, const CDataObject *pDO) const
 The function converts the formatted MFC string to the non-formatted long-type value.
virtual CFormatClone () const
 Creates a deep copy of a format.
virtual bool IsDate () const
 Indicates whether a format presents a date.
unsigned long GetStyle () const
 Gets a format style which is a combination of CLongDateFormat::Style enumeration.
virtual void Serialize (CSerializer &serializer)
 Serializes a format.

Static Public Member Functions

static long Now ()
 Gets local time, that is a number of seconds elapsed since midnight, January 1, 1970.
static int GetSerializeVertion ()
 Serialization version.
static TString FormatStl (long val, const CDataObject *pDO, unsigned long style, CPreferences::DateType dateType)
 A helper-function, which transforms unformatted value of long type into the formatted string, depending on a format style and a date type.
static bool ParseStl (const TString &text, long &val, const CDataObject *pDO, unsigned long style, CPreferences::DateType dateType)
 A helper-function, which parses the formatted string which presents a date to the value of long type, depending on a format style and a date type.

Detailed Description

Transforms time represented by 32-bit value that is a number of seconds elapsed since midnight, January 1, 1970.

To get the current time, use the static function CLongDateFormat::Now()

Note:
The upper date limit is January 18, 2038
 Format examples:

 CPreferences::SetDateType(CPreferences::DayMonthYear);

 1. CLongDateFormat(CLongDateFormat::date).FormatStl(CLongDateFormat::Now(), 0);
 2. CLongDateFormat(CLongDateFormat::short_date).FormatStl(CLongDateFormat::Now(), 0);
 3. CLongDateFormat(CLongDateFormat::time).FormatStl(CLongDateFormat::Now(), 0);
 4. CLongDateFormat(CLongDateFormat::short_datetime).FormatStl(CLongDateFormat::Now(), 0);

 CPreferences::SetDateType(CPreferences::MonthDayYear);

 5. CLongDateFormat(CLongDateFormat::date).FormatStl(CLongDateFormat::Now(), 0);
 6. CLongDateFormat(CLongDateFormat::short_date).FormatStl(CLongDateFormat::Now(), 0);
 7. CLongDateFormat(CLongDateFormat::time).FormatStl(CLongDateFormat::Now(), 0);
 8. CLongDateFormat(CLongDateFormat::short_datetime).FormatStl(CLongDateFormat::Now(), 0);

 CPreferences::SetDateType(CPreferences::YearMonthDay);
 CPreferences::SetDateSeparator(_T("-"));

 9. CLongDateFormat(CLongDateFormat::date).FormatStl(CLongDateFormat::Now(), 0);
 10. CLongDateFormat(CLongDateFormat::short_date).FormatStl(CLongDateFormat::Now(), 0);
 11. CLongDateFormat(CLongDateFormat::time).FormatStl(CLongDateFormat::Now(), 0);
 12. CLongDateFormat(CLongDateFormat::short_datetime).FormatStl(CLongDateFormat::Now(), 0);


 Output strings:

 1. 16/06/2007
 2. 16/06/07
 3. 13:18:58
 4. 16/06/07 13:18:58

 5. 06/16/2007
 6. 06/16/07
 7. 13:18:58
 8. 06/16/07 13:18:58

 9.  2007-06-16
 10. 07-06-16
 11. 13:18:58
 12. 07-06-16 13:18:58

Member Enumeration Documentation

enum Style

Format style.

Enumerator:
year  yyyy
short_year  yy
month  mm 1..12
day  dd 1..31
hour  hh 0..23
minute  mm 0..59
second  ss 0..59
date  dd/mm/yyyy
short_date  dd/mm/yy
time  hh:mm:ss
datetime  dd/mm/yyyy hh:mm:ss
short_datetime  dd/mm/yy hh:mm:ss


Constructor & Destructor Documentation

CLongDateFormat ( unsigned long  style  ) 

Constructor.

Parameters:
[in] style Combination of CLongDateFormat::Style enumeretion.

CLongDateFormat ( const CLongDateFormat format  ) 

Copy constructor.

Parameters:
[in] format Format to be copied.


Member Function Documentation

TString FormatStl ( long  val,
const CDataObject pDO 
) const [virtual]

The function converts a non-formatted value of long type to the string which presents the formatted date.

Parameters:
[in] val Value of long type to be formatted.
[in] pDO Pointer to CDataObject. This parameter is optional and may be zero.
Returns:
Formatted string.

Reimplemented from CFormat.

bool ParseStl ( const TString &  str,
long &  val,
const CDataObject pDO 
) const [virtual]

The function converts the string which presents the formatted date to the non-formatted value of long type.

Parameters:
[in] str Formatted date.
[in,out] val Value of long type that accepts the result of conversion.
[in] pDO Pointer to CDataObject. This parameter is optional and may be zero.
Returns:
True, if the string has been successfully parsed. Otherwise false.

Reimplemented from CFormat.

CString FormatMfc ( long  val,
const CDataObject pDO 
) const [virtual]

The function converts non-formatted value of long type to the formatted MFC string.

Parameters:
[in] val Non-formatted MFC string to be formatted.
[in] pDO Pointer to CDataObject. This parameter is optional and may be zero.
Returns:
Formatted string that is a result of conversion.

Reimplemented from CFormat.

bool ParseMfc ( const CString &  str,
long &  val,
const CDataObject pDO 
) const [virtual]

The function converts the formatted MFC string to the non-formatted long-type value.

Parameters:
[in] str MFC string to be formatted.
[in,out] val A value of the long type that is a result of the parsing.
[in] pDO Pointer to CDataObject. This parameter is optional and may be zero.
Returns:
True, if the string has been successfully parsed. Otherwise false.

Reimplemented from CFormat.

CFormat * Clone (  )  const [virtual]

Creates a deep copy of a format.

Returns:
Deep copy of a format object.

Implements CFormat.

long Now (  )  [static]

Gets local time, that is a number of seconds elapsed since midnight, January 1, 1970.

Returns:
Local time, that is a number of seconds elapsed since midnight, January 1, 1970.

bool IsDate (  )  const [virtual]

Indicates whether a format presents a date.

Returns:
Always true;

Reimplemented from CFormat.

unsigned long GetStyle (  )  const

Gets a format style which is a combination of CLongDateFormat::Style enumeration.

Returns:
Combination of CLongDateFormat::Style enum

void Serialize ( CSerializer serializer  )  [virtual]

Serializes a format.

Parameters:
[in] serializer Object, into which a format object is serialized.

Reimplemented from CFormat.

TString FormatStl ( long  val,
const CDataObject pDO,
unsigned long  style,
CPreferences::DateType  dateType 
) [static]

A helper-function, which transforms unformatted value of long type into the formatted string, depending on a format style and a date type.

Parameters:
[in] val Unformatted value
[in] pDO Pointer to a data object
[in] style Format style. Combination of CLongDateFormat::Style enumeration
[in] dateType Date type.
Returns:
Formatted string.

bool ParseStl ( const TString &  str,
long &  val,
const CDataObject pDO,
unsigned long  style,
CPreferences::DateType  dateType 
) [static]

A helper-function, which parses the formatted string which presents a date to the value of long type, depending on a format style and a date type.

Parameters:
[in] str Date string
[in,out] val Value to be filled.
[in] pDO Pointer to a data object
[in] style Format style. Combination of CLongDateFormat::Style enumeration
[in] dateType Date type.
Returns:
True if the string has been successfully parsed. Otherwise false.