Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » SqlArray sorting (Wrong sort with dates?)
SqlArray sorting [message #59524] |
Mon, 16 January 2023 23:20 |
jimlef
Messages: 90 Registered: September 2020 Location: US
|
Member |
|
|
I have the following code:
arrCount.Appending(true).AllSorting();
It's made so simple LOL...
Sorting number columns, words etc looks good, but when I sort a date column as in the picture:

You can see the dates are not sorting correctly (this is in month day year format)?
Dates are stored in the db as unix epoch since 1970, and format correctly when displayed according to my local settings using the simple DateIntConvert. All I can think of is that the array control is treating them as strings, rather than dates, but I don't know how to correct this? A custom function that breaks them up, and sorts the segments? Or modifing the dateintconvert's output? I'm so confused 
arrCount.ColumnAt(0).SetConvert ( DateIntConvert() );
...
struct DateIntConvertCls : ConvertDate {
virtual Value Format(const Value& q) const;
virtual Value Scan(const Value& text) const;
virtual int Filter(int chr) const;
};
// From sql borrow.cpp example
Value DateIntConvertCls::Format(const Value& q) const
{
return IsNull(q) ? String() : ::Format(Date( 1970, 1, 1) + (int)q);
}
// Modified from UPP source
Value DateIntConvertCls::Scan(const Value& text) const
{
const char *s;
Date date;
String txt = text;
if(txt.IsEmpty()) return (Date) Null;
s = StrToDate(date, txt);
if(s)
for(;;) {
if(IsDigit(*s))
break;
if(*s == '\0')
return date - Date(1970, 1, 1);
s++;
}
return ErrorValue(t_("Invalid date !"));
}
int DateIntConvertCls::Filter(int chr) const
{
return CharFilterDate(chr);
}
Convert& DateIntConvert()
{
return Single<DateIntConvertCls>();
}
Anyone have an idea as to how to get this sorted out? 
Thank you!
Jim
-
Attachment: datesort.png
(Size: 8.71KB, Downloaded 181 times)
|
|
|
Goto Forum:
Current Time: Tue Apr 29 00:48:52 CEST 2025
Total time taken to generate the page: 0.02490 seconds
|