Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » SqlArray sorting (Wrong sort with dates?)
SqlArray sorting [message #59524] Mon, 16 January 2023 23:20
jimlef is currently offline  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:

index.php?t=getfile&id=6757&private=0

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 Wink

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? Wink

Thank you!

Jim
  • Attachment: datesort.png
    (Size: 8.71KB, Downloaded 108 times)
 
Read Message
Previous Topic: strange layout problem
Next Topic: ArrayCtrl vertical grid line dislocated
Goto Forum:
  


Current Time: Fri Apr 19 06:11:40 CEST 2024

Total time taken to generate the page: 0.03219 seconds