Commits

Trammell Hudson committed dc815f4

output to stdio looks good

Comments (0)

Files changed (1)

 #include "pebble_app.h"
 #include "pebble_fonts.h"
 
+
 static const char *nums[] = {
 	"",
 	"een",
 	"kwart",
 };
 
+
+static const char *
+min_string(
+	int i
+)
+{
+	return nums[i];
+}
+
+
+static const char *
+hour_string(
+	int h
+)
+{
+	if (h == 0 || h == 24)
+		return "middernacht";
+
+	if (h == 12)
+		return "middag";
+
+	if (h < 12)
+		return nums[h];
+	else
+		return nums[h - 12];
+}
+
+
+static void
+nederlands_format(
+	char * buf,
+	int hour,
+	int min
+)
+{
+	buf[0] = '\0';
+
+	if (min == 0)
+	{
+		// just the hour + uur, except at midnight and noon
+		strcat(buf, hour_string(hour));
+		if (hour != 0 && hour != 12)
+			strcat(buf, "\nuur");
+	} else
+	if (min <= 15)
+	{
+		// over the hour
+		strcat(buf, min_string(min));
+		strcat(buf, "\nover\n");
+		strcat(buf, hour_string(hour));
+	} else
+	if (min < 30)
+	{
+		// over the kwart
+		strcat(buf, min_string(30 - min));
+		strcat(buf, "\nvoor half\n");
+		strcat(buf, hour_string(++hour));
+	} else
+	if (min == 30)
+	{
+		// just the half
+		strcat(buf, "half\n");
+		strcat(buf, hour_string(++hour));
+	} else
+	if (min < 45)
+	{
+		// over the half
+		strcat(buf, min_string(min - 30));
+		strcat(buf, "\nover half\n");
+		strcat(buf, hour_string(++hour));
+	} else
+	if (min == 45)
+	{
+		// just the kwart
+		strcat(buf, "kwart voor\n");
+		strcat(buf, hour_string(++hour));
+	} else
+	if (min < 60)
+	{
+		// over the kwart
+		strcat(buf, min_string(60 - min));
+		strcat(buf, "\nvoor\n");
+		strcat(buf, hour_string(++hour));
+	}
+
+	// add am/pm like phrase
+	if (hour == 0 || hour == 12 || hour == 24)
+	{
+		// nothing to do
+	} else
+	if (hour < 12)
+		strcat(buf, "\ns'ochtends");
+	else
+	if (hour < 18)
+		strcat(buf, "\ns'middags");
+	else
+	if (hour < 21)
+		strcat(buf, "\ns'avonds");
+	else
+		strcat(buf, "\ns'nachts");
+}
+
 PBL_APP_INFO(
 	"Nederlandse",
 	"hudson",
 	(void) ctx;
 	const PblTm * const ptm = event->tick_time;
 
+	int hour = ptm->tm_hour;
+	int min = ptm->tm_min;
+
+	nederlands_format(time_buffer, hour,  min);
+
+/*
 	string_format_time(
 		time_buffer,
 		sizeof(time_buffer),
 		"%H:%M",
 		event->tick_time
 	);
+*/
 	text_layer_set_text(&time_layer, time_buffer);
 }