|
|
|
@@ -1,98 +1,96 @@ |
1 | #include <string-list.h> |
| |
2 | |
| |
3 | #include "cgit.h" |
1 | #include "cgit.h" |
4 | #include "html.h" |
2 | #include "html.h" |
5 | #include "ui-shared.h" |
3 | #include "ui-shared.h" |
6 | #include "ui-stats.h" |
4 | #include "ui-stats.h" |
7 | |
5 | |
8 | #ifdef NO_C99_FORMAT |
6 | #ifdef NO_C99_FORMAT |
9 | #define SZ_FMT "%u" |
7 | #define SZ_FMT "%u" |
10 | #else |
8 | #else |
11 | #define SZ_FMT "%zu" |
9 | #define SZ_FMT "%zu" |
12 | #endif |
10 | #endif |
13 | |
11 | |
14 | #define MONTHS 6 |
12 | #define MONTHS 6 |
15 | |
13 | |
16 | struct authorstat { |
14 | struct authorstat { |
17 | long total; |
15 | long total; |
18 | struct string_list list; |
16 | struct string_list list; |
19 | }; |
17 | }; |
20 | |
18 | |
21 | #define DAY_SECS (60 * 60 * 24) |
19 | #define DAY_SECS (60 * 60 * 24) |
22 | #define WEEK_SECS (DAY_SECS * 7) |
20 | #define WEEK_SECS (DAY_SECS * 7) |
23 | |
21 | |
24 | static void trunc_week(struct tm *tm) |
22 | static void trunc_week(struct tm *tm) |
25 | { |
23 | { |
26 | time_t t = timegm(tm); |
24 | time_t t = timegm(tm); |
27 | t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; |
25 | t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; |
28 | gmtime_r(&t, tm); |
26 | gmtime_r(&t, tm); |
29 | } |
27 | } |
30 | |
28 | |
31 | static void dec_week(struct tm *tm) |
29 | static void dec_week(struct tm *tm) |
32 | { |
30 | { |
33 | time_t t = timegm(tm); |
31 | time_t t = timegm(tm); |
34 | t -= WEEK_SECS; |
32 | t -= WEEK_SECS; |
35 | gmtime_r(&t, tm); |
33 | gmtime_r(&t, tm); |
36 | } |
34 | } |
37 | |
35 | |
38 | static void inc_week(struct tm *tm) |
36 | static void inc_week(struct tm *tm) |
39 | { |
37 | { |
40 | time_t t = timegm(tm); |
38 | time_t t = timegm(tm); |
41 | t += WEEK_SECS; |
39 | t += WEEK_SECS; |
42 | gmtime_r(&t, tm); |
40 | gmtime_r(&t, tm); |
43 | } |
41 | } |
44 | |
42 | |
45 | static char *pretty_week(struct tm *tm) |
43 | static char *pretty_week(struct tm *tm) |
46 | { |
44 | { |
47 | static char buf[10]; |
45 | static char buf[10]; |
48 | |
46 | |
49 | strftime(buf, sizeof(buf), "W%V %G", tm); |
47 | strftime(buf, sizeof(buf), "W%V %G", tm); |
50 | return buf; |
48 | return buf; |
51 | } |
49 | } |
52 | |
50 | |
53 | static void trunc_month(struct tm *tm) |
51 | static void trunc_month(struct tm *tm) |
54 | { |
52 | { |
55 | tm->tm_mday = 1; |
53 | tm->tm_mday = 1; |
56 | } |
54 | } |
57 | |
55 | |
58 | static void dec_month(struct tm *tm) |
56 | static void dec_month(struct tm *tm) |
59 | { |
57 | { |
60 | tm->tm_mon--; |
58 | tm->tm_mon--; |
61 | if (tm->tm_mon < 0) { |
59 | if (tm->tm_mon < 0) { |
62 | tm->tm_year--; |
60 | tm->tm_year--; |
63 | tm->tm_mon = 11; |
61 | tm->tm_mon = 11; |
64 | } |
62 | } |
65 | } |
63 | } |
66 | |
64 | |
67 | static void inc_month(struct tm *tm) |
65 | static void inc_month(struct tm *tm) |
68 | { |
66 | { |
69 | tm->tm_mon++; |
67 | tm->tm_mon++; |
70 | if (tm->tm_mon > 11) { |
68 | if (tm->tm_mon > 11) { |
71 | tm->tm_year++; |
69 | tm->tm_year++; |
72 | tm->tm_mon = 0; |
70 | tm->tm_mon = 0; |
73 | } |
71 | } |
74 | } |
72 | } |
75 | |
73 | |
76 | static char *pretty_month(struct tm *tm) |
74 | static char *pretty_month(struct tm *tm) |
77 | { |
75 | { |
78 | static const char *months[] = { |
76 | static const char *months[] = { |
79 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
77 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
80 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
78 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
81 | }; |
79 | }; |
82 | return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900); |
80 | return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900); |
83 | } |
81 | } |
84 | |
82 | |
85 | static void trunc_quarter(struct tm *tm) |
83 | static void trunc_quarter(struct tm *tm) |
86 | { |
84 | { |
87 | trunc_month(tm); |
85 | trunc_month(tm); |
88 | while(tm->tm_mon % 3 != 0) |
86 | while(tm->tm_mon % 3 != 0) |
89 | dec_month(tm); |
87 | dec_month(tm); |
90 | } |
88 | } |
91 | |
89 | |
92 | static void dec_quarter(struct tm *tm) |
90 | static void dec_quarter(struct tm *tm) |
93 | { |
91 | { |
94 | dec_month(tm); |
92 | dec_month(tm); |
95 | dec_month(tm); |
93 | dec_month(tm); |
96 | dec_month(tm); |
94 | dec_month(tm); |
97 | } |
95 | } |
98 | |
96 | |
|