Replacement for KDateTime
David Jarvie
djarvie at kde.org
Mon Aug 3 20:07:44 BST 2015
On Monday 03 Aug 2015 19:49:52 Thomas Lübking wrote:
> On Sonntag, 2. August 2015 20:32:43 CEST, David Jarvie wrote:
>
> > Having a date-only attribute in KDateTime is very useful
> > because it allows both date-time and date-only values to be
> > encapsulated in a single class. This avoids having to be able to
> > pass either a QDate or QDateTime or to have a separate flag
> > everywhere this is used, and it allows date-time values to be
> > compared to date-only values using class methods.
>
> Sorry, but I don't follow here.
>
> QDateTime *has* a QDate AND a QTime member.
> They can independently be null/invalid.
>
> => With a QDateTime with invalid QTime member, you *have* a QDate-only QDateTime, agreed?
>
> The "problem" would be that
>
> if (kdt.isValid()) {
> if (kdt.isDateOnly())
> foo();
> else
> bar();
> }
>
> turns into:
>
> if (qdt.date().isValid()) {
> if (!qdt.time().isValid())
> foo();
> else
> bar();
> }
>
> right?
> Doesn't look that horrible.
>
> -
>
> Now, it however seems to me you'd like to have a flag "butIgnoreTheTime" that hints for some client code behavior, ie. you actually want to carry valid date and time in the object, but in addition have a flag _in_the_object_ to effectively pass a parameter to a function to do something different with this object.
>
> Is this actually correct?
>
> => That frankly sounds like a bool trap on steroids.
>
> You've an object flying around that may or not have set this flag for some™ ominous reason in the past for some™ function call and different modules might have different requirements for this flag for different reasons... ewwww.
As I understand it, a QDateTime is invalid if either the date or time component is invalid. People would usually expect that if QDateTime::isValid() returns false, the object must be invalid. So a date-only value in which only the date was valid would make the whole object invalid, which is misleading and would almost certainly lead to mistakes.
--
David Jarvie.
KDE developer.
KAlarm author -- http://www.astrojar.org.uk/kalarm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20150803/1db65469/attachment.htm>
More information about the kde-core-devel
mailing list