fix hour being negative

This commit is contained in:
Andrew Pamment 2018-02-27 20:14:01 +10:00
parent 27de6593b1
commit 4aa2c4f6c1
2 changed files with 15 additions and 5 deletions

View File

@ -66,7 +66,7 @@ void blog_display() {
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
char c;
int hour;
int j;
int lines = 2;
s_printf("\e[2J\e[1;1H");
@ -98,8 +98,12 @@ void blog_display() {
s_printf("\r\n\r\n");
lines = 0;
}
s_printf(get_string(284), (thetime.tm_hour - 12 == 0 ? 12 : thetime.tm_hour - 12), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900);
if (thetime.tm_hour >= 12) {
hour = thetime.tm_hour - 12;
} else {
hour = thetime.tm_hour;
}
s_printf(get_string(284), (hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900);
lines++;
if (lines == 22 && tolower(c) != 'c') {

View File

@ -18,7 +18,8 @@ char *www_blog() {
int blog_entry_count = 0;
int i, j;
struct tm thetime;
int hour;
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
@ -48,7 +49,12 @@ char *www_blog() {
} else {
for (i=0;i<blog_entry_count;i++) {
localtime_r(&blog_entries[i]->date, &thetime);
sprintf(buffer, "<div class=\"blog-header\"><div class=\"blog-title\"><h3>%s</h3></div><div class=\"blog-date\">%d:%02d%s %s, %s %d %d</div><div class=\"blog-author\">by %s</div></div>", blog_entries[i]->subject,(thetime.tm_hour - 12 == 0 ? 12 : thetime.tm_hour - 12), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900, blog_entries[i]->author);
if (thetime.tm_hour >= 12) {
hour = thetime.tm_hour - 12;
} else {
hour = thetime.tm_hour;
}
sprintf(buffer, "<div class=\"blog-header\"><div class=\"blog-title\"><h3>%s</h3></div><div class=\"blog-date\">%d:%02d%s %s, %s %d %d</div><div class=\"blog-author\">by %s</div></div>", blog_entries[i]->subject,(hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900, blog_entries[i]->author);
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);