Review Request: Add new KDate class to simplify date localization

David Jarvie djarvie at kde.org
Tue Oct 26 14:36:26 BST 2010



> On 2010-10-26 13:19:16, Parker Coates wrote:
> > "I have named it KDate, but there is the possibility people may get confused and think that KDateTime also localizes datetime's, but that is not the case.  If people think this will be a problem KLocalizedDate is an alternative if more awkward name."
> > 
> > My personal feeling is that "KLocalizedDate" is a better name for a few reasons.
> >  * "KLocalizedDate" explicitly says what this class does that QDate doesn't.
> >  * Although there are exceptions, a common assumption is that if Qt has a QSomething class, KDE's KSomething class probably inherits from it.
> >  * The typical advice I see given is that if there's KSomething class and a QSomething class, KDE code should use the KSomething class. It's my understanding that your intention is not for all KDE code to switch to KDate, only code which displays dates to users, right?
> >  * As you mention, this class is completely unrelated to KDateTime so it'd be nice to avoid any potential confusion. (By the arguments above, I guess KDateTime should have been named KTZDateTime or something similar.)

I agree with Parker.


- David


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://svn.reviewboard.kde.org/r/5692/#review8367
-----------------------------------------------------------


On 2010-10-25 20:54:08, John Layt wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://svn.reviewboard.kde.org/r/5692/
> -----------------------------------------------------------
> 
> (Updated 2010-10-25 20:54:08)
> 
> 
> Review request for kdelibs.
> 
> 
> Summary
> -------
> 
> The KCalendarSystem api for localizing dates is awkward, inconvenient, unintuitive, and long-winded, causing many mistakes to be made or localization to be ignored altogether.  This change adds a new KDate class designed to make localizing dates as easy as using QDate.
> 
> Some QDate code may look like:
> 
>     QDate myDate( aYear, aMonth, aDay );
>     int doy = myDate.dayOfYear();
> 
> The KDE localized date code looks something like:
> 
>     QDate myDate;
>     KGlobal::locale()->calendar()->setDate( myDate, aYear, aMonth, aDay );
>     int doy = KGlobal::locale()->calendar()->dayOfYear( myDate );
> 
> The localized KDate code would look like:
> 
>     KDate myDate( aYear, aMonth, aDay );
>     int doy = myDate.dayOfYear();
> 
> Much easier.
> 
> KDate is a thin wrapper around KCalendarSystem and QDate, with a near identical api to QDate and as such can be used as a drop-in replacement with very few changes.  Some deprecated or unnecessary KCalendarSystem methods have not been included, but these can still be accessed via the calendar() methods.  Some new convenience methods have also been added such as setCurrentDate() and addYearsOn().
> 
> Some methods have QDate overloads for convenience, and the assignment and comparison operators partially work with QDate on the rhs.  If anyone knows how to make it work with QDate on the lhs, or any other QDate compatibility ideas, I'm all ears.
> 
> For now I only intend this to be used as a convenience class by apps internally and not to be used in kdelibs api as I don't see much advantage in that, but I may do so if the demand for convenience is there.
> 
> I have named it KDate, but there is the possibility people may get confused and think that KDateTime also localizes datetime's, but that is not the case.  If people think this will be a problem KLocalizedDate is an alternative if more awkward name.
> 
> 
> Diffs
> -----
> 
>   /trunk/KDE/kdelibs/kdecore/CMakeLists.txt 1189756 
>   /trunk/KDE/kdelibs/kdecore/date/kdate.h PRE-CREATION 
>   /trunk/KDE/kdelibs/kdecore/date/kdate.cpp PRE-CREATION 
>   /trunk/KDE/kdelibs/kdecore/tests/kcalendartest.h 1189756 
>   /trunk/KDE/kdelibs/kdecore/tests/kcalendartest.cpp 1189756 
> 
> Diff: http://svn.reviewboard.kde.org/r/5692/diff
> 
> 
> Testing
> -------
> 
> Full unit tests included.
> 
> 
> Thanks,
> 
> John
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20101026/d3b63137/attachment.htm>


More information about the kde-core-devel mailing list