// default, they will not change if they had valid values or will
// default to Today() otherwise)
const wxChar *ParseFormat(const wxChar *date,
- const wxChar *format = wxDefaultDateTimeFormat,
+ const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime);
// parse a string containing the date/time in "free" format, this
// function will try to make an educated guess at the string contents
// argument corresponds to the preferred date and time representation
// for the current locale) and returns the string containing the
// resulting text representation
- wxString Format(const wxChar *format = wxDefaultDateTimeFormat,
+ wxString Format(const wxString& format = wxDefaultDateTimeFormat,
const TimeZone& tz = Local) const;
// preferred date representation for the current locale
wxString FormatDate() const { return Format(_T("%x")); }
// resulting text representation. Notice that only some of format
// specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
// minutes and seconds make sense, but not "PM/AM" string for example.
- wxString Format(const wxChar *format = wxDefaultTimeSpanFormat) const;
+ wxString Format(const wxString& format = wxDefaultTimeSpanFormat) const;
// implementation
// ------------------------------------------------------------------------
#ifdef HAVE_STRFTIME
// this function is a wrapper around strftime(3) adding error checking
-static wxString CallStrftime(const wxChar *format, const tm* tm)
+static wxString CallStrftime(const wxString& format, const tm* tm)
{
wxChar buf[4096];
// Create temp wxString here to work around mingw/cygwin bug 1046059
// wxDateTime to/from text representations
// ----------------------------------------------------------------------------
-wxString wxDateTime::Format(const wxChar *format, const TimeZone& tz) const
+wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
{
- wxCHECK_MSG( format, wxEmptyString, _T("NULL format in wxDateTime::Format") );
+ wxCHECK_MSG( !format.empty(), wxEmptyString,
+ _T("NULL format in wxDateTime::Format") );
// we have to use our own implementation if the date is out of range of
// strftime() or if we use non standard specificators
tmTimeOnly.tm_isdst = 0; // no DST, we adjust for tz ourselves
wxString tmp, res, fmt;
- for ( const wxChar *p = format; *p; p++ )
+ for ( wxString::const_iterator p = format.begin(); p != format.end(); ++p )
{
if ( *p != _T('%') )
{
}
// set the default format
- switch ( *++p )
+ switch ( (*++p).GetValue() )
{
case _T('Y'): // year has 4 digits
fmt = _T("%04d");
restart = false;
// start of the format specification
- switch ( *p )
+ switch ( (*p).GetValue() )
{
case _T('a'): // a weekday name
case _T('A'):
#endif // __WINDOWS__
const wxChar *wxDateTime::ParseFormat(const wxChar *date,
- const wxChar *format,
+ const wxString& format,
const wxDateTime& dateDef)
{
- wxCHECK_MSG( date && format, (wxChar *)NULL,
+ wxCHECK_MSG( date && !format.empty(), (wxChar *)NULL,
_T("NULL pointer in wxDateTime::ParseFormat()") );
wxString str;
int year = 0;
const wxChar *input = date;
- for ( const wxChar *fmt = format; *fmt; fmt++ )
+ for ( wxString::const_iterator fmt = format.begin(); fmt != format.end(); ++fmt )
{
if ( *fmt != _T('%') )
{
// the default widths for the various fields
if ( !width )
{
- switch ( *fmt )
+ switch ( (*fmt).GetValue() )
{
case _T('Y'): // year has 4 digits
width = 4;
}
// then the format itself
- switch ( *fmt )
+ switch ( (*fmt).GetValue() )
{
case _T('a'): // a weekday name
case _T('A'):
// And, to be better than MFC :-), we also have
// %E number of wEeks
// %l milliseconds (000 - 999)
-wxString wxTimeSpan::Format(const wxChar *format) const
+wxString wxTimeSpan::Format(const wxString& format) const
{
- wxCHECK_MSG( format, wxEmptyString, _T("NULL format in wxTimeSpan::Format") );
+ wxCHECK_MSG( !format.empty(), wxEmptyString,
+ _T("NULL format in wxTimeSpan::Format") );
wxString str;
- str.Alloc(wxStrlen(format));
+ str.Alloc(format.length());
// Suppose we have wxTimeSpan ts(1 /* hour */, 2 /* min */, 3 /* sec */)
//
// we remember the most important unit found so far
TimeSpanPart partBiggest = Part_MSec;
- for ( const wxChar *pch = format; *pch; pch++ )
+ for ( wxString::const_iterator pch = format.begin(); pch != format.end(); ++pch )
{
wxChar ch = *pch;