summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-05-22 21:08:46 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-05-22 21:12:41 (UTC)
commit5db39170b6c979655a0238dcd627e206febed88b (patch) (unidiff)
tree2c79691bde31f9db2861dc76010691e9dbdde1cb
parent3b86b44fc761cfa8b97c44bbbdd63c9fbf1127ed (diff)
downloadcgit-5db39170b6c979655a0238dcd627e206febed88b.zip
cgit-5db39170b6c979655a0238dcd627e206febed88b.tar.gz
cgit-5db39170b6c979655a0238dcd627e206febed88b.tar.bz2
Add cgit_print_age() function
This function can be used to print relative dates, just as in gitweb. Next step will be to actually use the new function. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.css25
-rw-r--r--cgit.h22
-rw-r--r--ui-commit.c4
-rw-r--r--ui-shared.c47
-rw-r--r--ui-summary.c4
5 files changed, 94 insertions, 8 deletions
diff --git a/cgit.css b/cgit.css
index 95c3e40..327eaba 100644
--- a/cgit.css
+++ b/cgit.css
@@ -390 +390,26 @@ table.list td.sublevel-repo {
390} 390}
391
392span.age-mins {
393 font-weight: bold;
394 color: #080;
395}
396
397span.age-hours {
398 color: #080;
399}
400
401span.age-days {
402 color: #040;
403}
404
405span.age-weeks {
406 color: #444;
407}
408
409span.age-months {
410 color: #888;
411}
412
413span.age-years {
414 color: #bbb;
415}
diff --git a/cgit.h b/cgit.h
index 8927236..4da2d3d 100644
--- a/cgit.h
+++ b/cgit.h
@@ -31,2 +31,21 @@
31 31
32
33/*
34 * Dateformats used on misc. pages
35 */
36#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S"
37#define FMT_SHORTDATE "%Y-%m-%d"
38
39
40/*
41 * Limits used for relative dates
42 */
43#define TM_MIN 60
44#define TM_HOUR (TM_MIN * 60)
45#define TM_DAY (TM_HOUR * 24)
46#define TM_WEEK (TM_DAY * 7)
47#define TM_YEAR (TM_DAY * 365)
48#define TM_MONTH (TM_YEAR / 12.0)
49
50
32typedef void (*configfn)(const char *name, const char *value); 51typedef void (*configfn)(const char *name, const char *value);
@@ -183,3 +202,4 @@ extern char *cgit_pageurl(const char *reponame, const char *pagename,
183extern void cgit_print_error(char *msg); 202extern void cgit_print_error(char *msg);
184extern void cgit_print_date(unsigned long secs); 203extern void cgit_print_date(time_t secs, char *format);
204extern void cgit_print_age(time_t t, time_t max_relative, char *format);
185extern void cgit_print_docstart(char *title, struct cacheitem *item); 205extern void cgit_print_docstart(char *title, struct cacheitem *item);
diff --git a/ui-commit.c b/ui-commit.c
index ff1fad3..59eeb1d 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -174,3 +174,3 @@ void cgit_print_commit(const char *hex)
174 html("</td><td class='right'>"); 174 html("</td><td class='right'>");
175 cgit_print_date(info->author_date); 175 cgit_print_date(info->author_date, FMT_LONGDATE);
176 html("</td></tr>\n"); 176 html("</td></tr>\n");
@@ -181,3 +181,3 @@ void cgit_print_commit(const char *hex)
181 html("</td><td class='right'>"); 181 html("</td><td class='right'>");
182 cgit_print_date(info->committer_date); 182 cgit_print_date(info->committer_date, FMT_LONGDATE);
183 html("</td></tr>\n"); 183 html("</td></tr>\n");
diff --git a/ui-shared.c b/ui-shared.c
index c7fbc5e..acc771b 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -90,5 +90,5 @@ char *cgit_currurl()
90 90
91void cgit_print_date(unsigned long secs) 91void cgit_print_date(time_t secs, char *format)
92{ 92{
93 char buf[32]; 93 char buf[64];
94 struct tm *time; 94 struct tm *time;
@@ -96,3 +96,3 @@ void cgit_print_date(unsigned long secs)
96 time = gmtime(&secs); 96 time = gmtime(&secs);
97 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); 97 strftime(buf, sizeof(buf)-1, format, time);
98 html_txt(buf); 98 html_txt(buf);
@@ -100,2 +100,43 @@ void cgit_print_date(unsigned long secs)
100 100
101void cgit_print_age(time_t t, time_t max_relative, char *format)
102{
103 time_t now, secs;
104
105 time(&now);
106 secs = now - t;
107
108 if (secs > max_relative && max_relative >= 0) {
109 cgit_print_date(t, format);
110 return;
111 }
112
113 if (secs < TM_HOUR * 2) {
114 htmlf("<span class='age-mins'>%.0f min.</span>",
115 secs * 1.0 / TM_MIN);
116 return;
117 }
118 if (secs < TM_DAY * 2) {
119 htmlf("<span class='age-hours'>%.0f hours</span>",
120 secs * 1.0 / TM_HOUR);
121 return;
122 }
123 if (secs < TM_WEEK * 2) {
124 htmlf("<span class='age-days'>%.0f days</span>",
125 secs * 1.0 / TM_DAY);
126 return;
127 }
128 if (secs < TM_MONTH * 2) {
129 htmlf("<span class='age-weeks'>%.0f weeks</span>",
130 secs * 1.0 / TM_WEEK);
131 return;
132 }
133 if (secs < TM_YEAR * 2) {
134 htmlf("<span class='age-months'>%.0f months</span>",
135 secs * 1.0 / TM_MONTH);
136 return;
137 }
138 htmlf("<span class='age-years'>%.0f years</span>",
139 secs * 1.0 / TM_YEAR);
140}
141
101void cgit_print_docstart(char *title, struct cacheitem *item) 142void cgit_print_docstart(char *title, struct cacheitem *item)
diff --git a/ui-summary.c b/ui-summary.c
index e7158cc..20394de 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -30,3 +30,3 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
30 html("</td><td>"); 30 html("</td><td>");
31 cgit_print_date(commit->date); 31 cgit_print_date(commit->date, FMT_LONGDATE);
32 html("</td><td>"); 32 html("</td><td>");
@@ -110,3 +110,3 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
110 if (info->tagger_date > 0) 110 if (info->tagger_date > 0)
111 cgit_print_date(info->tagger_date); 111 cgit_print_date(info->tagger_date, FMT_LONGDATE);
112 html("</td><td>"); 112 html("</td><td>");