Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help about COleDateTime::ParseDateTime

529 views
Skip to first unread message

Ronnie

unread,
Nov 7, 2007, 12:55:00 AM11/7/07
to
As you know, COleDateTime::ParseDateTime can parse a time string to date/time
value, and supports variety of time formats.
My problem is, if I input a time string "2007/11/01 13:00am" which is not a
acceptable time format because the hour value(13) must not over 12, but
COleDateTime::ParseDateTime returns date/time value "2007/11/01 13:00"
successfully. So how can i detect this unacceptable time format with
different locale settings, or any other ALT/MFC Class can be used to detect
this kind of unacceptable format? thank you.

Frank Hickman

unread,
Nov 7, 2007, 1:30:58 AM11/7/07
to
"Ronnie" <Ron...@discussions.microsoft.com> wrote in message
news:595C1509-089C-4532...@microsoft.com...

In this particular case, I would inform the user of the parsing error
because there is no way the system should be able to return a date/time
string in such a format. Even if the user is using 24 hour time format and
adds the am/pm, as in this case, the am/pm would return as pm for 1300.

--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.


Ronnie

unread,
Nov 7, 2007, 1:51:00 AM11/7/07
to
Thanks, I would like to inform the user of parsing error too,
but how can i find such an error when parsing the time string?
COleDateTime::ParseDateTime returns successfully indeed.
if checking string on myself, it's difficult to find the error because of
different AM/PM symbols with different locale settings.

GT

unread,
Nov 7, 2007, 10:14:24 AM11/7/07
to
"Ronnie" <Ron...@discussions.microsoft.com> wrote in message
news:595C1509-089C-4532...@microsoft.com...

13:00am is more than 'not an acceptable time format', its simpler than
that - its not a valid time at all !

Can you just do some simple check yourself after getting the string from the
user. If the string ends in 'am' or 'pm', then the number before it can't be
higher than 1200 or 12:00. If the last digit is a number, then it needs to
be in the range 00:00 or 0000 to 23:59 or 2359.


Victor

unread,
Nov 7, 2007, 2:30:13 PM11/7/07
to
Please, read the documentation about COleDateTime::ParseDateTime in MSDN!
It states that "... If the string could not be converted to a date/time
value or if there was a numerical overflow, the status of this COleDateTime
object is invalid."
So check the COleDateTime::GetStatus to be COleDateTime::valid.

Moreover, You could also use
try / catch( CMemoryException ) / catch( COleException )
blocks to handle all possible exceptions.

Victor

"Ronnie" <Ron...@discussions.microsoft.com> wrote in message

news:D50178EA-2A33-41A5...@microsoft.com...

Ronnie

unread,
Nov 7, 2007, 9:35:02 PM11/7/07
to
Thanks for your advice, I do want to check it myself after getting the string.

But it's difficult to check am/pm symbols in 12-hour format for different
locale settings. The am/pm symbols can be "am/pm" or "上午/下午" in china, and in
other locale settings, these symbols may be different.

So, if we want to parse the string, we must known all 12-hour format
representation in different locales. It may be a little difficult.

Ronnie

unread,
Nov 8, 2007, 3:32:01 AM11/8/07
to
Indeed, COleDateTime::ParseDateTime convert such an invalid format
successfully without any exceptions, the returned status is valid!

GT

unread,
Nov 8, 2007, 6:11:30 AM11/8/07
to
"Ronnie" <Ron...@discussions.microsoft.com> wrote in message
news:DE26B614-97EC-42E4...@microsoft.com...

> Thanks for your advice, I do want to check it myself after getting the
> string.
>
> But it's difficult to check am/pm symbols in 12-hour format for different
> locale settings. The am/pm symbols can be "am/pm" or "??/??" in china, and
> in
> other locale settings, these symbols may be different.
>
> So, if we want to parse the string, we must known all 12-hour format
> representation in different locales. It may be a little difficult.

Can't you just ignore the am/pm signals - no matter what the characters
actually are, there are only 12 hours in a morning and afternoon!. If you
start at the end of the string and work forwards, you will reach a number
which is the time. If the number is right at the end of the string, then it
is 24 hours, if the number is not the last thing in the string, then it is
12 hours and you can validate the number accordingly.


0 new messages