We use the DD-MM-YYYY HH:mm:ss
date and time format API between frontend and backend.
However, there are cases that backend gets only the date since time wasn’t selected at the frontend side.
The GET
call parameter will look like this:
startTime=16-11-2021
At the backend side, we use the COleDateTime
class in order to parse the date and time. The problem is that the time in the case above is initialized to 00:00:00
when actually no time is sent. I need a way to distinguish between no time sent and midnight as the actual time is significant in our system and there is a big difference between no time sent and midnight.
It seems that the ParseDateTime
function expects to get a flag in its second parameter VAR_TIMEVALUEONLY
to Ignore the date portion during parsing.
So for that, I need to implement a parse function in order to know if I got the time or not where it is expected that the ParseDateTime
function would be set as an undefined time like -1
when no time is sent.
Is there a way to distinguish between no time to midnight in COleDateTime
class? If not, maybe you have another way I can use public libraries like <chrono>
which could solve my problem?
COleDateTime
has a function GetStatus()
that is able to tell if the object has no value at all. In all other cases, it's valid. This means that there is no distinction between "no time" and midnight. The type seems designed to encode an absolute point in time. Date-only or time-only hijack this encoding with 0 components. No-date can easily be spotted, since numbering of date start at 0100-01-01 and cannot be confused with 0000-00-00. Nothing supports the spotting of no-time.
If you need a better handling of time uncertainty, this format is not suitable as it is. Unfortunately, most other common alternatives have similar issues. <chrono>
would offer an equivalent feature which is the time_point
. It also supports dates and time of day separately, with lots of conversion. Boost has similar limitations, as does DateTime
(unless you'd misuse the milliseconds, which would look weird).
As you get the time from the front end in DD-MM-YYYY HH:mm:ss
or DD-MM-YYYY
format, it's pretty easy for you to parse if there is or not time. The simplest would probably to create a DateTimeWrapper
to wrap COleDateTime
together with isTimeAccurate
indicator.