+/*
+ * Given the current office hours configuration it creates the custom
+ * HTML
+ */
+
+static ngx_str_t create_output_html(ngx_http_office_hours_conf_t * conf)
+{
+
+ char * output_buffer;
+ time_t now;
+ ngx_str_t output_html;
+ ngx_uint_t i, seconds_of_day;
+ ngx_uint_t ** parsed_office_hours;
+
+
+ output_buffer = malloc(1024 * sizeof(char));
+ parsed_office_hours = parse_office_hours(conf->office_hours);
+ now = ngx_time();
+ seconds_of_day = get_seconds_of_day(now);
+
+ sprintf(output_buffer, "%s", (char *) HEAD_HTML.data);
+
+ for (i = 0; i < 7; ++i) {
+ sprintf(output_buffer + strlen(output_buffer), "%s", format_hours(parsed_office_hours[i], (char *) DAY_NAMES[i]));
+ }
+
+ sprintf(output_buffer + strlen(output_buffer), "%s", (char *) MIDDLE_HTML.data);
+ sprintf(output_buffer + strlen(output_buffer), "%s", format_seconds(seconds_of_day));
+ sprintf(output_buffer + strlen(output_buffer), "%s", (char *) FOOT_HTML.data);
+
+ output_html.data = (unsigned char *) output_buffer;
+ output_html.len = strlen(output_buffer);
+
+ return output_html;
+}
+
+/*
+ * Given a tuple of seconds and a day name, outputs an HTML
+ * string containing the formatted data as a list item
+ */
+
+static char * format_hours(ngx_uint_t * hours, char * day)
+{
+
+ char * output_html;
+
+ output_html = malloc(64 * sizeof(char));
+ if (hours[0] == hours[1]) {
+ sprintf(output_html, "<li><strong>%s</strong>: CLOSED</li>",
+ day
+ );
+ return output_html;
+ }
+
+ sprintf(output_html, "<li><strong>%s</strong>: %s - %s</li>",
+ day,
+ (char *) format_seconds(hours[0]),
+ (char *) format_seconds(hours[1])
+ );
+
+ return output_html;
+}
+
+/*
+ * Given seconds of the day, it returns a string showing
+ * HH:MM in 24 hour format
+ */
+
+static char * format_seconds(ngx_uint_t seconds)
+{
+
+ char * output_html;
+ unsigned int hours, minutes;
+
+ output_html = malloc(6 * sizeof(char));
+
+ hours = seconds / 60 / 60;
+ minutes = (seconds / 60) % 60;
+
+ sprintf(output_html, "%s:%s",
+ left_pad(hours),
+ left_pad(minutes)
+ );
+
+ return output_html;
+}
+
+/*
+ * Returns a number as a string adding 0 if < 10
+ */
+
+static char * left_pad(unsigned int number)
+{
+
+ char * output_string;
+ char * padding;
+
+ padding = "";
+ output_string = malloc(3 * sizeof(char));
+
+ if (number < 10) {
+ padding = "0";
+ }
+
+ sprintf(output_string, "%s%u", padding, number);
+
+ return output_string;
+}
+