RE: Sorting GtkListStore date column
- From: "Freddie Unpenstein" <fredderic excite com>
- To: gtk-app-devel-list gnome org
- Cc:
- Subject: RE: Sorting GtkListStore date column
- Date: Sun, 12 Mar 2006 05:28:44 -0500 (EST)
I'm fairly new to GTK programming, and I'm helping out on an open
source GTK-based project (gcvs, part of the cvsgui project.) We
have a GtkListStore with a column containing date. The column is
specified as G_TYPE_STRING. When sorted, it does an alphanumeric
sort, so in English it puts all the Fridays together first,
followed by all the Mondays, Saturdays, Sundays, etc.Obviously, I
want to sort this in date sequence. How do I accomplish this?
Without knowing the exact format of the text, it's hard to help. For example, if there's a day and month in
there, it's probably best to ignore the day of week, however if there's only one week worth of data, then you
probably DO want to sort on day of week. Based on those assumptions... Do it the same way you'd do it in
any other case.
If the text is guaranteed to be cleanly formatted (eg. it's generated by another part of the program), then
you just read as much of the string as you need to identify the day of week; eg. switch on the second letter,
then use the first to differentiate the sun/tue case. However you do it, just rip the day of the week down
to a number, 0-7, and sort on that.
Of course, a far better way, is to store the date in a binary format (time_t goes well), even if you have to
convert it at load time, and generate the string representation in a custom data function (fills in the
STRING column as-needed from time_t data). This is vastly quicker to sort on, and will also sort on time
information if it's available, even if it's not being displayed.
Fredderic
_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]