Bug 11704 - rsyncstats sorts dates wrong
Summary: rsyncstats sorts dates wrong
Status: CLOSED FIXED
Alias: None
Product: rsync
Classification: Unclassified
Component: core (show other bugs)
Version: 3.1.2
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Wayne Davison
QA Contact: Rsync QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-29 20:45 UTC by Grischa Zengel
Modified: 2016-02-01 15:05 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Grischa Zengel 2016-01-29 20:45:13 UTC
rsyncstats show statistics with wrong date order:

TOTALS FOR SUMMARY PERIOD 2016/01/01 TO ***2016/01/21***

Daily Transmission Statistics

                 Number Of    Number of   Percent Of  Percent Of
     Date        Files Sent   MB  Sent    Files Sent  Bytes Sent
---------------  ----------  -----------  ----------  ----------
2016/01/01              570  10375.32866      0.12        0.69
2016/01/16              655  7317.213854      0.13        0.48
2016/01/24              495  5681.975908      0.10        0.38
2016/01/27            41125  101154.5519      8.46        6.70
2016/01/04            17075  62525.35909      3.51        4.14
2016/01/05            19870  65251.58114      4.09        4.32
2016/01/15            21620  65535.48440      4.45        4.34
2016/01/17              395  3713.043026      0.08        0.25
2016/01/02              360  4160.903625      0.07        0.28
2016/01/07            21565  84046.16057      4.43        5.57
2016/01/13            23450  75723.10462      4.82        5.02
2016/01/25            22150  89712.77994      4.55        5.94
2016/01/10              495  6874.872217      0.10        0.46
2016/01/26            34415  72377.36720      7.08        4.80
2016/01/03              600  7965.899901      0.12        0.53
2016/01/23             2140  10545.03610      0.44        0.70
2016/01/09              680  11327.12449      0.14        0.75
2016/01/28            22580  78863.89039      4.64        5.23
2016/01/08            20820  62567.35772      4.28        4.15
2016/01/11            29490  87068.98149      6.06        5.77
2016/01/12            25095  72422.45863      5.16        4.80
2016/01/22            30926  83395.29467      6.36        5.53
2016/01/06             2505  15280.35709      0.52        1.01
2016/01/18            30435  91414.26186      6.26        6.06
2016/01/19            36935  77847.47815      7.59        5.16
2016/01/20            27596  84001.79939      5.67        5.57
2016/01/14            25050  78379.55794      5.15        5.19
2016/01/21            27289  93731.06716      5.61        6.21

The problem is this:
sub datecompare {
    $a gt $b;
}

This function should return -1,0,1 and not true/false.

It should be:
sub datecompare {
    $a cmp $b;
}

because this is default sort rule you can change:
@dates = sort datecompare keys %xferbytes;
to
@dates = sort keys %xferbytes;

foreach $date (sort datecompare keys %xferbytes) {
to
foreach $date (sort keys %xferbytes) {
Comment 1 Wayne Davison 2016-01-31 22:42:55 UTC
Wow, that bug has been around since 1998. I fixed it in git, as well as optimizing the other sort function to use "cmp" instead of both "lt" and "gt".

Thanks for the report...
Comment 2 Grischa Zengel 2016-02-01 15:05:03 UTC
It looks good.

Thanks.