Colored clock for work hours
Patch status: rejected
Patch by Blaz Balon
Long description:
If enabled it color clock green during working hours (default 7am to 5pm) and week (Mon to Fri). Days and hours can be manualy configured.
To apply this patch, use:
curl http://cr.i3wm.org/patch/98/raw.patch | git am
b/i3status.c
| 18 | 
	  
	  @@ -242,12 +242,22 @@ int main(int argc, char *argv[]) {
   | 
  
| 19 | 
	  
	   | 
  
| 20 | 
	  
	           cfg_opt_t time_opts[] = {
   | 
  
| 21 | 
	  
	                   CFG_STR("format", "%Y-%m-%d %H:%M:%S", CFGF_NONE),
   | 
  
| 22 | 
	  
	  +                CFG_BOOL("workday_color", false, CFGF_NONE),
   | 
  
| 23 | 
	  
	  +                CFG_INT("work_start", 7, CFGF_NONE),
   | 
  
| 24 | 
	  
	  +                CFG_INT("work_end", 17, CFGF_NONE),
   | 
  
| 25 | 
	  
	  +                CFG_STR("workdays", "1,2,3,4,5", CFGF_NONE),
   | 
  
| 26 | 
	  
	  + CFG_CUSTOM_COLOR_OPTS,  | 
  
| 27 | 
	  
	  CFG_END()  | 
  
| 28 | 
	  
	  };  | 
  
| 29 | 
	  
	   | 
  
| 30 | 
	  
	           cfg_opt_t tztime_opts[] = {
   | 
  
| 31 | 
	  
	                   CFG_STR("format", "%Y-%m-%d %H:%M:%S %Z", CFGF_NONE),
   | 
  
| 32 | 
	  
	  +                CFG_BOOL("workday_color", false, CFGF_NONE),
   | 
  
| 33 | 
	  
	  +                CFG_INT("work_start", 7, CFGF_NONE),
   | 
  
| 34 | 
	  
	  +                CFG_INT("work_end", 17, CFGF_NONE),
   | 
  
| 35 | 
	  
	                   CFG_STR("timezone", "", CFGF_NONE),
   | 
  
| 36 | 
	  
	  +                CFG_STR("workdays", "1,2,3,4,5", CFGF_NONE),
   | 
  
| 37 | 
	  
	  + CFG_CUSTOM_COLOR_OPTS,  | 
  
| 38 | 
	  
	  CFG_END()  | 
  
| 39 | 
	  
	  };  | 
  
| 40 | 
	  
	   | 
  
| 41 | 
	  
	  @@ -469,13 +479,13 @@ int main(int argc, char *argv[]) {
   | 
  
| 42 | 
	  
	   | 
  
| 43 | 
	  
	                           CASE_SEC("time") {
   | 
  
| 44 | 
	  
	                                   SEC_OPEN_MAP("time");
   | 
  
| 45 | 
	  
	  - print_time(json_gen, buffer, cfg_getstr(sec, "format"), NULL, tv.tv_sec);  | 
  
| 46 | 
	  
	  + print_time(json_gen, buffer, cfg_getstr(sec, "format"), cfg_getbool(sec, "workday_color"), cfg_getint(sec, "work_start"), cfg_getint(sec, "work_end"), cfg_getstr(sec, "workdays"), NULL, tv.tv_sec);  | 
  
| 47 | 
	  
	  SEC_CLOSE_MAP;  | 
  
| 48 | 
	  
	  }  | 
  
| 49 | 
	  
	   | 
  
| 50 | 
	  
	                           CASE_SEC_TITLE("tztime") {
   | 
  
| 51 | 
	  
	                                   SEC_OPEN_MAP("tztime");
   | 
  
| 52 | 
	  
	  - print_time(json_gen, buffer, cfg_getstr(sec, "format"), cfg_getstr(sec, "timezone"), tv.tv_sec);  | 
  
| 53 | 
	  
	  + print_time(json_gen, buffer, cfg_getstr(sec, "format"), cfg_getbool(sec, "workday_color"), cfg_getint(sec, "work_start"), cfg_getint(sec, "work_end"), cfg_getstr(sec, "workdays"), cfg_getstr(sec, "timezone"), tv.tv_sec);  | 
  
| 54 | 
	  
	  SEC_CLOSE_MAP;  | 
  
| 55 | 
	  
	  }  | 
  
| 56 | 
	  
	   | 
  
b/include/i3status.h
| 61 | 
	  
	  @@ -143,7 +143,7 @@ void set_timezone(const char *tz);  | 
  
| 62 | 
	  
	  void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);  | 
  
| 63 | 
	  
	  void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format);  | 
  
| 64 | 
	  
	  void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity);  | 
  
| 65 | 
	  
	  -void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *tz, time_t t);  | 
  
| 66 | 
	  
	  +void print_time(yajl_gen json_gen, char *buffer, const char *format, bool wcolor, int wstart, int wend, const char *workdays, const char *tz, time_t t);  | 
  
| 67 | 
	  
	  void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t);  | 
  
| 68 | 
	  
	  const char *get_ip_addr();  | 
  
| 69 | 
	  
	  void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);  | 
  
b/man/i3status.man
| 74 | 
	  
	  @@ -276,16 +276,30 @@ Outputs the current time in the local timezone.  | 
  
| 75 | 
	  
	  To use a different timezone, you can set the TZ environment variable,  | 
  
| 76 | 
	  
	  or use the +tztime+ module.  | 
  
| 77 | 
	  
	  See +strftime(3)+ for details on the format string.  | 
  
| 78 | 
	  
	  +Workdays colors can be turn on, resulting into showing date in green for  | 
  
| 79 | 
	  
	  +inside wirking hours, and red for outside working hours. Workdays can be  | 
  
| 80 | 
	  
	  +specified with numbers from 0 to 7, 0 and 7 being Sunday, 1 Monday,...  | 
  
| 81 | 
	  
	   | 
  
| 82 | 
	  
	  *Example order*: +time+  | 
  
| 83 | 
	  
	   | 
  
| 84 | 
	  
	  *Example format*: +%Y-%m-%d %H:%M:%S+  | 
  
| 85 | 
	  
	   | 
  
| 86 | 
	  
	  +*Example workday_color*: +false+  | 
  
| 87 | 
	  
	  +  | 
  
| 88 | 
	  
	  +*Example work_start*: +7+  | 
  
| 89 | 
	  
	  +  | 
  
| 90 | 
	  
	  +*Example work_end*: +17+  | 
  
| 91 | 
	  
	  +  | 
  
| 92 | 
	  
	  +*Example workdays*: +"1,2,3,4,5"+  | 
  
| 93 | 
	  
	  +  | 
  
| 94 | 
	  
	  === TzTime  | 
  
| 95 | 
	  
	   | 
  
| 96 | 
	  
	  Outputs the current time in the given timezone.  | 
  
| 97 | 
	  
	  If no timezone is given, local time will be used.  | 
  
| 98 | 
	  
	  See +strftime(3)+ for details on the format string.  | 
  
| 99 | 
	  
	  +Workdays colors can be turn on, resulting into showing date in green for  | 
  
| 100 | 
	  
	  +inside wirking hours, and red for outside working hours. Workdays can be  | 
  
| 101 | 
	  
	  +specified with numbers from 0 to 7, 0 and 7 being Sunday, 1 Monday,...  | 
  
| 102 | 
	  
	  The system's timezone database is usually installed in +/usr/share/zoneinfo+.  | 
  
| 103 | 
	  
	  Files below that path make for valid timezone strings, e.g. for  | 
  
| 104 | 
	  
	  +/usr/share/zoneinfo/Europe/Berlin+ you can set timezone to +Europe/Berlin+  | 
  
| 105 | 
	  
	  @@ -295,8 +309,16 @@ in the +tztime+ module.  | 
  
| 106 | 
	  
	   | 
  
| 107 | 
	  
	  *Example format*: +%Y-%m-%d %H:%M:%S %Z+  | 
  
| 108 | 
	  
	   | 
  
| 109 | 
	  
	  +*Example workday_color*: +false+  | 
  
| 110 | 
	  
	  +  | 
  
| 111 | 
	  
	  +*Example work_start*: +7+  | 
  
| 112 | 
	  
	  +  | 
  
| 113 | 
	  
	  +*Example work_end*: +17+  | 
  
| 114 | 
	  
	  +  | 
  
| 115 | 
	  
	  *Example timezone*: +Europe/Berlin+  | 
  
| 116 | 
	  
	   | 
  
| 117 | 
	  
	  +*Example workdays*: +"1,2,3,4,5"+  | 
  
| 118 | 
	  
	  +  | 
  
| 119 | 
	  
	  === DDate  | 
  
| 120 | 
	  
	   | 
  
| 121 | 
	  
	  Outputs the current discordian date in user-specified format. See +ddate(1)+ for  | 
  
b/src/print_time.c
| 126 | 
	  
	  @@ -33,14 +33,32 @@ void set_timezone(const char *tz) {
   | 
  
| 127 | 
	  
	  }  | 
  
| 128 | 
	  
	  }  | 
  
| 129 | 
	  
	   | 
  
| 130 | 
	  
	  -void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *tz, time_t t) {
   | 
  
| 131 | 
	  
	  +void print_time(yajl_gen json_gen, char *buffer, const char *format, bool wcolor, int wstart, int wend, const char *wdays, const char *tz, time_t t) {
   | 
  
| 132 | 
	  
	  char *outwalk = buffer;  | 
  
| 133 | 
	  
	  + char *dayday;  | 
  
| 134 | 
	  
	  struct tm tm;  | 
  
| 135 | 
	  
	  + char tt[24];  | 
  
| 136 | 
	  
	  + char dd[10];  | 
  
| 137 | 
	  
	   | 
  
| 138 | 
	  
	  /* Convert time and format output. */  | 
  
| 139 | 
	  
	  set_timezone(tz);  | 
  
| 140 | 
	  
	  localtime_r(&t, &tm);  | 
  
| 141 | 
	  
	  outwalk += strftime(outwalk, 4095, format, &tm);  | 
  
| 142 | 
	  
	  *outwalk = '\0';  | 
  
| 143 | 
	  
	  +  | 
  
| 144 | 
	  
	  + /* Colors for working hours */  | 
  
| 145 | 
	  
	  +        if (wcolor) {
   | 
  
| 146 | 
	  
	  + strftime(tt, 24, "%H", &tm);  | 
  
| 147 | 
	  
	  + strftime(dd, 10, "%w", &tm);  | 
  
| 148 | 
	  
	  + dayday = strstr(wdays, dd);  | 
  
| 149 | 
	  
	  + int hours = atoi(tt);  | 
  
| 150 | 
	  
	  +          if (hours >= wstart && hours <= wend && dayday != NULL) {
   | 
  
| 151 | 
	  
	  +            START_COLOR("color_good");
   | 
  
| 152 | 
	  
	  +          } else {
   | 
  
| 153 | 
	  
	  +            START_COLOR("color_bad");
   | 
  
| 154 | 
	  
	  + }  | 
  
| 155 | 
	  
	  + }  | 
  
| 156 | 
	  
	  +  | 
  
| 157 | 
	  
	  + END_COLOR;  | 
  
| 158 | 
	  
	  OUTPUT_FULL_TEXT(buffer);  | 
  
| 159 | 
	  
	  }  |