diff options
author | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2010-02-22 19:55:05 +0100 |
---|---|---|
committer | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2010-02-22 19:55:05 +0100 |
commit | 74dd6f509092e294baf7650b6c1a0fd1cde4be4a (patch) | |
tree | 1e1383a77bda5c54c34fd2f5388df518cbba58a6 | |
parent | 5676ca7738e2d53191493a3761cd11f14e83dbed (diff) |
sort numerical and than alphanumerical
-rw-r--r-- | timepollhead.rb | 12 | ||||
-rw-r--r-- | timestring.rb | 4 |
2 files changed, 13 insertions, 3 deletions
diff --git a/timepollhead.rb b/timepollhead.rb index b5abb72..c0e4547 100644 --- a/timepollhead.rb +++ b/timepollhead.rb @@ -204,7 +204,7 @@ END end times = concrete_times - realtimes = times.collect{|t| Time.parse(t) if t =~ /\d\d:\d\d/}.compact + realtimes = times.collect{|t| Time.parse(t) if t =~ /^\d\d:\d\d$/}.compact [9,16].each{|i| realtimes << Time.parse("#{i.to_s.rjust(2,"0")}:00")} ["firsttime","lasttime"].each{|t| @@ -311,7 +311,15 @@ END ret += timenavi(EARLIER,revision) (@firsttime..@lasttime).each{|i| times << "#{i.to_s.rjust(2,"0")}:00" } - times.flatten.compact.uniq.sort.each{|time| + times.flatten.compact.uniq.sort{|a,b| + if a =~ /^\d\d:\d\d$/ && !(b =~ /^\d\d:\d\d$/) + -1 + elsif !(a =~ /^\d\d:\d\d$/) && b =~ /^\d\d:\d\d$/ + 1 + else + a.to_i == b.to_i ? a <=> b : a.to_i <=> b.to_i + end + }.each{|time| ret +="<tr>\n<td class='navigation'>#{time}</td>" days.each{|day| timestamp = TimeString.new(day,time) diff --git a/timestring.rb b/timestring.rb index 78168bd..387aba3 100644 --- a/timestring.rb +++ b/timestring.rb @@ -56,7 +56,9 @@ class TimeString end def <=>(other) if self.date == other.date - if self.time.class == String && other.time.class == String || self.time.class == Time && other.time.class == Time + if self.time.class == String && other.time.class == String + self.time.to_i == other.time.to_i ? self.time <=> other.time : self.time.to_i <=> other.time.to_i + elsif self.time.class == Time && other.time.class == Time self.time <=> other.time elsif self.time.class == NilClass && other.time.class == NilClass 0 |