add meridiem for 12h format

reverse-branch
martin 18 years ago
parent 227c4f1ff8
commit f8f44a555c
  1. 22
      clock.c

@ -57,14 +57,14 @@ static const long number[10][LGNUM] = {
{1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1} /* 9 */ {1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1} /* 9 */
}; };
char *meridiem;
int SCHANGE = 19;
int hour[2]; int hour[2];
int min[2]; int min[2];
int sec[2]; int sec[2];
int defx=1; int defx=1;
int defy=1; int defy=1;
int bg = COLOR_BLACK; int bg = COLOR_BLACK;
int SCHANGE = 19;
bool enable_sec = 0; bool enable_sec = 0;
bool enable_tw = 0; bool enable_tw = 0;
struct tm *tm; struct tm *tm;
@ -83,7 +83,7 @@ start(void) {
refresh(); refresh();
if (use_default_colors() == OK); if (use_default_colors() == OK);
bg = -1; bg = -1;
init_pair(1,COLOR_GREEN, COLOR_GREEN); init_pair(1,COLOR_BLACK, COLOR_GREEN);
init_pair(2, bg, bg); init_pair(2, bg, bg);
curs_set(0); curs_set(0);
} }
@ -151,14 +151,18 @@ arrange_clock(int h1, int h2,
print_number(h2, defx, defy + 7); print_number(h2, defx, defy + 7);
attron(COLOR_PAIR(1)); attron(COLOR_PAIR(1));
mvaddstr(defx + 1, defy + 15," ");
move(defx + 1, defy + 15);
printw("%s",meridiem);
mvaddstr(defx + 3, defy + 15," "); mvaddstr(defx + 3, defy + 15," ");
attroff(COLOR_PAIR(1)); attroff(COLOR_PAIR(1));
print_number(m1, defx, defy + 19); print_number(m1, defx, defy + 19);
print_number(m2, defx, defy + 26); print_number(m2, defx, defy + 26);
if(enable_sec){ if(enable_sec){
attron(COLOR_PAIR(1)); attron(COLOR_PAIR(1));
mvaddstr(defx + 1, defy + 34," "); mvaddstr(defx + 1, defy + 34," ");
mvaddstr(defx + 3, defy + 34," "); mvaddstr(defx + 3, defy + 34," ");
@ -178,7 +182,6 @@ void
check_key(void) { check_key(void) {
int c; int c;
c = getch(); c = getch();
switch(c) { switch(c) {
case KEY_UP: case KEY_UP:
case 'k': case 'k':
@ -222,13 +225,20 @@ check_key(void) {
void void
get_time(void) { get_time(void) {
int i;
int ihour; int ihour;
tm = localtime(&lt); tm = localtime(&lt);
lt = time(NULL); lt = time(NULL);
ihour = tm->tm_hour; ihour = tm->tm_hour;
if (enable_tw && ihour > 12) {
meridiem = "PM";
} else if (enable_tw && ihour < 12) {
meridiem = "AM";
} else {
meridiem = " ";
}
ihour = (enable_tw && ihour > 12) ? ihour - 12 : ihour; ihour = (enable_tw && ihour > 12) ? ihour - 12 : ihour;
ihour = (enable_tw && !ihour) ? 12 : ihour; ihour = (enable_tw && !ihour) ? 12 : ihour;

Loading…
Cancel
Save