*/
#include "h/mh.h"
+#include "dtime.h"
+#include "error.h"
#include "h/icalendar.h"
-#include <h/fmt_scan.h>
+#include "datetime.h"
+#include "h/fmt_scan.h"
#include "h/tws.h"
#include "h/utils.h"
#include "unquote.h"
*/
static int
parse_datetime (const char *datetime, const char *zone, bool dst,
- struct tws *tws) {
+ struct tws *tws)
+{
char utc_indicator;
bool form_1;
int items_matched;
}
tzdesc_t
-load_timezones (const contentline *clines) {
+load_timezones (const contentline *clines)
+{
tzdesc_t timezones = NULL, timezone = NULL;
bool in_vtimezone, in_standard, in_daylight;
tzparams *params = NULL;
}
void
-free_timezones (tzdesc_t timezone) {
+free_timezones (tzdesc_t timezone)
+{
tzdesc_t next;
for ( ; timezone; timezone = next) {
* Given a recurrence rule and year, calculate its time in seconds
* from 01 January UTC of the year.
*/
-time_t
+static time_t
rrule_clock (const char *rrule, const char *starttime, const char *zone,
- unsigned int year) {
+ unsigned int year)
+{
time_t clock = 0;
if (nmh_strcasestr (rrule, "FREQ=YEARLY;INTERVAL=1") ||
int specific_day = 1; /* BYDAY integer (prefix) */
char buf[32];
int day;
+ int end_of_week;
if ((cp = nmh_strcasestr (rrule, "BYDAY="))) {
cp += 6;
/* BYDAY integers must be ASCII. */
- if (*cp == '+') { ++cp; } /* +n specific day; don't support '-' */
- else if (*cp == '-') { goto fail; }
+ if (*cp == '+') { ++cp; } /* +n specific day */
+ else if (*cp == '-') { ++cp; specific_day = -1; }
- if (isdigit ((unsigned char) *cp)) { specific_day = *cp++ - 0x30; }
+ if (isdigit ((unsigned char) *cp)) { specific_day *= *cp++ - 0x30; }
if (! strncasecmp (cp, "SU", 2)) { wday = 0; }
else if (! strncasecmp (cp, "MO", 2)) { wday = 1; }
month = atoi (cp + 8);
}
- for (day = 1; day <= 7; ++day) {
+ end_of_week = specific_day > 0 ? 7 * specific_day :
+ dmlastday(year, month) + 7 * (1 + specific_day);
+ for (day = end_of_week - 6; day <= end_of_week; ++day) {
/* E.g, 11-01-2014 02:00:00-0400 */
snprintf (buf, sizeof buf, "%02d-%02d-%04u %.2s:%.2s:%.2s%s",
- month, day + 7 * (specific_day-1), year,
- starttime, starttime + 2, starttime + 4,
- zone ? zone : "0000");
+ month, day, year, starttime, starttime + 2,
+ starttime + 4, zone ? zone : "0000");
if ((tws = dparsetime (buf))) {
if (! (tws->tw_flags & (TW_SEXP|TW_SIMP))) { set_dotw (tws); }
}
}
- if (day <= 7) {
+ if (day <= end_of_week) {
clock = tws->tw_clock;
}
}
-fail:
if (clock == 0) {
inform("Unsupported RRULE format: %s, assume local timezone, continuing...",
- rrule);
+ rrule);
}
return clock;
}
char *
-format_datetime (tzdesc_t timezones, const contentline *node) {
+format_datetime (tzdesc_t timezones, const contentline *node)
+{
param_list *p;
char *dt_timezone = NULL;
int dst = 0;