Re: [greenstone-users] the trouble with DateList

From jens wille
DateThu, 17 Feb 2005 17:57:25 +0100
Subject Re: [greenstone-users] the trouble with DateList
In-Reply-To (4213AD0C-2080201-cs-waikato-ac-nz)
hi katherine!

Katherine Don wrote:
> If you want to send me your code, I'll put it in, otherwise it
> will be added to our TODO list.
basically, i use a custom sort routine which behaves normally unless
$date and $sort_other are separated by "::" in which case it sorts
reversely by $date and normally by $sort_other.

sub my_sort {
my $p = (ref $a eq 'ARRAY') ? $a->[1] : $a;
my $q = (ref $b eq 'ARRAY') ? $b->[1] : $b;

$p =~ m{^(d+)::};
my $r = $1 || '';
$q =~ m{^(d+)::};
my $s = $1 || '';

$s cmp $r
||
$p cmp $q;
}

strangely enough DateList now only works together with one of
-nogroup or -bymonth (i have no idea why this is so - otherwise the
displayed DateList is just empty).
[UPDATE: it doesn't seem to work with the original DateList.pm
either... %-(]

besides, i don't know how to sort the HLists reversely (2004 2005 ->
2005 2004; January February -> February January).

it's pretty ugly, too, but i hope it's helpful anyway ;-)
please find attached my complete diff against 2.52 DateList.pm (not
the cvs version).

best regards

jens


<<attachment>>
Type: text/plain
Filename: DateList.pm.diff

67,70c67
< { 'name' => "newestfirst",
< 'desc' => "{DateList.newestfirst}",
< 'type' => "flag",
< 'reqd' => "no" }
---
>
102d98
< q^newestfirst^, $self->{'newestfirst'},
144,145c140,141
< # clearly separate $date and $sort_other in order to sort newest first
< $self->{'list'}->{$doc_OID} = $date . ($self->{'newestfirst'} ? '::' : '') . $sort_other;
---
>
> $self->{'list'}->{$doc_OID} = "$date$sort_other";
149,161d144
< sub my_sort {
< my $p = (ref $a eq 'ARRAY') ? $a->[1] : $a;
< my $q = (ref $b eq 'ARRAY') ? $b->[1] : $b;
<
< $p =~ m{^(d+)::};
< my $r = $1 || '';
< $q =~ m{^(d+)::};
< my $s = $1 || '';
<
< $s cmp $r
< ||
< $p cmp $q;
< }
166,167c149
< #my @classlist = sort {$self->{'list'}->{$a} cmp $self->{'list'}->{$b};} keys %{$self->{'list'}};
< my @classlist = map { $_->[0] } sort my_sort map { [$_, $self->{'list'}->{$_}] } keys %{$self->{'list'}};
---
> my @classlist = sort {$self->{'list'}->{$a} cmp $self->{'list'}->{$b};} keys %{$self->{'list'}};