Package: ical2html / 2.1-3

1001_week_starts_monday.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Description: Ad option to start week on Monday
Author: Carles Pina i Estany <carles@pina.cat>
Bug-Debian: http://bugs.debian.org/679194
Last-Update: 2015-10-24
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/ical2html.c
+++ b/ical2html.c
@@ -45,6 +45,7 @@
   -l, --location               include event's location in that <PRE>\n\
   -f, --footer=TEXT            add text at the bottom of the HTML file\n\
   -z, --timezone=country/city  adjust for this timezone (default: GMT)\n\
+  -m, --monday                 draw Monday as first week day (Sunday is default)\n\
   start is of the form yyyymmdd, e.g., 20020927 (27 Sep 2002)\n\
   duration is in days or weeks, e.g., P5W (5 weeks) or P60D (60 days)\n\
   file is an iCalendar file, default is standard input\n"
@@ -59,10 +60,11 @@
   {"location", 0, 0, 'l'},
   {"footer", 1, 0, 'f'},
   {"timezone", 1, 0, 'z'},
+  {"monday", 0, 0, 'm'},
   {0, 0, 0, 0}
 };
 
-#define OPTIONS "dlp:P:c:C:f:z:"
+#define OPTIONS "dlmp:P:c:C:f:z:"
 
 static const char *months[] = {"", "January", "February", "March", "April",
 			       "May", "June", "July", "August", "September",
@@ -268,13 +270,17 @@
 static void print_calendar(const struct icaltimetype start,
 			   const struct icaldurationtype duration,
 			   const int nrevents, const event_item events[],
-			   const int do_description, const int do_location)
+			   const int do_description, const int do_location,
+			   const int starts_on_monday)
 {
   struct icaltimetype day;
   struct icaltimetype end;
   char s[9];
   int y, m, d, w;
-  int i = 0;			/* Loop over events */
+  int i = 0;	/* Loop over events */
+  int skip;	/* How many days to skip of that week until 1st */
+  int lastDay;
+  if (starts_on_monday) lastDay = 2; else lastDay = 1;
 
   end = icaltime_add(start, duration);
 
@@ -290,14 +296,26 @@
       day = icaltime_from_string(s);
 
       printf("<table><caption>%s %d</caption>\n", months[m], y);
-      printf("<thead><tr><th>Sunday<th>Monday<th>Tuesday<th>Wednesday");
-      printf("<th>Thursday<th>Friday<th>Saturday\n");
+      printf("<thead><tr>");
+      if (starts_on_monday) {
+         printf("<th>Monday<th>Tuesday<th>Wednesday");
+         printf("<th>Thursday<th>Friday<th>Saturday<th>Sunday\n");
+      }
+      else {
+         printf("<th>Sunday<th>Monday<th>Tuesday<th>Wednesday");
+         printf("<th>Thursday<th>Friday<th>Saturday\n");
+
+      }
       printf("<tbody>\n");
 
       w = icaltime_day_of_week(day);
-      if (w != 1) {		/* Empty cells until 1st of month */
-	printf("<tr>\n");
-	for (; w > 1; w--) printf("<td class=skip>\n");
+      if (starts_on_monday)
+         if (w == 1) skip = 6; else skip = w-2;
+      else
+         skip = w-1;
+
+      if (skip != 0) {
+         for(; skip > 0; skip--) printf("<td class=skip>\n");
       }
 
       /* Skip events before this day (can only occur at very start) */
@@ -310,7 +328,11 @@
 	sprintf(s, "%04d%02d%02d", y, m, d);
 	day = icaltime_from_string(s);
 	w = icaltime_day_of_week(day);
-	if (w == 1) printf("<tr>\n");
+	if (w == lastDay)
+	{
+		printf("<tr>\n");
+	}
+
 	printf("<td><p class=date>%d\n\n", d);
 
 	/* Print all events on this day (the events are sorted) */
@@ -449,6 +471,7 @@
   char c;
   int dummy1, dummy2, dummy3, do_description = 0, do_location = 0;
   icaltimezone *tz;
+  int starts_on_monday = 0;
 
   /* We handle errors ourselves */
   icalerror_errors_are_fatal = 0;
@@ -470,6 +493,7 @@
     case 'l': do_location = 1; break;
     case 'f': footer = strdup(optarg); break;
     case 'z': tz = icaltimezone_get_builtin_timezone(optarg); break;
+    case 'm': starts_on_monday = 1; break;
     default: fatal(ERR_USAGE, USAGE);
     }
   }
@@ -509,7 +533,7 @@
 
   /* Print the sorted results */
   print_header(periodstart, duration);
-  print_calendar(periodstart, duration, nrevents, events, do_description, do_location);
+  print_calendar(periodstart, duration, nrevents, events, do_description, do_location, starts_on_monday);
   print_footer(footer);
 
   /* Clean up */