Configurable time format.

This commit is contained in:
Felicity Tarnell 2014-03-08 13:49:19 +00:00
parent 2af789884e
commit 0479ee0f89
7 changed files with 63 additions and 29 deletions

View file

@ -481,7 +481,7 @@ int s = 0;
return; return;
} }
ct = maketime(s); ct = maketime(s, time_format);
swprintf(pr, wsizeof(pr), L"Merge %d marked entries [%ls] into current entry?", swprintf(pr, wsizeof(pr), L"Merge %d marked entries [%ls] into current entry?",
nmarked, ct); nmarked, ct);
free(ct); free(ct);

30
str.c
View file

@ -174,6 +174,9 @@ time_t i = 0, r = 0;
r += i; r += i;
i = 0; i = 0;
continue; continue;
case L' ':
continue;
} }
if (wcschr(L"0123456789", *tm) == NULL) if (wcschr(L"0123456789", *tm) == NULL)
@ -187,29 +190,46 @@ time_t i = 0, r = 0;
} }
wchar_t * wchar_t *
maketime(tm) maketime(tm, fmt)
time_t tm; time_t tm;
{ {
wchar_t res[64] = {}; wchar_t res[64] = {};
wchar_t t[16]; wchar_t t[16];
if (fmt == TIME_HMS) {
int h, m, s;
time_to_hms(tm, h, m, s);
swprintf(t, wsizeof(t), L"%02d:%02d:%02d",
h, m, s);
return wcsdup(t);
}
if (fmt == TIME_HM) {
int h, m, s;
time_to_hms(tm, h, m, s);
swprintf(t, wsizeof(t), L"%02d:%02d", h, m);
return wcsdup(t);
}
if (tm >= (60 * 60)) { if (tm >= (60 * 60)) {
swprintf(t, wsizeof(t), L"%dh", tm / (60 * 60)); swprintf(t, wsizeof(t), L"%2dh ", tm / (60 * 60));
wcslcat(res, t, wsizeof(res)); wcslcat(res, t, wsizeof(res));
tm %= (60 * 60); tm %= (60 * 60);
} }
if (tm >= 60) { if (tm >= 60) {
swprintf(t, wsizeof(t), L"%dm", tm / 60); swprintf(t, wsizeof(t), L"%2dm ", tm / 60);
wcslcat(res, t, wsizeof(res)); wcslcat(res, t, wsizeof(res));
tm %= 60; tm %= 60;
} }
if (tm) { if (fmt == TIME_AHMS && tm) {
swprintf(t, wsizeof(t), L"%ds", tm); swprintf(t, wsizeof(t), L"%2ds ", tm);
wcslcat(res, t, wsizeof(res)); wcslcat(res, t, wsizeof(res));
} }
res[wcslen(res) - 1] = '\0';
return wcsdup(res); return wcsdup(res);
} }

7
str.h
View file

@ -15,10 +15,15 @@
#include "wide.h" #include "wide.h"
#define TIME_HMS 0 /* HH:MM:SS */
#define TIME_HM 1 /* HH:MM */
#define TIME_AHMS 2 /* 1h10m37s */
#define TIME_AHM 3 /* 1h10w */
size_t tokenise (const wchar_t *, wchar_t ***result); size_t tokenise (const wchar_t *, wchar_t ***result);
void tokfree (wchar_t ***); void tokfree (wchar_t ***);
time_t parsetime (const wchar_t *); time_t parsetime (const wchar_t *);
wchar_t *maketime (time_t); wchar_t *maketime (time_t, int format);
wchar_t *escstr (const wchar_t *); wchar_t *escstr (const wchar_t *);
#endif /* !TTS_STR_H */ #endif /* !TTS_STR_H */

2
tts.c
View file

@ -92,6 +92,7 @@ int mark_advance = 1;
int bill_advance = 0; int bill_advance = 0;
int bill_increment = 0; int bill_increment = 0;
wchar_t *auto_nonbillable; wchar_t *auto_nonbillable;
int time_format;
variable_t variables[] = { variable_t variables[] = {
{ L"delete_advance", VTYPE_BOOL, &delete_advance }, { L"delete_advance", VTYPE_BOOL, &delete_advance },
@ -100,6 +101,7 @@ variable_t variables[] = {
{ L"show_billable", VTYPE_BOOL, &show_billable }, { L"show_billable", VTYPE_BOOL, &show_billable },
{ L"auto_non_billable", VTYPE_STRING, &auto_nonbillable }, { L"auto_non_billable", VTYPE_STRING, &auto_nonbillable },
{ L"bill_increment", VTYPE_INT, &bill_increment }, { L"bill_increment", VTYPE_INT, &bill_increment },
{ L"time_format", VTYPE_INT, &time_format },
{ } { }
}; };

2
tts.h
View file

@ -73,4 +73,6 @@ size_t wcslcat(wchar_t *s1, const wchar_t *s2, size_t n);
size_t wcslcpy(wchar_t *s1, const wchar_t *s2, size_t n); size_t wcslcpy(wchar_t *s1, const wchar_t *s2, size_t n);
#endif #endif
extern int time_format;
#endif /* !TTS_H */ #endif /* !TTS_H */

View file

@ -11,6 +11,15 @@
#set mark_advance 1 #set mark_advance 1
#set delete_advance 1 #set delete_advance 1
# Select the time format used in the display; value can be from 0 to 3.
#
# 0: 10:03:37 (default)
# 1: 10:03
# 2: 10h 3m 37s
# 3: 10h 3m
#
#set time_format 0
#### Billing options #### Billing options
# #
# If set, show billable time in each daily summary. # If set, show billable time in each daily summary.

40
ui.c
View file

@ -119,13 +119,12 @@ wchar_t title[64];
waddwstr(titwin, title); waddwstr(titwin, title);
if (itime > 0) { if (itime > 0) {
wchar_t str[128]; wchar_t str[128], *tm;
int h, m, s;
time_t passed = time(NULL) - itime; time_t passed = time(NULL) - itime;
time_to_hms(passed, h, m, s); tm = maketime(passed, time_format);
swprintf(str, wsizeof(str), L" *** MARK INTERRUPT: %02d:%02d:%02d ***", swprintf(str, wsizeof(str), L" *** MARK INTERRUPT: %ls ***", tm);
h, m, s); free(tm);
wattron(titwin, A_BOLD); wattron(titwin, A_BOLD);
waddwstr(titwin, str); waddwstr(titwin, str);
@ -431,9 +430,9 @@ chtype oldbg;
for (; en; en = TTS_TAILQ_NEXT(en, en_entries)) { for (; en; en = TTS_TAILQ_NEXT(en, en_entries)) {
time_t n; time_t n;
int h, s, m;
wchar_t flags[10], stime[16], *p; wchar_t flags[10], stime[16], *p;
attr_t attrs = 0; attr_t attrs = 0;
wchar_t *etime;
if (!showinv && en->en_flags.efl_invoiced) if (!showinv && en->en_flags.efl_invoiced)
continue; continue;
@ -443,11 +442,11 @@ chtype oldbg;
if (lastday != entry_day(en)) { if (lastday != entry_day(en)) {
struct tm *lt; struct tm *lt;
wchar_t lbl[128]; wchar_t lbl[128];
wchar_t *itime = maketime(entry_time_for_day(entry_day(en), 1, 0)), wchar_t *itime = maketime(entry_time_for_day(entry_day(en), 1, 0), time_format),
*ntime = maketime(entry_time_for_day(entry_day(en), 0, 0)), *ntime = maketime(entry_time_for_day(entry_day(en), 0, 0), time_format),
*btime = maketime(entry_time_for_day(entry_day(en), 2, bill_increment)), *btime = maketime(entry_time_for_day(entry_day(en), 2, bill_increment), time_format),
*ttime = maketime(entry_time_for_day(entry_day(en), 1, 0) + *ttime = maketime(entry_time_for_day(entry_day(en), 1, 0) +
entry_time_for_day(entry_day(en), 0, 0)); entry_time_for_day(entry_day(en), 0, 0), time_format);
wchar_t hdrtext[256]; wchar_t hdrtext[256];
int n = 0; int n = 0;
@ -473,33 +472,33 @@ chtype oldbg;
if (*itime) { if (*itime) {
wcslcat(hdrtext, L"I:", wsizeof(hdrtext)); wcslcat(hdrtext, L"I:", wsizeof(hdrtext));
wcslcat(hdrtext, itime, wsizeof(hdrtext)); wcslcat(hdrtext, itime, wsizeof(hdrtext));
free(itime);
n++; n++;
} }
free(itime);
if (*ntime) { if (*ntime) {
if (n++) if (n++)
wcslcat(hdrtext, L" ", wsizeof(hdrtext)); wcslcat(hdrtext, L" ", wsizeof(hdrtext));
wcslcat(hdrtext, L"N:", wsizeof(hdrtext)); wcslcat(hdrtext, L"N:", wsizeof(hdrtext));
wcslcat(hdrtext, ntime, wsizeof(hdrtext)); wcslcat(hdrtext, ntime, wsizeof(hdrtext));
free(ntime);
} }
free(ntime);
if (*ttime) { if (*ttime) {
if (n++) if (n++)
wcslcat(hdrtext, L" ", wsizeof(hdrtext)); wcslcat(hdrtext, L" ", wsizeof(hdrtext));
wcslcat(hdrtext, L"T:", wsizeof(hdrtext)); wcslcat(hdrtext, L"T:", wsizeof(hdrtext));
wcslcat(hdrtext, ttime, wsizeof(hdrtext)); wcslcat(hdrtext, ttime, wsizeof(hdrtext));
free(ttime);
} }
free(ttime);
if (*btime) { if (*btime) {
if (n++) if (n++)
wcslcat(hdrtext, L" ", wsizeof(hdrtext)); wcslcat(hdrtext, L" ", wsizeof(hdrtext));
wcslcat(hdrtext, L"B:", wsizeof(hdrtext)); wcslcat(hdrtext, L"B:", wsizeof(hdrtext));
wcslcat(hdrtext, btime, wsizeof(hdrtext)); wcslcat(hdrtext, btime, wsizeof(hdrtext));
free(btime);
} }
free(btime);
wcslcat(hdrtext, L"]", wsizeof(hdrtext)); wcslcat(hdrtext, L"]", wsizeof(hdrtext));
@ -558,14 +557,11 @@ chtype oldbg;
n = en->en_secs; n = en->en_secs;
if (en->en_started) if (en->en_started)
n += time(NULL) - en->en_started; n += time(NULL) - en->en_started;
h = n / (60 * 60);
n %= (60 * 60);
m = n / 60;
n %= 60;
s = n;
swprintf(stime, wsizeof(stime), L"%02d:%02d:%02d%c ", etime = maketime(n, time_format);
h, m, s, (itime && (en == running)) ? '*' : ' '); swprintf(stime, wsizeof(stime), L"%8ls%c ",
*etime ? etime : L"0m", (itime && (en == running)) ? '*' : ' ');
free(etime);
waddwstr(listwin, stime); waddwstr(listwin, stime);
memset(flags, 0, sizeof(flags)); memset(flags, 0, sizeof(flags));
@ -627,7 +623,7 @@ wchar_t *defstr = NULL;
wchar_t *tstr; wchar_t *tstr;
time_t ret; time_t ret;
defstr = maketime(def); defstr = maketime(def, TIME_AHMS);
if ((tstr = prompt(pr, defstr, NULL)) == NULL) { if ((tstr = prompt(pr, defstr, NULL)) == NULL) {
free(defstr); free(defstr);