/* Datetime.c generated by valac 0.56.19, the Vala compiler
 * generated from Datetime.vala, do not modify */

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include "planify.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
#include <json-glib/json-glib.h>
#include <chrono.h>
#include <gee.h>
#include <glib-object.h>
#include <libical-glib/libical-glib.h>
#include <libecal/libecal.h>
#include <gobject/gvaluecollector.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_time_zone_unref0(var) ((var == NULL) ? NULL : (var = (g_time_zone_unref (var), NULL)))
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
typedef struct _UtilsParamSpecDatetime UtilsParamSpecDatetime;
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _UtilsParamSpecDatetime {
	GParamSpec parent_instance;
};

static gpointer utils_datetime_parent_class = NULL;
static GRegex* utils_datetime__iso_due_regex;
static GRegex* utils_datetime__iso_due_regex = NULL;

static gboolean utils_datetime_check_by_day (const gchar* day,
                                      GArray* day_array);
static gboolean utils_datetime_is_iso_due_date (const gchar* date);
static void utils_datetime_finalize (UtilsDatetime * obj);
static GType utils_datetime_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

GDateTime*
utils_datetime_get_todoist_datetime (const gchar* date)
{
	gboolean _tmp0_ = FALSE;
	GDateTime* datetime = NULL;
	gint _tmp1_;
	gint _tmp2_;
	GDateTime* result;
	if (g_strcmp0 (date, "") == 0) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = date == NULL;
	}
	if (_tmp0_) {
		result = NULL;
		return result;
	}
	datetime = NULL;
	_tmp1_ = strlen (date);
	_tmp2_ = _tmp1_;
	if (_tmp2_ <= 10) {
		gchar** _date = NULL;
		gchar** _tmp3_;
		gchar** _tmp4_;
		gint _date_length1;
		gint __date_size_;
		gchar** _tmp5_;
		gint _tmp5__length1;
		const gchar* _tmp6_;
		gchar** _tmp7_;
		gint _tmp7__length1;
		const gchar* _tmp8_;
		gchar** _tmp9_;
		gint _tmp9__length1;
		const gchar* _tmp10_;
		GDateTime* _tmp11_;
		_tmp4_ = _tmp3_ = g_strsplit (date, "-", 0);
		_date = _tmp4_;
		_date_length1 = _vala_array_length (_tmp3_);
		__date_size_ = _date_length1;
		_tmp5_ = _date;
		_tmp5__length1 = _date_length1;
		_tmp6_ = _tmp5_[0];
		_tmp7_ = _date;
		_tmp7__length1 = _date_length1;
		_tmp8_ = _tmp7_[1];
		_tmp9_ = _date;
		_tmp9__length1 = _date_length1;
		_tmp10_ = _tmp9_[2];
		_tmp11_ = g_date_time_new_local (atoi (_tmp6_), atoi (_tmp8_), atoi (_tmp10_), 0, 0, (gdouble) 0);
		_g_date_time_unref0 (datetime);
		datetime = _tmp11_;
		_date = (_vala_array_free (_date, _date_length1, (GDestroyNotify) g_free), NULL);
	} else {
		gchar** _date = NULL;
		gchar** _tmp12_;
		gchar** _tmp13_;
		gchar** _tmp14_;
		gint _tmp14__length1;
		const gchar* _tmp15_;
		gchar** _tmp16_;
		gchar** _tmp17_;
		gchar** _tmp18_;
		gint _tmp18__length1;
		gint _date_length1;
		gint __date_size_;
		gchar** _time = NULL;
		gchar** _tmp19_;
		gchar** _tmp20_;
		gchar** _tmp21_;
		gint _tmp21__length1;
		const gchar* _tmp22_;
		gchar** _tmp23_;
		gchar** _tmp24_;
		gchar** _tmp25_;
		gint _tmp25__length1;
		gint _time_length1;
		gint __time_size_;
		gchar** _tmp26_;
		gint _tmp26__length1;
		const gchar* _tmp27_;
		gchar** _tmp28_;
		gint _tmp28__length1;
		const gchar* _tmp29_;
		gchar** _tmp30_;
		gint _tmp30__length1;
		const gchar* _tmp31_;
		gchar** _tmp32_;
		gint _tmp32__length1;
		const gchar* _tmp33_;
		gchar** _tmp34_;
		gint _tmp34__length1;
		const gchar* _tmp35_;
		gchar** _tmp36_;
		gint _tmp36__length1;
		const gchar* _tmp37_;
		GDateTime* _tmp38_;
		_tmp13_ = _tmp12_ = g_strsplit (date, "T", 0);
		_tmp14_ = _tmp13_;
		_tmp14__length1 = _vala_array_length (_tmp12_);
		_tmp15_ = _tmp14_[0];
		_tmp17_ = _tmp16_ = g_strsplit (_tmp15_, "-", 0);
		_tmp18_ = _tmp17_;
		_tmp18__length1 = _vala_array_length (_tmp16_);
		_tmp14_ = (_vala_array_free (_tmp14_, _tmp14__length1, (GDestroyNotify) g_free), NULL);
		_date = _tmp18_;
		_date_length1 = _tmp18__length1;
		__date_size_ = _date_length1;
		_tmp20_ = _tmp19_ = g_strsplit (date, "T", 0);
		_tmp21_ = _tmp20_;
		_tmp21__length1 = _vala_array_length (_tmp19_);
		_tmp22_ = _tmp21_[1];
		_tmp24_ = _tmp23_ = g_strsplit (_tmp22_, ":", 0);
		_tmp25_ = _tmp24_;
		_tmp25__length1 = _vala_array_length (_tmp23_);
		_tmp21_ = (_vala_array_free (_tmp21_, _tmp21__length1, (GDestroyNotify) g_free), NULL);
		_time = _tmp25_;
		_time_length1 = _tmp25__length1;
		__time_size_ = _time_length1;
		_tmp26_ = _date;
		_tmp26__length1 = _date_length1;
		_tmp27_ = _tmp26_[0];
		_tmp28_ = _date;
		_tmp28__length1 = _date_length1;
		_tmp29_ = _tmp28_[1];
		_tmp30_ = _date;
		_tmp30__length1 = _date_length1;
		_tmp31_ = _tmp30_[2];
		_tmp32_ = _time;
		_tmp32__length1 = _time_length1;
		_tmp33_ = _tmp32_[0];
		_tmp34_ = _time;
		_tmp34__length1 = _time_length1;
		_tmp35_ = _tmp34_[1];
		_tmp36_ = _time;
		_tmp36__length1 = _time_length1;
		_tmp37_ = _tmp36_[2];
		_tmp38_ = g_date_time_new_local (atoi (_tmp27_), atoi (_tmp29_), atoi (_tmp31_), atoi (_tmp33_), atoi (_tmp35_), (gdouble) atoi (_tmp37_));
		_g_date_time_unref0 (datetime);
		datetime = _tmp38_;
		_time = (_vala_array_free (_time, _time_length1, (GDestroyNotify) g_free), NULL);
		_date = (_vala_array_free (_date, _date_length1, (GDestroyNotify) g_free), NULL);
	}
	result = datetime;
	return result;
}

gchar*
utils_datetime_get_relative_date_from_date (GDateTime* datetime)
{
	gchar* returned = NULL;
	gchar* _tmp1_;
	gchar* result;
	if (datetime == NULL) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("");
		result = _tmp0_;
		return result;
	}
	_tmp1_ = g_strdup ("");
	returned = _tmp1_;
	if (utils_datetime_is_today (datetime)) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (_ ("Today"));
		_g_free0 (returned);
		returned = _tmp2_;
	} else {
		if (utils_datetime_is_tomorrow (datetime)) {
			gchar* _tmp3_;
			_tmp3_ = g_strdup (_ ("Tomorrow"));
			_g_free0 (returned);
			returned = _tmp3_;
		} else {
			if (utils_datetime_is_yesterday (datetime)) {
				gchar* _tmp4_;
				_tmp4_ = g_strdup (_ ("Yesterday"));
				_g_free0 (returned);
				returned = _tmp4_;
			} else {
				gchar* _tmp5_;
				_tmp5_ = utils_datetime_get_default_date_format_from_date (datetime);
				_g_free0 (returned);
				returned = _tmp5_;
			}
		}
	}
	if (utils_datetime_has_time (datetime)) {
		const gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp6_ = returned;
		_tmp7_ = utils_datetime_get_default_time_format (utils_datetime_is_clock_format_12h (), FALSE);
		_tmp8_ = _tmp7_;
		_tmp9_ = g_date_time_format (datetime, _tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = g_strdup_printf ("%s, %s", _tmp6_, _tmp10_);
		_g_free0 (returned);
		returned = _tmp11_;
		_g_free0 (_tmp10_);
		_g_free0 (_tmp8_);
	}
	result = returned;
	return result;
}

gchar*
utils_datetime_days_left (GDateTime* datetime,
                          gboolean show_today)
{
	gchar* return_value = NULL;
	gchar* _tmp0_;
	GTimeSpan days = 0LL;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GTimeSpan _tmp3_;
	gchar* result;
	g_return_val_if_fail (datetime != NULL, NULL);
	_tmp0_ = g_strdup ("");
	return_value = _tmp0_;
	_tmp1_ = g_date_time_new_now_local ();
	_tmp2_ = _tmp1_;
	_tmp3_ = g_date_time_difference (datetime, _tmp2_) / G_TIME_SPAN_DAY;
	_g_date_time_unref0 (_tmp2_);
	days = _tmp3_;
	if (utils_datetime_is_today (datetime)) {
		const gchar* _tmp4_ = NULL;
		gchar* _tmp5_;
		if (show_today) {
			_tmp4_ = _ ("Today");
		} else {
			_tmp4_ = "";
		}
		_tmp5_ = g_strdup (_tmp4_);
		_g_free0 (return_value);
		return_value = _tmp5_;
	} else {
		if (utils_datetime_is_overdue (datetime)) {
			const gchar* _tmp6_ = NULL;
			gchar* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			if (days > ((GTimeSpan) 1)) {
				_tmp6_ = _ ("days");
			} else {
				_tmp6_ = _ ("day");
			}
			_tmp7_ = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) (days * -1));
			_tmp8_ = _tmp7_;
			_tmp9_ = g_strdup_printf ("%s %s ago", _tmp8_, _tmp6_);
			_tmp10_ = _tmp9_;
			_tmp11_ = g_strdup (_ (_tmp10_));
			_g_free0 (return_value);
			return_value = _tmp11_;
			_g_free0 (_tmp10_);
			_g_free0 (_tmp8_);
		} else {
			const gchar* _tmp12_ = NULL;
			gchar* _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			gchar* _tmp16_;
			gchar* _tmp17_;
			if (days > ((GTimeSpan) 1)) {
				_tmp12_ = _ ("days");
			} else {
				_tmp12_ = _ ("day");
			}
			_tmp13_ = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) (days + 1));
			_tmp14_ = _tmp13_;
			_tmp15_ = g_strdup_printf ("%s %s left", _tmp14_, _tmp12_);
			_tmp16_ = _tmp15_;
			_tmp17_ = g_strdup (_ (_tmp16_));
			_g_free0 (return_value);
			return_value = _tmp17_;
			_g_free0 (_tmp16_);
			_g_free0 (_tmp14_);
		}
	}
	result = return_value;
	return result;
}

gchar*
utils_datetime_get_default_time_format (gboolean is_12h,
                                        gboolean with_second)
{
	gchar* result;
	if (is_12h == TRUE) {
		if (with_second == TRUE) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (_ ("%-l:%M:%S %p"));
			result = _tmp0_;
			return result;
		} else {
			gchar* _tmp1_;
			_tmp1_ = g_strdup (_ ("%-l:%M %p"));
			result = _tmp1_;
			return result;
		}
	} else {
		if (with_second == TRUE) {
			gchar* _tmp2_;
			_tmp2_ = g_strdup (_ ("%H:%M:%S"));
			result = _tmp2_;
			return result;
		} else {
			gchar* _tmp3_;
			_tmp3_ = g_strdup (_ ("%H:%M"));
			result = _tmp3_;
			return result;
		}
	}
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

gboolean
utils_datetime_is_clock_format_12h (void)
{
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	GSettings* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gboolean _tmp5_;
	gboolean result;
	_tmp0_ = services_settings_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_->settings;
	_tmp3_ = g_settings_get_string (_tmp2_, "clock-format");
	_tmp4_ = _tmp3_;
	_tmp5_ = string_contains (_tmp4_, "12h");
	_g_free0 (_tmp4_);
	_g_object_unref0 (_tmp1_);
	result = _tmp5_;
	return result;
}

gboolean
utils_datetime_is_yesterday (GDateTime* date)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	_tmp0_ = g_date_time_new_now_local ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_date_time_add_days (_tmp1_, -1);
	_tmp3_ = _tmp2_;
	_tmp4_ = utils_datetime_is_same_day (date, _tmp3_);
	_g_date_time_unref0 (_tmp3_);
	_g_date_time_unref0 (_tmp1_);
	result = _tmp4_;
	return result;
}

gboolean
utils_datetime_is_same_day (GDateTime* day1,
                            GDateTime* day2)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (day1 != NULL, FALSE);
	g_return_val_if_fail (day2 != NULL, FALSE);
	if (g_date_time_get_day_of_year (day1) == g_date_time_get_day_of_year (day2)) {
		_tmp0_ = g_date_time_get_year (day1) == g_date_time_get_year (day2);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

gboolean
utils_datetime_is_overdue (GDateTime* date)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	GDateTime* _tmp5_;
	gboolean _tmp6_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	_tmp0_ = utils_datetime_get_date_only (date);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_date_time_new_now_local ();
	_tmp3_ = _tmp2_;
	_tmp4_ = utils_datetime_get_date_only (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_date_time_compare (_tmp1_, _tmp5_) == -1;
	_g_date_time_unref0 (_tmp5_);
	_g_date_time_unref0 (_tmp3_);
	_g_date_time_unref0 (_tmp1_);
	if (_tmp6_) {
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

gchar*
utils_datetime_get_calendar_icon (GDateTime* date)
{
	gchar* result;
	g_return_val_if_fail (date != NULL, NULL);
	if (utils_datetime_is_today (date)) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("planner-today");
		result = _tmp0_;
		return result;
	} else {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("planner-scheduled");
		result = _tmp1_;
		return result;
	}
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

void
utils_datetime_parse_todoist_recurrency (ObjectsDueDate* duedate,
                                         JsonObject* object)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp4_ = NULL;
	gchar* lang = NULL;
	gchar* _tmp6_;
	ChronoCore* chrono = NULL;
	const gchar* _tmp7_;
	ChronoCore* _tmp8_;
	ChronoParseResult* _result_ = NULL;
	ChronoCore* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	ChronoParseResult* _tmp12_;
	gboolean _tmp13_ = FALSE;
	ChronoParseResult* _tmp14_;
	ChronoParseResult* _tmp18_;
	ChronoRecurrenceRule* _tmp19_;
	ChronoRecurrenceRule* _tmp20_;
	gint _tmp21_;
	gint _tmp22_;
	ChronoParseResult* _tmp23_;
	ChronoRecurrenceRule* _tmp24_;
	ChronoRecurrenceRule* _tmp25_;
	ChronoRecurrenceType _tmp26_;
	ChronoRecurrenceType _tmp27_;
	ChronoParseResult* _tmp28_;
	ChronoRecurrenceRule* _tmp29_;
	ChronoRecurrenceRule* _tmp30_;
	GeeArrayList* _tmp31_;
	GeeArrayList* _tmp32_;
	g_return_if_fail (duedate != NULL);
	g_return_if_fail (object != NULL);
	if (json_object_has_member (object, "lang")) {
		const gchar* _tmp2_;
		_tmp2_ = json_object_get_string_member (object, "lang");
		_tmp1_ = g_strcmp0 (_tmp2_, "en") != 0;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		const gchar* _tmp3_;
		_tmp3_ = json_object_get_string_member (object, "lang");
		_tmp0_ = g_strcmp0 (_tmp3_, "es") != 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		objects_due_date_set_recurrence_supported (duedate, FALSE);
		return;
	}
	if (json_object_has_member (object, "lang")) {
		const gchar* _tmp5_;
		_tmp5_ = json_object_get_string_member (object, "lang");
		_tmp4_ = _tmp5_;
	} else {
		_tmp4_ = "en";
	}
	_tmp6_ = g_strdup (_tmp4_);
	lang = _tmp6_;
	_tmp7_ = lang;
	_tmp8_ = chrono_core_new (_tmp7_);
	chrono = _tmp8_;
	_tmp9_ = chrono;
	_tmp10_ = objects_due_date_get_recurrence_string (duedate);
	_tmp11_ = _tmp10_;
	_tmp12_ = chrono_core_parse (_tmp9_, _tmp11_, TRUE);
	_result_ = _tmp12_;
	_tmp14_ = _result_;
	if (_tmp14_ == NULL) {
		_tmp13_ = TRUE;
	} else {
		ChronoParseResult* _tmp15_;
		ChronoRecurrenceRule* _tmp16_;
		ChronoRecurrenceRule* _tmp17_;
		_tmp15_ = _result_;
		_tmp16_ = chrono_parse_result_get_recurrence (_tmp15_);
		_tmp17_ = _tmp16_;
		_tmp13_ = _tmp17_ == NULL;
	}
	if (_tmp13_) {
		objects_due_date_set_recurrence_supported (duedate, FALSE);
		objects_due_date_set_recurrency_type (duedate, RECURRENCY_TYPE_NONE);
		objects_due_date_set_recurrency_interval (duedate, 0);
		objects_due_date_set_recurrency_weeks (duedate, "");
		_g_object_unref0 (_result_);
		_g_object_unref0 (chrono);
		_g_free0 (lang);
		return;
	}
	objects_due_date_set_recurrence_supported (duedate, TRUE);
	objects_due_date_set_is_recurring (duedate, TRUE);
	_tmp18_ = _result_;
	_tmp19_ = chrono_parse_result_get_recurrence (_tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = chrono_recurrence_rule_get_interval (_tmp20_);
	_tmp22_ = _tmp21_;
	objects_due_date_set_recurrency_interval (duedate, _tmp22_);
	_tmp23_ = _result_;
	_tmp24_ = chrono_parse_result_get_recurrence (_tmp23_);
	_tmp25_ = _tmp24_;
	_tmp26_ = chrono_recurrence_rule_get_recurrence_type (_tmp25_);
	_tmp27_ = _tmp26_;
	switch (_tmp27_) {
		case CHRONO_RECURRENCE_TYPE_DAILY:
		{
			objects_due_date_set_recurrency_type (duedate, RECURRENCY_TYPE_EVERY_DAY);
			break;
		}
		case CHRONO_RECURRENCE_TYPE_WEEKLY:
		{
			objects_due_date_set_recurrency_type (duedate, RECURRENCY_TYPE_EVERY_WEEK);
			break;
		}
		case CHRONO_RECURRENCE_TYPE_MONTHLY:
		{
			objects_due_date_set_recurrency_type (duedate, RECURRENCY_TYPE_EVERY_MONTH);
			break;
		}
		case CHRONO_RECURRENCE_TYPE_YEARLY:
		{
			objects_due_date_set_recurrency_type (duedate, RECURRENCY_TYPE_EVERY_YEAR);
			break;
		}
		default:
		{
			objects_due_date_set_recurrency_type (duedate, RECURRENCY_TYPE_EVERY_DAY);
			break;
		}
	}
	objects_due_date_set_recurrency_weeks (duedate, "");
	_tmp28_ = _result_;
	_tmp29_ = chrono_parse_result_get_recurrence (_tmp28_);
	_tmp30_ = _tmp29_;
	_tmp31_ = chrono_recurrence_rule_get_days_of_week (_tmp30_);
	_tmp32_ = _tmp31_;
	if (_tmp32_ != NULL) {
		gchar* weeks = NULL;
		gchar* _tmp33_;
		const gchar* _tmp52_;
		gint _tmp53_;
		gint _tmp54_;
		_tmp33_ = g_strdup ("");
		weeks = _tmp33_;
		{
			GeeArrayList* _day_list = NULL;
			ChronoParseResult* _tmp34_;
			ChronoRecurrenceRule* _tmp35_;
			ChronoRecurrenceRule* _tmp36_;
			GeeArrayList* _tmp37_;
			GeeArrayList* _tmp38_;
			gint _day_size = 0;
			GeeArrayList* _tmp39_;
			gint _tmp40_;
			gint _tmp41_;
			gint _day_index = 0;
			_tmp34_ = _result_;
			_tmp35_ = chrono_parse_result_get_recurrence (_tmp34_);
			_tmp36_ = _tmp35_;
			_tmp37_ = chrono_recurrence_rule_get_days_of_week (_tmp36_);
			_tmp38_ = _tmp37_;
			_day_list = _tmp38_;
			_tmp39_ = _day_list;
			_tmp40_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp39_);
			_tmp41_ = _tmp40_;
			_day_size = _tmp41_;
			_day_index = -1;
			while (TRUE) {
				gint _tmp42_;
				gint _tmp43_;
				gint day = 0;
				GeeArrayList* _tmp44_;
				gpointer _tmp45_;
				const gchar* _tmp46_;
				gchar* _tmp47_;
				gchar* _tmp48_;
				gchar* _tmp49_;
				gchar* _tmp50_;
				gchar* _tmp51_;
				_day_index = _day_index + 1;
				_tmp42_ = _day_index;
				_tmp43_ = _day_size;
				if (!(_tmp42_ < _tmp43_)) {
					break;
				}
				_tmp44_ = _day_list;
				_tmp45_ = gee_abstract_list_get ((GeeAbstractList*) _tmp44_, _day_index);
				day = (gint) ((gintptr) _tmp45_);
				if (day == 0) {
					day = 7;
				}
				_tmp46_ = weeks;
				_tmp47_ = g_strdup_printf ("%i", day);
				_tmp48_ = _tmp47_;
				_tmp49_ = g_strconcat (_tmp48_, ",", NULL);
				_tmp50_ = _tmp49_;
				_tmp51_ = g_strconcat (_tmp46_, _tmp50_, NULL);
				_g_free0 (weeks);
				weeks = _tmp51_;
				_g_free0 (_tmp50_);
				_g_free0 (_tmp48_);
			}
		}
		_tmp52_ = weeks;
		_tmp53_ = strlen (_tmp52_);
		_tmp54_ = _tmp53_;
		if (_tmp54_ > 0) {
			const gchar* _tmp55_;
			const gchar* _tmp56_;
			gint _tmp57_;
			gint _tmp58_;
			gchar* _tmp59_;
			gchar* _tmp60_;
			_tmp55_ = weeks;
			_tmp56_ = weeks;
			_tmp57_ = strlen (_tmp56_);
			_tmp58_ = _tmp57_;
			_tmp59_ = string_substring (_tmp55_, (glong) 0, (glong) (_tmp58_ - 1));
			_tmp60_ = _tmp59_;
			objects_due_date_set_recurrency_weeks (duedate, _tmp60_);
			_g_free0 (_tmp60_);
		}
		_g_free0 (weeks);
	}
	_g_object_unref0 (_result_);
	_g_object_unref0 (chrono);
	_g_free0 (lang);
}

gboolean
utils_datetime_has_time (GDateTime* datetime)
{
	gboolean returned = FALSE;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	g_return_val_if_fail (datetime != NULL, FALSE);
	if (datetime == NULL) {
		result = FALSE;
		return result;
	}
	returned = TRUE;
	if (g_date_time_get_hour (datetime) == 0) {
		_tmp1_ = g_date_time_get_minute (datetime) == 0;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		_tmp0_ = g_date_time_get_second (datetime) == 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		returned = FALSE;
	}
	result = returned;
	return result;
}

gboolean
utils_datetime_is_today (GDateTime* date)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	if (date == NULL) {
		result = FALSE;
		return result;
	}
	_tmp0_ = g_date_time_new_now_local ();
	_tmp1_ = _tmp0_;
	_tmp2_ = utils_datetime_is_same_day (date, _tmp1_);
	_g_date_time_unref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

gboolean
utils_datetime_is_tomorrow (GDateTime* date)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	if (date == NULL) {
		result = FALSE;
		return result;
	}
	_tmp0_ = g_date_time_new_now_local ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_date_time_add_days (_tmp1_, 1);
	_tmp3_ = _tmp2_;
	_tmp4_ = utils_datetime_is_same_day (date, _tmp3_);
	_g_date_time_unref0 (_tmp3_);
	_g_date_time_unref0 (_tmp1_);
	result = _tmp4_;
	return result;
}

gboolean
utils_datetime_is_next_week (GDateTime* date)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	if (date == NULL) {
		result = FALSE;
		return result;
	}
	_tmp0_ = g_date_time_new_now_local ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_date_time_add_days (_tmp1_, 7);
	_tmp3_ = _tmp2_;
	_tmp4_ = utils_datetime_is_same_day (date, _tmp3_);
	_g_date_time_unref0 (_tmp3_);
	_g_date_time_unref0 (_tmp1_);
	result = _tmp4_;
	return result;
}

GDateTime*
utils_datetime_get_date_from_string (const gchar* date)
{
	GTimeZone* _tmp0_;
	GTimeZone* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* result;
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = g_time_zone_new_local ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_date_time_new_from_iso8601 (date, _tmp1_);
	_tmp3_ = _tmp2_;
	_g_time_zone_unref0 (_tmp1_);
	result = _tmp3_;
	return result;
}

static gchar*
g_date_time_to_string (GDateTime* self)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_date_time_format (self, "%FT%H:%M:%S%z");
	result = _tmp0_;
	return result;
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

void
utils_datetime_recurrence_to_due (ICalRecurrence* recurrence,
                                  ObjectsDueDate* due)
{
	ICalRecurrenceFrequency freq = 0;
	gshort interval = 0;
	gint count = 0;
	ICalTime* until = NULL;
	ICalTime* _tmp2_;
	ICalTime* _tmp3_;
	RecurrencyType _tmp9_;
	RecurrencyType _tmp10_;
	g_return_if_fail (recurrence != NULL);
	g_return_if_fail (due != NULL);
	objects_due_date_set_is_recurring (due, TRUE);
	freq = i_cal_recurrence_get_freq (recurrence);
	if (freq == I_CAL_MINUTELY_RECURRENCE) {
		objects_due_date_set_recurrency_type (due, RECURRENCY_TYPE_MINUTELY);
	} else {
		if (freq == I_CAL_HOURLY_RECURRENCE) {
			objects_due_date_set_recurrency_type (due, RECURRENCY_TYPE_HOURLY);
		} else {
			if (freq == I_CAL_DAILY_RECURRENCE) {
				objects_due_date_set_recurrency_type (due, RECURRENCY_TYPE_EVERY_DAY);
			} else {
				if (freq == I_CAL_WEEKLY_RECURRENCE) {
					objects_due_date_set_recurrency_type (due, RECURRENCY_TYPE_EVERY_WEEK);
				} else {
					if (freq == I_CAL_MONTHLY_RECURRENCE) {
						GArray* monthday_array = NULL;
						GArray* _tmp0_;
						GArray* _tmp1_;
						objects_due_date_set_recurrency_type (due, RECURRENCY_TYPE_EVERY_MONTH);
						_tmp0_ = i_cal_recurrence_get_by_array (recurrence, I_CAL_BY_MONTH_DAY);
						monthday_array = _tmp0_;
						_tmp1_ = monthday_array;
						{
							GArray* val_collection = NULL;
							guint val_index = 0U;
							val_collection = _tmp1_;
							for (val_index = 0; val_index < val_collection->len; val_index = val_index + 1) {
								gshort val = 0;
								val = g_array_index (val_collection, gshort, val_index);
								{
									if (((gint) val) == -1) {
										objects_due_date_set_recurrency_last_day_of_month (due, TRUE);
										break;
									}
								}
							}
						}
						_g_array_unref0 (monthday_array);
					} else {
						if (freq == I_CAL_YEARLY_RECURRENCE) {
							objects_due_date_set_recurrency_type (due, RECURRENCY_TYPE_EVERY_YEAR);
						}
					}
				}
			}
		}
	}
	interval = i_cal_recurrence_get_interval (recurrence);
	objects_due_date_set_recurrency_interval (due, (gint) interval);
	count = i_cal_recurrence_get_count (recurrence);
	objects_due_date_set_recurrency_count (due, count);
	_tmp2_ = i_cal_recurrence_get_until (recurrence);
	until = _tmp2_;
	_tmp3_ = until;
	if (!i_cal_time_is_null_time (_tmp3_)) {
		ICalTime* _tmp4_;
		GDateTime* _tmp5_;
		GDateTime* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		_tmp4_ = until;
		_tmp5_ = utils_datetime_ical_to_date_time_local (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_date_time_to_string (_tmp6_);
		_tmp8_ = _tmp7_;
		objects_due_date_set_recurrency_end (due, _tmp8_);
		_g_free0 (_tmp8_);
		_g_date_time_unref0 (_tmp6_);
	}
	_tmp9_ = objects_due_date_get_recurrency_type (due);
	_tmp10_ = _tmp9_;
	if (_tmp10_ == RECURRENCY_TYPE_EVERY_WEEK) {
		gchar* recurrency_weeks = NULL;
		gchar* _tmp11_;
		GArray* day_array = NULL;
		GArray* _tmp12_;
		GArray* _tmp13_;
		GArray* _tmp16_;
		GArray* _tmp19_;
		GArray* _tmp22_;
		GArray* _tmp25_;
		GArray* _tmp28_;
		GArray* _tmp31_;
		gboolean _tmp34_ = FALSE;
		const gchar* _tmp35_;
		const gchar* _tmp43_;
		_tmp11_ = g_strdup ("");
		recurrency_weeks = _tmp11_;
		_tmp12_ = i_cal_recurrence_get_by_array (recurrence, I_CAL_BY_DAY);
		day_array = _tmp12_;
		_tmp13_ = day_array;
		if (utils_datetime_check_by_day ("1", _tmp13_)) {
			const gchar* _tmp14_;
			gchar* _tmp15_;
			_tmp14_ = recurrency_weeks;
			_tmp15_ = g_strconcat (_tmp14_, "7,", NULL);
			_g_free0 (recurrency_weeks);
			recurrency_weeks = _tmp15_;
		}
		_tmp16_ = day_array;
		if (utils_datetime_check_by_day ("2", _tmp16_)) {
			const gchar* _tmp17_;
			gchar* _tmp18_;
			_tmp17_ = recurrency_weeks;
			_tmp18_ = g_strconcat (_tmp17_, "1,", NULL);
			_g_free0 (recurrency_weeks);
			recurrency_weeks = _tmp18_;
		}
		_tmp19_ = day_array;
		if (utils_datetime_check_by_day ("3", _tmp19_)) {
			const gchar* _tmp20_;
			gchar* _tmp21_;
			_tmp20_ = recurrency_weeks;
			_tmp21_ = g_strconcat (_tmp20_, "2,", NULL);
			_g_free0 (recurrency_weeks);
			recurrency_weeks = _tmp21_;
		}
		_tmp22_ = day_array;
		if (utils_datetime_check_by_day ("4", _tmp22_)) {
			const gchar* _tmp23_;
			gchar* _tmp24_;
			_tmp23_ = recurrency_weeks;
			_tmp24_ = g_strconcat (_tmp23_, "3,", NULL);
			_g_free0 (recurrency_weeks);
			recurrency_weeks = _tmp24_;
		}
		_tmp25_ = day_array;
		if (utils_datetime_check_by_day ("5", _tmp25_)) {
			const gchar* _tmp26_;
			gchar* _tmp27_;
			_tmp26_ = recurrency_weeks;
			_tmp27_ = g_strconcat (_tmp26_, "4,", NULL);
			_g_free0 (recurrency_weeks);
			recurrency_weeks = _tmp27_;
		}
		_tmp28_ = day_array;
		if (utils_datetime_check_by_day ("6", _tmp28_)) {
			const gchar* _tmp29_;
			gchar* _tmp30_;
			_tmp29_ = recurrency_weeks;
			_tmp30_ = g_strconcat (_tmp29_, "5,", NULL);
			_g_free0 (recurrency_weeks);
			recurrency_weeks = _tmp30_;
		}
		_tmp31_ = day_array;
		if (utils_datetime_check_by_day ("7", _tmp31_)) {
			const gchar* _tmp32_;
			gchar* _tmp33_;
			_tmp32_ = recurrency_weeks;
			_tmp33_ = g_strconcat (_tmp32_, "6,", NULL);
			_g_free0 (recurrency_weeks);
			recurrency_weeks = _tmp33_;
		}
		_tmp35_ = recurrency_weeks;
		if (_tmp35_ != NULL) {
			const gchar* _tmp36_;
			gchar** _tmp37_;
			gchar** _tmp38_;
			gchar** _tmp39_;
			gint _tmp39__length1;
			_tmp36_ = recurrency_weeks;
			_tmp38_ = _tmp37_ = g_strsplit (_tmp36_, ",", 0);
			_tmp39_ = _tmp38_;
			_tmp39__length1 = _vala_array_length (_tmp37_);
			_tmp34_ = _vala_array_length (_tmp37_) > 0;
			_tmp39_ = (_vala_array_free (_tmp39_, _tmp39__length1, (GDestroyNotify) g_free), NULL);
		} else {
			_tmp34_ = FALSE;
		}
		if (_tmp34_) {
			const gchar* _tmp40_;
			gchar* _tmp41_;
			gchar* _tmp42_;
			_tmp40_ = recurrency_weeks;
			_tmp41_ = string_slice (_tmp40_, (glong) 0, (glong) -1);
			_tmp42_ = _tmp41_;
			_g_free0 (_tmp42_);
		}
		_tmp43_ = recurrency_weeks;
		objects_due_date_set_recurrency_weeks (due, _tmp43_);
		_g_array_unref0 (day_array);
		_g_free0 (recurrency_weeks);
	}
	_g_object_unref0 (until);
}

static gboolean
utils_datetime_check_by_day (const gchar* day,
                             GArray* day_array)
{
	gboolean result;
	g_return_val_if_fail (day != NULL, FALSE);
	g_return_val_if_fail (day_array != NULL, FALSE);
	{
		GArray* _day_collection = NULL;
		guint _day_index = 0U;
		_day_collection = day_array;
		for (_day_index = 0; _day_index < _day_collection->len; _day_index = _day_index + 1) {
			gshort _day = 0;
			_day = g_array_index (_day_collection, gshort, _day_index);
			{
				gchar* _tmp0_;
				gchar* _tmp1_;
				gboolean _tmp2_;
				_tmp0_ = g_strdup_printf ("%hi", _day);
				_tmp1_ = _tmp0_;
				_tmp2_ = g_strcmp0 (_tmp1_, day) == 0;
				_g_free0 (_tmp1_);
				if (_tmp2_) {
					result = TRUE;
					return result;
				}
			}
		}
	}
	result = FALSE;
	return result;
}

GDateTime*
utils_datetime_format_date (GDateTime* date)
{
	GDateTime* _tmp0_;
	GDateTime* result;
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = g_date_time_new_local (g_date_time_get_year (date), g_date_time_get_month (date), g_date_time_get_day_of_month (date), 0, 0, (gdouble) 0);
	result = _tmp0_;
	return result;
}

gboolean
utils_datetime_is_this_week (GDateTime* date)
{
	GDateTime* current_date = NULL;
	GDateTime* _tmp0_;
	GDateTime* start_of_week = NULL;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* end_of_week = NULL;
	GDateTime* _tmp4_;
	GDateTime* _tmp5_;
	gboolean _tmp6_ = FALSE;
	GDateTime* _tmp7_;
	GDateTime* _tmp8_;
	GDateTime* _tmp9_;
	gboolean _tmp10_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	_tmp0_ = g_date_time_new_now_local ();
	current_date = _tmp0_;
	_tmp1_ = current_date;
	_tmp2_ = current_date;
	_tmp3_ = g_date_time_add_days (_tmp1_, (g_date_time_get_day_of_week (_tmp2_) - 1) * -1);
	start_of_week = _tmp3_;
	_tmp4_ = current_date;
	_tmp5_ = g_date_time_add_days (_tmp4_, 6);
	end_of_week = _tmp5_;
	_tmp7_ = start_of_week;
	_tmp8_ = utils_datetime_format_date (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_date_time_compare (date, _tmp9_) >= 0;
	_g_date_time_unref0 (_tmp9_);
	if (_tmp10_) {
		GDateTime* _tmp11_;
		GDateTime* _tmp12_;
		GDateTime* _tmp13_;
		_tmp11_ = end_of_week;
		_tmp12_ = utils_datetime_format_date (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp6_ = g_date_time_compare (date, _tmp13_) <= 0;
		_g_date_time_unref0 (_tmp13_);
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		result = TRUE;
		_g_date_time_unref0 (end_of_week);
		_g_date_time_unref0 (start_of_week);
		_g_date_time_unref0 (current_date);
		return result;
	}
	result = FALSE;
	_g_date_time_unref0 (end_of_week);
	_g_date_time_unref0 (start_of_week);
	_g_date_time_unref0 (current_date);
	return result;
}

gboolean
utils_datetime_is_next_x_week (GDateTime* date,
                               gint days)
{
	GDateTime* current_date = NULL;
	GDateTime* _tmp0_;
	GDateTime* end_date = NULL;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	gboolean _tmp3_ = FALSE;
	GDateTime* _tmp4_;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	gboolean _tmp7_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	_tmp0_ = g_date_time_new_now_local ();
	current_date = _tmp0_;
	_tmp1_ = current_date;
	_tmp2_ = g_date_time_add_days (_tmp1_, days);
	end_date = _tmp2_;
	_tmp4_ = current_date;
	_tmp5_ = utils_datetime_format_date (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_date_time_compare (date, _tmp6_) >= 0;
	_g_date_time_unref0 (_tmp6_);
	if (_tmp7_) {
		GDateTime* _tmp8_;
		GDateTime* _tmp9_;
		GDateTime* _tmp10_;
		_tmp8_ = end_date;
		_tmp9_ = utils_datetime_format_date (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp3_ = g_date_time_compare (date, _tmp10_) <= 0;
		_g_date_time_unref0 (_tmp10_);
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		result = TRUE;
		_g_date_time_unref0 (end_date);
		_g_date_time_unref0 (current_date);
		return result;
	}
	result = FALSE;
	_g_date_time_unref0 (end_date);
	_g_date_time_unref0 (current_date);
	return result;
}

gboolean
utils_datetime_is_this_month (GDateTime* date)
{
	GDateTime* current_date = NULL;
	GDateTime* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GDateTime* _tmp2_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	_tmp0_ = g_date_time_new_now_local ();
	current_date = _tmp0_;
	_tmp2_ = current_date;
	if (g_date_time_get_month (_tmp2_) == g_date_time_get_month (date)) {
		GDateTime* _tmp3_;
		_tmp3_ = current_date;
		_tmp1_ = g_date_time_get_year (_tmp3_) == g_date_time_get_year (date);
	} else {
		_tmp1_ = FALSE;
	}
	result = _tmp1_;
	_g_date_time_unref0 (current_date);
	return result;
}

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

GDateTime*
utils_datetime_next_recurrency (GDateTime* datetime,
                                ObjectsDueDate* duedate)
{
	GDateTime* returned = NULL;
	GDateTime* _tmp0_;
	RecurrencyType _tmp1_;
	RecurrencyType _tmp2_;
	GDateTime* result;
	g_return_val_if_fail (datetime != NULL, NULL);
	g_return_val_if_fail (duedate != NULL, NULL);
	_tmp0_ = _g_date_time_ref0 (datetime);
	returned = _tmp0_;
	_tmp1_ = objects_due_date_get_recurrency_type (duedate);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == RECURRENCY_TYPE_MINUTELY) {
		GDateTime* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		GDateTime* _tmp6_;
		_tmp3_ = returned;
		_tmp4_ = objects_due_date_get_recurrency_interval (duedate);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_date_time_add_minutes (_tmp3_, _tmp5_);
		_g_date_time_unref0 (returned);
		returned = _tmp6_;
	} else {
		RecurrencyType _tmp7_;
		RecurrencyType _tmp8_;
		_tmp7_ = objects_due_date_get_recurrency_type (duedate);
		_tmp8_ = _tmp7_;
		if (_tmp8_ == RECURRENCY_TYPE_HOURLY) {
			GDateTime* _tmp9_;
			gint _tmp10_;
			gint _tmp11_;
			GDateTime* _tmp12_;
			_tmp9_ = returned;
			_tmp10_ = objects_due_date_get_recurrency_interval (duedate);
			_tmp11_ = _tmp10_;
			_tmp12_ = g_date_time_add_hours (_tmp9_, _tmp11_);
			_g_date_time_unref0 (returned);
			returned = _tmp12_;
		} else {
			RecurrencyType _tmp13_;
			RecurrencyType _tmp14_;
			_tmp13_ = objects_due_date_get_recurrency_type (duedate);
			_tmp14_ = _tmp13_;
			if (_tmp14_ == RECURRENCY_TYPE_EVERY_DAY) {
				GDateTime* _tmp15_;
				gint _tmp16_;
				gint _tmp17_;
				GDateTime* _tmp18_;
				_tmp15_ = returned;
				_tmp16_ = objects_due_date_get_recurrency_interval (duedate);
				_tmp17_ = _tmp16_;
				_tmp18_ = g_date_time_add_days (_tmp15_, _tmp17_);
				_g_date_time_unref0 (returned);
				returned = _tmp18_;
			} else {
				RecurrencyType _tmp19_;
				RecurrencyType _tmp20_;
				_tmp19_ = objects_due_date_get_recurrency_type (duedate);
				_tmp20_ = _tmp19_;
				if (_tmp20_ == RECURRENCY_TYPE_EVERY_WEEK) {
					const gchar* _tmp21_;
					const gchar* _tmp22_;
					_tmp21_ = objects_due_date_get_recurrency_weeks (duedate);
					_tmp22_ = _tmp21_;
					if (g_strcmp0 (_tmp22_, "") == 0) {
						GDateTime* _tmp23_;
						gint _tmp24_;
						gint _tmp25_;
						GDateTime* _tmp26_;
						_tmp23_ = returned;
						_tmp24_ = objects_due_date_get_recurrency_interval (duedate);
						_tmp25_ = _tmp24_;
						_tmp26_ = g_date_time_add_days (_tmp23_, _tmp25_ * 7);
						_g_date_time_unref0 (returned);
						returned = _tmp26_;
					} else {
						GDateTime* _tmp27_;
						_tmp27_ = utils_datetime_next_recurrency_week (datetime, duedate, TRUE);
						_g_date_time_unref0 (returned);
						returned = _tmp27_;
					}
				} else {
					RecurrencyType _tmp28_;
					RecurrencyType _tmp29_;
					_tmp28_ = objects_due_date_get_recurrency_type (duedate);
					_tmp29_ = _tmp28_;
					if (_tmp29_ == RECURRENCY_TYPE_EVERY_MONTH) {
						gboolean _tmp30_;
						gboolean _tmp31_;
						_tmp30_ = objects_due_date_get_recurrency_last_day_of_month (duedate);
						_tmp31_ = _tmp30_;
						if (_tmp31_) {
							GDateTime* next_month = NULL;
							GDateTime* _tmp32_;
							gint _tmp33_;
							gint _tmp34_;
							GDateTime* _tmp35_;
							gint days = 0;
							GDateTime* _tmp36_;
							GDateTime* _tmp37_;
							GDateTime* _tmp38_;
							GDateTime* _tmp39_;
							GDateTime* _tmp40_;
							GDateTime* _tmp41_;
							GDateTime* _tmp42_;
							GDateTime* _tmp43_;
							_tmp32_ = returned;
							_tmp33_ = objects_due_date_get_recurrency_interval (duedate);
							_tmp34_ = _tmp33_;
							_tmp35_ = g_date_time_add_months (_tmp32_, _tmp34_);
							next_month = _tmp35_;
							_tmp36_ = next_month;
							_tmp37_ = next_month;
							days = (gint) g_date_get_days_in_month ((GDateMonth) g_date_time_get_month (_tmp36_), (GDateYear) g_date_time_get_year (_tmp37_));
							_tmp38_ = next_month;
							_tmp39_ = next_month;
							_tmp40_ = returned;
							_tmp41_ = returned;
							_tmp42_ = returned;
							_tmp43_ = g_date_time_new_local (g_date_time_get_year (_tmp38_), g_date_time_get_month (_tmp39_), days, g_date_time_get_hour (_tmp40_), g_date_time_get_minute (_tmp41_), (gdouble) g_date_time_get_second (_tmp42_));
							_g_date_time_unref0 (returned);
							returned = _tmp43_;
							_g_date_time_unref0 (next_month);
						} else {
							GDateTime* _tmp44_;
							gint _tmp45_;
							gint _tmp46_;
							GDateTime* _tmp47_;
							_tmp44_ = returned;
							_tmp45_ = objects_due_date_get_recurrency_interval (duedate);
							_tmp46_ = _tmp45_;
							_tmp47_ = g_date_time_add_months (_tmp44_, _tmp46_);
							_g_date_time_unref0 (returned);
							returned = _tmp47_;
						}
					} else {
						RecurrencyType _tmp48_;
						RecurrencyType _tmp49_;
						_tmp48_ = objects_due_date_get_recurrency_type (duedate);
						_tmp49_ = _tmp48_;
						if (_tmp49_ == RECURRENCY_TYPE_EVERY_YEAR) {
							GDateTime* _tmp50_;
							gint _tmp51_;
							gint _tmp52_;
							GDateTime* _tmp53_;
							_tmp50_ = returned;
							_tmp51_ = objects_due_date_get_recurrency_interval (duedate);
							_tmp52_ = _tmp51_;
							_tmp53_ = g_date_time_add_years (_tmp50_, _tmp52_);
							_g_date_time_unref0 (returned);
							returned = _tmp53_;
						}
					}
				}
			}
		}
	}
	result = returned;
	return result;
}

gint
utils_datetime_get_next_day_of_week_from_recurrency_week (GDateTime* datetime,
                                                          ObjectsDueDate* duedate)
{
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar** weeks = NULL;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	gchar** _tmp7_;
	gchar** _tmp8_;
	gint weeks_length1;
	gint _weeks_size_;
	gint day_of_week = 0;
	gint index = 0;
	gchar** _tmp14_;
	gint _tmp14__length1;
	gchar** _tmp15_;
	gint _tmp15__length1;
	const gchar* _tmp16_;
	gint result;
	g_return_val_if_fail (datetime != NULL, -1);
	g_return_val_if_fail (duedate != NULL, -1);
	_tmp1_ = objects_due_date_get_recurrency_weeks (duedate);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp3_ = objects_due_date_get_recurrency_weeks (duedate);
		_tmp4_ = _tmp3_;
		_tmp0_ = g_strcmp0 (_tmp4_, "") == 0;
	}
	if (_tmp0_) {
		result = g_date_time_get_day_of_week (datetime);
		return result;
	}
	_tmp5_ = objects_due_date_get_recurrency_weeks (duedate);
	_tmp6_ = _tmp5_;
	_tmp8_ = _tmp7_ = g_strsplit (_tmp6_, ",", 0);
	weeks = _tmp8_;
	weeks_length1 = _vala_array_length (_tmp7_);
	_weeks_size_ = weeks_length1;
	day_of_week = g_date_time_get_day_of_week (datetime);
	index = 0;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp9_ = FALSE;
			_tmp9_ = TRUE;
			while (TRUE) {
				gchar** _tmp11_;
				gint _tmp11__length1;
				gchar** _tmp12_;
				gint _tmp12__length1;
				const gchar* _tmp13_;
				if (!_tmp9_) {
					gint _tmp10_;
					_tmp10_ = i;
					i = _tmp10_ + 1;
				}
				_tmp9_ = FALSE;
				_tmp11_ = weeks;
				_tmp11__length1 = weeks_length1;
				if (!(i < _tmp11__length1)) {
					break;
				}
				_tmp12_ = weeks;
				_tmp12__length1 = weeks_length1;
				_tmp13_ = _tmp12_[i];
				if (day_of_week <= atoi (_tmp13_)) {
					index = i;
					break;
				}
			}
		}
	}
	_tmp14_ = weeks;
	_tmp14__length1 = weeks_length1;
	if (index > (_tmp14__length1 - 1)) {
		index = 0;
	}
	_tmp15_ = weeks;
	_tmp15__length1 = weeks_length1;
	_tmp16_ = _tmp15_[index];
	result = atoi (_tmp16_);
	weeks = (_vala_array_free (weeks, weeks_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

GDateTime*
utils_datetime_next_recurrency_week (GDateTime* datetime,
                                     ObjectsDueDate* duedate,
                                     gboolean user)
{
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar** weeks = NULL;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	gchar** _tmp10_;
	gchar** _tmp11_;
	gint weeks_length1;
	gint _weeks_size_;
	gint day_of_week = 0;
	gint days = 0;
	gint next_day = 0;
	gint index = 0;
	gint recurrency_interval = 0;
	gchar** _tmp17_;
	gint _tmp17__length1;
	const gchar* _tmp18_;
	gboolean _tmp19_ = FALSE;
	GDateTime* _tmp22_;
	GDateTime* _tmp23_;
	GDateTime* _tmp24_;
	GDateTime* _tmp25_;
	GDateTime* result;
	g_return_val_if_fail (datetime != NULL, NULL);
	g_return_val_if_fail (duedate != NULL, NULL);
	_tmp1_ = objects_due_date_get_recurrency_weeks (duedate);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp3_ = objects_due_date_get_recurrency_weeks (duedate);
		_tmp4_ = _tmp3_;
		_tmp0_ = g_strcmp0 (_tmp4_, "") == 0;
	}
	if (_tmp0_) {
		gint _tmp5_;
		gint _tmp6_;
		GDateTime* _tmp7_;
		_tmp5_ = objects_due_date_get_recurrency_interval (duedate);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_date_time_add_days (datetime, _tmp6_ * 7);
		result = _tmp7_;
		return result;
	}
	_tmp8_ = objects_due_date_get_recurrency_weeks (duedate);
	_tmp9_ = _tmp8_;
	_tmp11_ = _tmp10_ = g_strsplit (_tmp9_, ",", 0);
	weeks = _tmp11_;
	weeks_length1 = _vala_array_length (_tmp10_);
	_weeks_size_ = weeks_length1;
	day_of_week = g_date_time_get_day_of_week (datetime);
	days = 0;
	next_day = 0;
	index = 0;
	recurrency_interval = 0;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp12_ = FALSE;
			_tmp12_ = TRUE;
			while (TRUE) {
				gchar** _tmp14_;
				gint _tmp14__length1;
				gchar** _tmp15_;
				gint _tmp15__length1;
				const gchar* _tmp16_;
				if (!_tmp12_) {
					gint _tmp13_;
					_tmp13_ = i;
					i = _tmp13_ + 1;
				}
				_tmp12_ = FALSE;
				_tmp14_ = weeks;
				_tmp14__length1 = weeks_length1;
				if (!(i < _tmp14__length1)) {
					break;
				}
				_tmp15_ = weeks;
				_tmp15__length1 = weeks_length1;
				_tmp16_ = _tmp15_[i];
				if (day_of_week < atoi (_tmp16_)) {
					index = i;
					break;
				}
			}
		}
	}
	_tmp17_ = weeks;
	_tmp17__length1 = weeks_length1;
	_tmp18_ = _tmp17_[index];
	next_day = atoi (_tmp18_);
	if (day_of_week < next_day) {
		days = next_day - day_of_week;
	} else {
		days = 7 - (day_of_week - next_day);
	}
	if (user) {
		_tmp19_ = index == 0;
	} else {
		_tmp19_ = FALSE;
	}
	if (_tmp19_) {
		gint _tmp20_;
		gint _tmp21_;
		_tmp20_ = objects_due_date_get_recurrency_interval (duedate);
		_tmp21_ = _tmp20_;
		recurrency_interval = (_tmp21_ - 1) * 7;
	}
	_tmp22_ = g_date_time_add_days (datetime, days);
	_tmp23_ = _tmp22_;
	_tmp24_ = g_date_time_add_days (_tmp23_, recurrency_interval);
	_tmp25_ = _tmp24_;
	_g_date_time_unref0 (_tmp23_);
	result = _tmp25_;
	weeks = (_vala_array_free (weeks, weeks_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

static gint
string_index_of_nth_char (const gchar* self,
                          glong c)
{
	gchar* _tmp0_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_offset_to_pointer (self, c);
	result = (gint) (_tmp0_ - ((gchar*) self));
	return result;
}

gchar*
utils_datetime_get_recurrency_weeks (RecurrencyType recurrency_type,
                                     gint recurrency_interval,
                                     const gchar* recurrency_weeks,
                                     const gchar* end,
                                     gboolean recurrency_last_day_of_month)
{
	gchar* returned = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp34_;
	gchar* _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	gchar* result;
	g_return_val_if_fail (recurrency_weeks != NULL, NULL);
	g_return_val_if_fail (end != NULL, NULL);
	_tmp0_ = recurrency_type_to_friendly_string (recurrency_type, &recurrency_interval);
	returned = _tmp0_;
	if (recurrency_type == RECURRENCY_TYPE_EVERY_MONTH) {
		_tmp1_ = recurrency_last_day_of_month;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		gchar* _tmp2_ = NULL;
		gchar* _tmp5_;
		if (recurrency_interval == 1) {
			gchar* _tmp3_;
			_tmp3_ = g_strdup (_ ("Every last day of month"));
			_g_free0 (_tmp2_);
			_tmp2_ = _tmp3_;
		} else {
			gchar* _tmp4_;
			_tmp4_ = g_strdup_printf (_ ("Every %d months (last day)"), recurrency_interval);
			_g_free0 (_tmp2_);
			_tmp2_ = _tmp4_;
		}
		_tmp5_ = _tmp2_;
		_tmp2_ = NULL;
		_g_free0 (returned);
		returned = _tmp5_;
		_g_free0 (_tmp2_);
	} else {
		gboolean _tmp6_ = FALSE;
		gboolean _tmp7_ = FALSE;
		if (recurrency_type == RECURRENCY_TYPE_EVERY_WEEK) {
			_tmp7_ = recurrency_weeks != NULL;
		} else {
			_tmp7_ = FALSE;
		}
		if (_tmp7_) {
			gchar** _tmp8_;
			gchar** _tmp9_;
			gchar** _tmp10_;
			gint _tmp10__length1;
			_tmp9_ = _tmp8_ = g_strsplit (recurrency_weeks, ",", 0);
			_tmp10_ = _tmp9_;
			_tmp10__length1 = _vala_array_length (_tmp8_);
			_tmp6_ = _vala_array_length (_tmp8_) > 0;
			_tmp10_ = (_vala_array_free (_tmp10_, _tmp10__length1, (GDestroyNotify) g_free), NULL);
		} else {
			_tmp6_ = FALSE;
		}
		if (_tmp6_) {
			gchar* weeks = NULL;
			gchar* _tmp11_;
			const gchar* _tmp26_;
			const gchar* _tmp27_;
			gchar* _tmp28_;
			gchar* _tmp29_;
			gchar* _tmp30_;
			const gchar* _tmp31_;
			const gchar* _tmp32_;
			gchar* _tmp33_;
			_tmp11_ = g_strdup ("");
			weeks = _tmp11_;
			if (string_contains (recurrency_weeks, "1")) {
				const gchar* _tmp12_;
				gchar* _tmp13_;
				_tmp12_ = weeks;
				_tmp13_ = g_strconcat (_tmp12_, _ ("Mo,"), NULL);
				_g_free0 (weeks);
				weeks = _tmp13_;
			}
			if (string_contains (recurrency_weeks, "2")) {
				const gchar* _tmp14_;
				gchar* _tmp15_;
				_tmp14_ = weeks;
				_tmp15_ = g_strconcat (_tmp14_, _ ("Tu,"), NULL);
				_g_free0 (weeks);
				weeks = _tmp15_;
			}
			if (string_contains (recurrency_weeks, "3")) {
				const gchar* _tmp16_;
				gchar* _tmp17_;
				_tmp16_ = weeks;
				_tmp17_ = g_strconcat (_tmp16_, _ ("We,"), NULL);
				_g_free0 (weeks);
				weeks = _tmp17_;
			}
			if (string_contains (recurrency_weeks, "4")) {
				const gchar* _tmp18_;
				gchar* _tmp19_;
				_tmp18_ = weeks;
				_tmp19_ = g_strconcat (_tmp18_, _ ("Th,"), NULL);
				_g_free0 (weeks);
				weeks = _tmp19_;
			}
			if (string_contains (recurrency_weeks, "5")) {
				const gchar* _tmp20_;
				gchar* _tmp21_;
				_tmp20_ = weeks;
				_tmp21_ = g_strconcat (_tmp20_, _ ("Fr,"), NULL);
				_g_free0 (weeks);
				weeks = _tmp21_;
			}
			if (string_contains (recurrency_weeks, "6")) {
				const gchar* _tmp22_;
				gchar* _tmp23_;
				_tmp22_ = weeks;
				_tmp23_ = g_strconcat (_tmp22_, _ ("Sa,"), NULL);
				_g_free0 (weeks);
				weeks = _tmp23_;
			}
			if (string_contains (recurrency_weeks, "7")) {
				const gchar* _tmp24_;
				gchar* _tmp25_;
				_tmp24_ = weeks;
				_tmp25_ = g_strconcat (_tmp24_, _ ("Su,"), NULL);
				_g_free0 (weeks);
				weeks = _tmp25_;
			}
			_tmp26_ = weeks;
			_tmp27_ = weeks;
			_tmp28_ = g_utf8_strreverse (_tmp27_, (gssize) -1);
			_tmp29_ = _tmp28_;
			_tmp30_ = string_slice (_tmp26_, (glong) 0, (glong) (-string_index_of_nth_char (_tmp29_, (glong) 1)));
			_g_free0 (weeks);
			weeks = _tmp30_;
			_g_free0 (_tmp29_);
			_tmp31_ = returned;
			_tmp32_ = weeks;
			_tmp33_ = g_strdup_printf ("%s (%s)", _tmp31_, _tmp32_);
			_g_free0 (returned);
			returned = _tmp33_;
			_g_free0 (weeks);
		}
	}
	_tmp34_ = returned;
	_tmp35_ = g_strconcat (_tmp34_, " ", NULL);
	_tmp36_ = _tmp35_;
	_tmp37_ = g_strconcat (_tmp36_, end, NULL);
	_tmp38_ = _tmp37_;
	_g_free0 (_tmp36_);
	result = _tmp38_;
	_g_free0 (returned);
	return result;
}

GDateTime*
utils_datetime_get_today_format_date (void)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* result;
	_tmp0_ = g_date_time_new_now_local ();
	_tmp1_ = _tmp0_;
	_tmp2_ = utils_datetime_get_date_only (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_date_time_unref0 (_tmp1_);
	result = _tmp3_;
	return result;
}

GDateTime*
utils_datetime_get_date_only (GDateTime* date)
{
	GDateTime* _tmp0_;
	GDateTime* result;
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = g_date_time_new_local (g_date_time_get_year (date), g_date_time_get_month (date), g_date_time_get_day_of_month (date), 0, 0, (gdouble) 0);
	result = _tmp0_;
	return result;
}

gchar*
utils_datetime_get_default_date_format_from_date (GDateTime* date)
{
	gchar* format = NULL;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* result;
	if (date == NULL) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("");
		result = _tmp0_;
		return result;
	}
	_tmp1_ = g_date_time_new_now_local ();
	_tmp2_ = _tmp1_;
	_tmp3_ = utils_datetime_get_default_date_format (FALSE, TRUE, g_date_time_get_year (date) != g_date_time_get_year (_tmp2_));
	_tmp4_ = _tmp3_;
	_tmp5_ = g_date_time_format (date, _tmp4_);
	_tmp6_ = _tmp5_;
	_g_free0 (_tmp4_);
	_g_date_time_unref0 (_tmp2_);
	format = _tmp6_;
	result = format;
	return result;
}

gchar*
utils_datetime_get_todoist_datetime_format (GDateTime* date)
{
	gchar* returned = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = g_strdup ("");
	returned = _tmp0_;
	if (utils_datetime_has_time (date)) {
		gchar* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp1_ = g_date_time_format (date, "%F");
		_tmp2_ = _tmp1_;
		_tmp3_ = g_strconcat (_tmp2_, "T", NULL);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_date_time_format (date, "%T");
		_tmp6_ = _tmp5_;
		_tmp7_ = g_strconcat (_tmp4_, _tmp6_, NULL);
		_g_free0 (returned);
		returned = _tmp7_;
		_g_free0 (_tmp6_);
		_g_free0 (_tmp4_);
		_g_free0 (_tmp2_);
	} else {
		gchar* _tmp8_;
		_tmp8_ = g_date_time_format (date, "%F");
		_g_free0 (returned);
		returned = _tmp8_;
	}
	result = returned;
	return result;
}

static gboolean
utils_datetime_is_iso_due_date (const gchar* date)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp7_ = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	if (date == NULL) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (date, "") == 0;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	{
		GRegex* _tmp1_;
		GRegex* _tmp6_;
		_tmp1_ = utils_datetime__iso_due_regex;
		if (_tmp1_ == NULL) {
			GRegex* _tmp2_ = NULL;
			GRegex* _tmp3_;
			GRegex* _tmp5_;
			_tmp3_ = g_regex_new ("^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2})?$", 0, 0, &_inner_error0_);
			_tmp2_ = _tmp3_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gboolean _tmp4_ = FALSE;
				if (_inner_error0_->domain == G_REGEX_ERROR) {
					goto __catch0_g_regex_error;
				}
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return _tmp4_;
			}
			_tmp5_ = _tmp2_;
			_tmp2_ = NULL;
			_g_regex_unref0 (utils_datetime__iso_due_regex);
			utils_datetime__iso_due_regex = _tmp5_;
			_g_regex_unref0 (_tmp2_);
		}
		_tmp6_ = utils_datetime__iso_due_regex;
		result = g_regex_match (_tmp6_, date, 0, NULL);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		result = FALSE;
		return result;
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return _tmp7_;
}

gchar*
utils_datetime_due_to_todoist_natural_language (ObjectsDueDate* due)
{
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gboolean _tmp8_ = FALSE;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gboolean _tmp16_ = FALSE;
	gboolean _tmp17_ = FALSE;
	gboolean _tmp18_;
	gboolean _tmp19_;
	gchar* recurrency_type_string = NULL;
	gchar* _tmp30_;
	RecurrencyType _tmp31_;
	RecurrencyType _tmp32_;
	gchar** days = NULL;
	gchar* _tmp39_;
	gchar* _tmp40_;
	gchar* _tmp41_;
	gchar* _tmp42_;
	gchar* _tmp43_;
	gchar* _tmp44_;
	gchar* _tmp45_;
	gchar** _tmp46_;
	gint days_length1;
	gint _days_size_;
	gchar* returned = NULL;
	gchar* _tmp47_;
	gint _tmp48_;
	gint _tmp49_;
	gboolean _tmp73_ = FALSE;
	RecurrencyType _tmp74_;
	RecurrencyType _tmp75_;
	gboolean _tmp104_ = FALSE;
	GDateTime* _tmp105_;
	GDateTime* _tmp106_;
	const gchar* _tmp119_;
	const gchar* _tmp120_;
	gchar* result;
	g_return_val_if_fail (due != NULL, NULL);
	_tmp1_ = objects_due_date_get_recurrence_string (due);
	_tmp2_ = _tmp1_;
	if (g_strcmp0 (_tmp2_, "") != 0) {
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp3_ = objects_due_date_get_is_recurring (due);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp5_ = objects_due_date_get_recurrence_string (due);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_strdup (_tmp6_);
		result = _tmp7_;
		return result;
	}
	_tmp9_ = objects_due_date_get_date (due);
	_tmp10_ = _tmp9_;
	if (g_strcmp0 (_tmp10_, "") != 0) {
		const gchar* _tmp11_;
		const gchar* _tmp12_;
		_tmp11_ = objects_due_date_get_date (due);
		_tmp12_ = _tmp11_;
		_tmp8_ = !utils_datetime_is_iso_due_date (_tmp12_);
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		const gchar* _tmp13_;
		const gchar* _tmp14_;
		gchar* _tmp15_;
		_tmp13_ = objects_due_date_get_date (due);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_strdup (_tmp14_);
		result = _tmp15_;
		return result;
	}
	_tmp18_ = objects_due_date_get_is_recurring (due);
	_tmp19_ = _tmp18_;
	if (_tmp19_ == FALSE) {
		_tmp17_ = TRUE;
	} else {
		RecurrencyType _tmp20_;
		RecurrencyType _tmp21_;
		_tmp20_ = objects_due_date_get_recurrency_type (due);
		_tmp21_ = _tmp20_;
		_tmp17_ = _tmp21_ < RECURRENCY_TYPE_HOURLY;
	}
	if (_tmp17_) {
		_tmp16_ = TRUE;
	} else {
		RecurrencyType _tmp22_;
		RecurrencyType _tmp23_;
		_tmp22_ = objects_due_date_get_recurrency_type (due);
		_tmp23_ = _tmp22_;
		_tmp16_ = _tmp23_ > RECURRENCY_TYPE_EVERY_YEAR;
	}
	if (_tmp16_) {
		GDateTime* _tmp24_;
		GDateTime* _tmp25_;
		_tmp24_ = objects_due_date_get_datetime (due);
		_tmp25_ = _tmp24_;
		if (_tmp25_ != NULL) {
			GDateTime* _tmp26_;
			GDateTime* _tmp27_;
			gchar* _tmp28_;
			_tmp26_ = objects_due_date_get_datetime (due);
			_tmp27_ = _tmp26_;
			_tmp28_ = utils_datetime_get_todoist_datetime_format (_tmp27_);
			result = _tmp28_;
			return result;
		} else {
			gchar* _tmp29_;
			_tmp29_ = g_strdup ("");
			result = _tmp29_;
			return result;
		}
	}
	_tmp30_ = g_strdup ("");
	recurrency_type_string = _tmp30_;
	_tmp31_ = objects_due_date_get_recurrency_type (due);
	_tmp32_ = _tmp31_;
	switch (_tmp32_) {
		case RECURRENCY_TYPE_HOURLY:
		{
			gchar* _tmp33_;
			_tmp33_ = g_strdup ("hour");
			_g_free0 (recurrency_type_string);
			recurrency_type_string = _tmp33_;
			break;
		}
		case RECURRENCY_TYPE_EVERY_DAY:
		{
			gchar* _tmp34_;
			_tmp34_ = g_strdup ("day");
			_g_free0 (recurrency_type_string);
			recurrency_type_string = _tmp34_;
			break;
		}
		case RECURRENCY_TYPE_EVERY_WEEK:
		{
			gchar* _tmp35_;
			_tmp35_ = g_strdup ("week");
			_g_free0 (recurrency_type_string);
			recurrency_type_string = _tmp35_;
			break;
		}
		case RECURRENCY_TYPE_EVERY_MONTH:
		{
			gchar* _tmp36_;
			_tmp36_ = g_strdup ("month");
			_g_free0 (recurrency_type_string);
			recurrency_type_string = _tmp36_;
			break;
		}
		case RECURRENCY_TYPE_EVERY_YEAR:
		{
			gchar* _tmp37_;
			_tmp37_ = g_strdup ("year");
			_g_free0 (recurrency_type_string);
			recurrency_type_string = _tmp37_;
			break;
		}
		default:
		{
			gchar* _tmp38_;
			_tmp38_ = g_strdup ("day");
			_g_free0 (recurrency_type_string);
			recurrency_type_string = _tmp38_;
			break;
		}
	}
	_tmp39_ = g_strdup ("mon,");
	_tmp40_ = g_strdup ("tue,");
	_tmp41_ = g_strdup ("wed,");
	_tmp42_ = g_strdup ("thu,");
	_tmp43_ = g_strdup ("fri,");
	_tmp44_ = g_strdup ("sat,");
	_tmp45_ = g_strdup ("sun,");
	_tmp46_ = g_new0 (gchar*, 7 + 1);
	_tmp46_[0] = _tmp39_;
	_tmp46_[1] = _tmp40_;
	_tmp46_[2] = _tmp41_;
	_tmp46_[3] = _tmp42_;
	_tmp46_[4] = _tmp43_;
	_tmp46_[5] = _tmp44_;
	_tmp46_[6] = _tmp45_;
	days = _tmp46_;
	days_length1 = 7;
	_days_size_ = days_length1;
	_tmp47_ = g_strdup ("every ");
	returned = _tmp47_;
	_tmp48_ = objects_due_date_get_recurrency_interval (due);
	_tmp49_ = _tmp48_;
	if (_tmp49_ > 1) {
		const gchar* _tmp50_;
		gint _tmp51_;
		gint _tmp52_;
		gchar* _tmp53_;
		gchar* _tmp54_;
		gchar* _tmp55_;
		gchar* _tmp56_;
		gchar* _tmp57_;
		const gchar* _tmp58_;
		const gchar* _tmp59_;
		gchar* _tmp60_;
		const gchar* _tmp61_;
		gchar* _tmp62_;
		_tmp50_ = returned;
		_tmp51_ = objects_due_date_get_recurrency_interval (due);
		_tmp52_ = _tmp51_;
		_tmp53_ = g_strdup_printf ("%i", _tmp52_);
		_tmp54_ = _tmp53_;
		_tmp55_ = g_strconcat (_tmp54_, " ", NULL);
		_tmp56_ = _tmp55_;
		_tmp57_ = g_strconcat (_tmp50_, _tmp56_, NULL);
		_g_free0 (returned);
		returned = _tmp57_;
		_g_free0 (_tmp56_);
		_g_free0 (_tmp54_);
		_tmp58_ = returned;
		_tmp59_ = recurrency_type_string;
		_tmp60_ = g_strconcat (_tmp58_, _tmp59_, NULL);
		_g_free0 (returned);
		returned = _tmp60_;
		_tmp61_ = returned;
		_tmp62_ = g_strconcat (_tmp61_, "s ", NULL);
		_g_free0 (returned);
		returned = _tmp62_;
	} else {
		gboolean _tmp63_ = FALSE;
		RecurrencyType _tmp64_;
		RecurrencyType _tmp65_;
		_tmp64_ = objects_due_date_get_recurrency_type (due);
		_tmp65_ = _tmp64_;
		if (_tmp65_ == RECURRENCY_TYPE_EVERY_WEEK) {
			const gchar* _tmp66_;
			const gchar* _tmp67_;
			_tmp66_ = objects_due_date_get_recurrency_weeks (due);
			_tmp67_ = _tmp66_;
			_tmp63_ = g_strcmp0 (_tmp67_, "") != 0;
		} else {
			_tmp63_ = FALSE;
		}
		if (!_tmp63_) {
			const gchar* _tmp68_;
			const gchar* _tmp69_;
			gchar* _tmp70_;
			gchar* _tmp71_;
			gchar* _tmp72_;
			_tmp68_ = returned;
			_tmp69_ = recurrency_type_string;
			_tmp70_ = g_strconcat (_tmp69_, " ", NULL);
			_tmp71_ = _tmp70_;
			_tmp72_ = g_strconcat (_tmp68_, _tmp71_, NULL);
			_g_free0 (returned);
			returned = _tmp72_;
			_g_free0 (_tmp71_);
		}
	}
	_tmp74_ = objects_due_date_get_recurrency_type (due);
	_tmp75_ = _tmp74_;
	if (_tmp75_ == RECURRENCY_TYPE_EVERY_WEEK) {
		const gchar* _tmp76_;
		const gchar* _tmp77_;
		_tmp76_ = objects_due_date_get_recurrency_weeks (due);
		_tmp77_ = _tmp76_;
		_tmp73_ = g_strcmp0 (_tmp77_, "") != 0;
	} else {
		_tmp73_ = FALSE;
	}
	if (_tmp73_) {
		const gchar* _tmp78_;
		const gchar* _tmp79_;
		_tmp78_ = objects_due_date_get_recurrency_weeks (due);
		_tmp79_ = _tmp78_;
		if (g_strcmp0 (_tmp79_, "1,2,3,4,5") == 0) {
			const gchar* _tmp80_;
			gchar* _tmp81_;
			gint _tmp82_;
			gint _tmp83_;
			const gchar* _tmp86_;
			gchar* _tmp87_;
			_tmp80_ = returned;
			_tmp81_ = g_strconcat (_tmp80_, "weekday", NULL);
			_g_free0 (returned);
			returned = _tmp81_;
			_tmp82_ = objects_due_date_get_recurrency_interval (due);
			_tmp83_ = _tmp82_;
			if (_tmp83_ > 1) {
				const gchar* _tmp84_;
				gchar* _tmp85_;
				_tmp84_ = returned;
				_tmp85_ = g_strconcat (_tmp84_, "s", NULL);
				_g_free0 (returned);
				returned = _tmp85_;
			}
			_tmp86_ = returned;
			_tmp87_ = g_strconcat (_tmp86_, " ", NULL);
			_g_free0 (returned);
			returned = _tmp87_;
		} else {
			gchar** selected_days = NULL;
			const gchar* _tmp88_;
			const gchar* _tmp89_;
			gchar** _tmp90_;
			gchar** _tmp91_;
			gint selected_days_length1;
			gint _selected_days_size_;
			gchar** _tmp92_;
			gint _tmp92__length1;
			const gchar* _tmp100_;
			gchar* _tmp101_;
			gchar* _tmp102_;
			gchar* _tmp103_;
			_tmp88_ = objects_due_date_get_recurrency_weeks (due);
			_tmp89_ = _tmp88_;
			_tmp91_ = _tmp90_ = g_strsplit (_tmp89_, ",", 0);
			selected_days = _tmp91_;
			selected_days_length1 = _vala_array_length (_tmp90_);
			_selected_days_size_ = selected_days_length1;
			_tmp92_ = selected_days;
			_tmp92__length1 = selected_days_length1;
			{
				gchar** day_collection = NULL;
				gint day_collection_length1 = 0;
				gint _day_collection_size_ = 0;
				gint day_it = 0;
				day_collection = _tmp92_;
				day_collection_length1 = _tmp92__length1;
				for (day_it = 0; day_it < day_collection_length1; day_it = day_it + 1) {
					gchar* _tmp93_;
					gchar* day = NULL;
					_tmp93_ = g_strdup (day_collection[day_it]);
					day = _tmp93_;
					{
						gint dayint = 0;
						const gchar* _tmp94_;
						gboolean _tmp95_ = FALSE;
						const gchar* _tmp96_;
						gchar** _tmp97_;
						gint _tmp97__length1;
						const gchar* _tmp98_;
						gchar* _tmp99_;
						_tmp94_ = day;
						dayint = atoi (_tmp94_);
						if (dayint > 7) {
							_tmp95_ = TRUE;
						} else {
							_tmp95_ = dayint < 1;
						}
						if (_tmp95_) {
							_g_free0 (day);
							continue;
						}
						_tmp96_ = returned;
						_tmp97_ = days;
						_tmp97__length1 = days_length1;
						_tmp98_ = _tmp97_[dayint - 1];
						_tmp99_ = g_strconcat (_tmp96_, _tmp98_, NULL);
						_g_free0 (returned);
						returned = _tmp99_;
						_g_free0 (day);
					}
				}
			}
			_tmp100_ = returned;
			_tmp101_ = string_slice (_tmp100_, (glong) 0, (glong) -1);
			_tmp102_ = _tmp101_;
			_tmp103_ = g_strconcat (_tmp102_, " ", NULL);
			_g_free0 (returned);
			returned = _tmp103_;
			_g_free0 (_tmp102_);
			selected_days = (_vala_array_free (selected_days, selected_days_length1, (GDestroyNotify) g_free), NULL);
		}
	}
	_tmp105_ = objects_due_date_get_datetime (due);
	_tmp106_ = _tmp105_;
	if (_tmp106_ != NULL) {
		GDateTime* _tmp107_;
		GDateTime* _tmp108_;
		_tmp107_ = objects_due_date_get_datetime (due);
		_tmp108_ = _tmp107_;
		_tmp104_ = utils_datetime_has_time (_tmp108_);
	} else {
		_tmp104_ = FALSE;
	}
	if (_tmp104_) {
		const gchar* _tmp109_;
		gchar* _tmp110_;
		gchar* time = NULL;
		GDateTime* _tmp111_;
		GDateTime* _tmp112_;
		gchar* _tmp113_;
		const gchar* _tmp114_;
		const gchar* _tmp115_;
		gchar* _tmp116_;
		gchar* _tmp117_;
		gchar* _tmp118_;
		_tmp109_ = returned;
		_tmp110_ = g_strconcat (_tmp109_, "at ", NULL);
		_g_free0 (returned);
		returned = _tmp110_;
		_tmp111_ = objects_due_date_get_datetime (due);
		_tmp112_ = _tmp111_;
		_tmp113_ = g_date_time_format (_tmp112_, "%T");
		time = _tmp113_;
		_tmp114_ = returned;
		_tmp115_ = time;
		_tmp116_ = string_slice (_tmp115_, (glong) 0, (glong) -3);
		_tmp117_ = _tmp116_;
		_tmp118_ = g_strconcat (_tmp114_, _tmp117_, NULL);
		_g_free0 (returned);
		returned = _tmp118_;
		_g_free0 (_tmp117_);
		_g_free0 (time);
	}
	_tmp119_ = objects_due_date_get_recurrency_end (due);
	_tmp120_ = _tmp119_;
	if (g_strcmp0 (_tmp120_, "") != 0) {
		const gchar* _tmp121_;
		gchar* _tmp122_;
		const gchar* _tmp123_;
		GDateTime* _tmp124_;
		GDateTime* _tmp125_;
		gchar* _tmp126_;
		gchar* _tmp127_;
		gchar* _tmp128_;
		_tmp121_ = returned;
		_tmp122_ = g_strconcat (_tmp121_, "until ", NULL);
		_g_free0 (returned);
		returned = _tmp122_;
		_tmp123_ = returned;
		_tmp124_ = objects_due_date_get_end_datetime (due);
		_tmp125_ = _tmp124_;
		_tmp126_ = g_date_time_format (_tmp125_, "%F");
		_tmp127_ = _tmp126_;
		_tmp128_ = g_strconcat (_tmp123_, _tmp127_, NULL);
		_g_free0 (returned);
		returned = _tmp128_;
		_g_free0 (_tmp127_);
	}
	result = returned;
	days = (_vala_array_free (days, days_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (recurrency_type_string);
	return result;
}

gboolean
utils_datetime_has_time_from_string (const gchar* date)
{
	GTimeZone* _tmp0_;
	GTimeZone* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	_tmp0_ = g_time_zone_new_local ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_date_time_new_from_iso8601 (date, _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = utils_datetime_has_time (_tmp3_);
	_g_date_time_unref0 (_tmp3_);
	_g_time_zone_unref0 (_tmp1_);
	result = _tmp4_;
	return result;
}

gint
utils_datetime_get_days_of_month (gint index,
                                  gint year_nav)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	gint result;
	if (index == 1) {
		_tmp5_ = TRUE;
	} else {
		_tmp5_ = index == 3;
	}
	if (_tmp5_) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = index == 5;
	}
	if (_tmp4_) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = index == 7;
	}
	if (_tmp3_) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = index == 8;
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = index == 10;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = index == 12;
	}
	if (_tmp0_) {
		result = 31;
		return result;
	} else {
		if (index == 2) {
			if ((year_nav % 4) == 0) {
				result = 29;
				return result;
			} else {
				result = 28;
				return result;
			}
		} else {
			result = 30;
			return result;
		}
	}
}

GDateTime*
utils_datetime_get_start_of_month (GDateTime* date)
{
	GDateTime* _tmp1_;
	GDateTime* result;
	if (date == NULL) {
		GDateTime* _tmp0_;
		_tmp0_ = g_date_time_new_now_local ();
		_g_date_time_unref0 (date);
		date = _tmp0_;
	}
	_tmp1_ = g_date_time_new_local (g_date_time_get_year (date), g_date_time_get_month (date), 1, 0, 0, (gdouble) 0);
	result = _tmp1_;
	_g_date_time_unref0 (date);
	return result;
}

gboolean
utils_datetime_is_current_month (GDateTime* date)
{
	GDateTime* now = NULL;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	gboolean result;
	g_return_val_if_fail (date != NULL, FALSE);
	_tmp0_ = g_date_time_new_now_local ();
	now = _tmp0_;
	_tmp1_ = now;
	if (g_date_time_get_year (date) == g_date_time_get_year (_tmp1_)) {
		GDateTime* _tmp2_;
		_tmp2_ = now;
		if (g_date_time_get_month (date) == g_date_time_get_month (_tmp2_)) {
			result = TRUE;
			_g_date_time_unref0 (now);
			return result;
		} else {
			result = FALSE;
			_g_date_time_unref0 (now);
			return result;
		}
	} else {
		result = FALSE;
		_g_date_time_unref0 (now);
		return result;
	}
}

/**
     * Converts the given ICal.Time to a GLib.DateTime, represented in the
     * system timezone.
     *
     * All timezone information in the original @date is lost. However, the
     * {@link GLib.TimeZone} contained in the resulting DateTime is correct,
     * since there is a well-defined local timezone between both libical and
     * GLib.
     */
GDateTime*
utils_datetime_ical_to_date_time_local (ICalTime* date)
{
	ICalTime* converted = NULL;
	ICalTime* _tmp0_;
	gint year = 0;
	gint month = 0;
	gint day = 0;
	gint hour = 0;
	gint minute = 0;
	gint second = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	gint _tmp4_ = 0;
	gint _tmp5_ = 0;
	gint _tmp6_ = 0;
	GDateTime* _tmp7_;
	GDateTime* result;
	g_return_val_if_fail (date != NULL, NULL);
	_vala_assert (!i_cal_time_is_null_time (date), "!date.is_null_time ()");
	_tmp0_ = utils_datetime_ical_convert_to_local (date);
	converted = _tmp0_;
	i_cal_time_get_date (converted, &_tmp1_, &_tmp2_, &_tmp3_);
	year = _tmp1_;
	month = _tmp2_;
	day = _tmp3_;
	i_cal_time_get_time (converted, &_tmp4_, &_tmp5_, &_tmp6_);
	hour = _tmp4_;
	minute = _tmp5_;
	second = _tmp6_;
	_tmp7_ = g_date_time_new_local (year, month, day, hour, minute, (gdouble) second);
	result = _tmp7_;
	_g_object_unref0 (converted);
	return result;
}

/** Converts the given ICal.Time to the local (or system) timezone */
ICalTime*
utils_datetime_ical_convert_to_local (ICalTime* time)
{
	ICalTimezone* system_tz = NULL;
	ICalTimezone* _tmp0_;
	ICalTime* _tmp1_;
	ICalTime* result;
	g_return_val_if_fail (time != NULL, NULL);
	_tmp0_ = utils_datetime_get_system_timezone ();
	system_tz = _tmp0_;
	_tmp1_ = i_cal_time_convert_to_zone (time, system_tz);
	result = _tmp1_;
	_g_object_unref0 (system_tz);
	return result;
}

/**
     * Converts two DateTimes representing a date and a time to one TimeType.
     *
     * The first contains the date; its time settings are ignored. The second
     * one contains the time itself; its date settings are ignored. If the time
     * is `null`, the resulting TimeType is of `DATE` type; if it is given, the
     * TimeType is of `DATE-TIME` type.
     *
     * This also accepts an optional `timezone` argument. If it is given a
     * timezone, the resulting TimeType will be relative to the given timezone.
     * If it is `null`, the resulting TimeType will be "floating" with no
     * timezone. If the argument is not given, it will default to the system
     * timezone.
     */
ICalTime*
utils_datetime_datetimes_to_icaltime (GDateTime* date,
                                      GDateTime* time_local,
                                      ICalTimezone* timezone)
{
	ICalTime* _result_ = NULL;
	ICalTime* _tmp0_;
	ICalTime* result;
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = i_cal_time_new_from_day_of_year (g_date_time_get_day_of_year (date), g_date_time_get_year (date));
	_result_ = _tmp0_;
	if (time_local == NULL) {
		ICalTime* _tmp1_;
		_tmp1_ = _result_;
		i_cal_time_set_is_date (_tmp1_, TRUE);
	} else {
		ICalTime* _tmp2_;
		ICalTime* _tmp3_;
		ICalTime* _tmp4_;
		_tmp2_ = _result_;
		i_cal_time_set_is_date (_tmp2_, FALSE);
		_tmp3_ = _result_;
		i_cal_time_set_timezone (_tmp3_, timezone);
		_tmp4_ = _result_;
		i_cal_time_set_time (_tmp4_, g_date_time_get_hour (time_local), g_date_time_get_minute (time_local), g_date_time_get_second (time_local));
	}
	result = _result_;
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

ICalTimezone*
utils_datetime_get_system_timezone (void)
{
	ICalTimezone* _tmp0_;
	ICalTimezone* _tmp1_;
	ICalTimezone* result;
	_tmp0_ = e_cal_util_get_system_timezone ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

gchar*
utils_datetime_get_markdown_format_date (ObjectsItem* item)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	ObjectsDueDate* _tmp3_;
	ObjectsDueDate* _tmp4_;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* result;
	g_return_val_if_fail (item != NULL, NULL);
	_tmp0_ = objects_item_get_has_due (item);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (" ");
		result = _tmp2_;
		return result;
	}
	_tmp3_ = objects_item_get_due (item);
	_tmp4_ = _tmp3_;
	_tmp5_ = objects_due_date_get_datetime (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = utils_datetime_get_relative_date_from_date (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_strconcat (" (", _tmp8_, NULL);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_strconcat (_tmp10_, ") ", NULL);
	_tmp12_ = _tmp11_;
	_g_free0 (_tmp10_);
	_g_free0 (_tmp8_);
	result = _tmp12_;
	return result;
}

GDateTime*
utils_datetime_get_datetime_no_seconds (GDateTime* date,
                                        GDateTime* time)
{
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	GDateTime* _tmp2_;
	GDateTime* result;
	g_return_val_if_fail (date != NULL, NULL);
	if (time == NULL) {
		_tmp0_ = g_date_time_get_hour (date);
	} else {
		_tmp0_ = g_date_time_get_hour (time);
	}
	if (time == NULL) {
		_tmp1_ = g_date_time_get_minute (date);
	} else {
		_tmp1_ = g_date_time_get_minute (time);
	}
	_tmp2_ = g_date_time_new_local (g_date_time_get_year (date), g_date_time_get_month (date), g_date_time_get_day_of_month (date), _tmp0_, _tmp1_, (gdouble) 0);
	result = _tmp2_;
	return result;
}

gchar*
utils_datetime_get_relative_time_from_date (GDateTime* date)
{
	GDateTime* date_only = NULL;
	GDateTime* _tmp0_;
	GDateTime* today = NULL;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	gchar* relative_time = NULL;
	GDateTime* _tmp5_;
	gchar* result;
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = utils_datetime_get_date_only (date);
	date_only = _tmp0_;
	_tmp1_ = g_date_time_new_now_local ();
	_tmp2_ = _tmp1_;
	_tmp3_ = utils_datetime_get_date_only (_tmp2_);
	_tmp4_ = _tmp3_;
	_g_date_time_unref0 (_tmp2_);
	today = _tmp4_;
	_tmp5_ = date_only;
	if (utils_datetime_is_today (_tmp5_)) {
		gchar* _tmp6_;
		_tmp6_ = g_strdup (_ ("Today"));
		_g_free0 (relative_time);
		relative_time = _tmp6_;
	} else {
		GDateTime* _tmp7_;
		_tmp7_ = date_only;
		if (utils_datetime_is_tomorrow (_tmp7_)) {
			gchar* _tmp8_;
			_tmp8_ = g_strdup (_ ("Tomorrow"));
			_g_free0 (relative_time);
			relative_time = _tmp8_;
		} else {
			GDateTime* _tmp9_;
			_tmp9_ = date_only;
			if (utils_datetime_is_yesterday (_tmp9_)) {
				gchar* _tmp10_;
				_tmp10_ = g_strdup (_ ("Yesterday"));
				_g_free0 (relative_time);
				relative_time = _tmp10_;
			} else {
				gint days_diff = 0;
				GDateTime* _tmp11_;
				GDateTime* _tmp12_;
				_tmp11_ = date_only;
				_tmp12_ = today;
				days_diff = (gint) (g_date_time_difference (_tmp11_, _tmp12_) / G_TIME_SPAN_DAY);
				if (days_diff > 0) {
					gchar* _tmp13_;
					_tmp13_ = g_strdup_printf (ngettext ("in %d day", "in %d days", (gulong) days_diff), days_diff);
					_g_free0 (relative_time);
					relative_time = _tmp13_;
				} else {
					gchar* _tmp14_;
					_tmp14_ = g_strdup_printf (ngettext ("%d day ago", "%d days ago", (gulong) (-days_diff)), -days_diff);
					_g_free0 (relative_time);
					relative_time = _tmp14_;
				}
			}
		}
	}
	result = relative_time;
	_g_date_time_unref0 (today);
	_g_date_time_unref0 (date_only);
	return result;
}

gchar*
utils_datetime_get_short_date_format_from_date (GDateTime* date)
{
	GDateTime* date_only = NULL;
	GDateTime* _tmp0_;
	gchar* day_name = NULL;
	gchar* _tmp1_;
	gchar* day_month = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = utils_datetime_get_date_only (date);
	date_only = _tmp0_;
	_tmp1_ = g_date_time_format (date_only, "%a");
	day_name = _tmp1_;
	_tmp2_ = g_date_time_format (date_only, "%e %b");
	day_month = _tmp2_;
	_tmp3_ = g_strdup_printf ("%s, %s", day_name, day_month);
	result = _tmp3_;
	_g_free0 (day_month);
	_g_free0 (day_name);
	_g_date_time_unref0 (date_only);
	return result;
}

gchar*
utils_datetime_get_default_date_format (gboolean with_weekday,
                                        gboolean with_day,
                                        gboolean with_year)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gchar* _tmp24_;
	gchar* result;
	if (with_weekday == TRUE) {
		_tmp1_ = with_day == TRUE;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		_tmp0_ = with_year == TRUE;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (_ ("%a, %b %-e, %Y"));
		result = _tmp2_;
		return result;
	} else {
		gboolean _tmp3_ = FALSE;
		gboolean _tmp4_ = FALSE;
		if (with_weekday == FALSE) {
			_tmp4_ = with_day == TRUE;
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			_tmp3_ = with_year == TRUE;
		} else {
			_tmp3_ = FALSE;
		}
		if (_tmp3_) {
			gchar* _tmp5_;
			_tmp5_ = g_strdup (_ ("%b %-e %Y"));
			result = _tmp5_;
			return result;
		} else {
			gboolean _tmp6_ = FALSE;
			gboolean _tmp7_ = FALSE;
			if (with_weekday == FALSE) {
				_tmp7_ = with_day == FALSE;
			} else {
				_tmp7_ = FALSE;
			}
			if (_tmp7_) {
				_tmp6_ = with_year == TRUE;
			} else {
				_tmp6_ = FALSE;
			}
			if (_tmp6_) {
				gchar* _tmp8_;
				_tmp8_ = g_strdup (_ ("%Y"));
				result = _tmp8_;
				return result;
			} else {
				gboolean _tmp9_ = FALSE;
				gboolean _tmp10_ = FALSE;
				if (with_weekday == FALSE) {
					_tmp10_ = with_day == TRUE;
				} else {
					_tmp10_ = FALSE;
				}
				if (_tmp10_) {
					_tmp9_ = with_year == FALSE;
				} else {
					_tmp9_ = FALSE;
				}
				if (_tmp9_) {
					gchar* _tmp11_;
					_tmp11_ = g_strdup (_ ("%b %-e"));
					result = _tmp11_;
					return result;
				} else {
					gboolean _tmp12_ = FALSE;
					gboolean _tmp13_ = FALSE;
					if (with_weekday == TRUE) {
						_tmp13_ = with_day == FALSE;
					} else {
						_tmp13_ = FALSE;
					}
					if (_tmp13_) {
						_tmp12_ = with_year == TRUE;
					} else {
						_tmp12_ = FALSE;
					}
					if (_tmp12_) {
						gchar* _tmp14_;
						_tmp14_ = g_strdup (_ ("%a %Y"));
						result = _tmp14_;
						return result;
					} else {
						gboolean _tmp15_ = FALSE;
						gboolean _tmp16_ = FALSE;
						if (with_weekday == TRUE) {
							_tmp16_ = with_day == FALSE;
						} else {
							_tmp16_ = FALSE;
						}
						if (_tmp16_) {
							_tmp15_ = with_year == FALSE;
						} else {
							_tmp15_ = FALSE;
						}
						if (_tmp15_) {
							gchar* _tmp17_;
							_tmp17_ = g_strdup (_ ("%a"));
							result = _tmp17_;
							return result;
						} else {
							gboolean _tmp18_ = FALSE;
							gboolean _tmp19_ = FALSE;
							if (with_weekday == TRUE) {
								_tmp19_ = with_day == TRUE;
							} else {
								_tmp19_ = FALSE;
							}
							if (_tmp19_) {
								_tmp18_ = with_year == FALSE;
							} else {
								_tmp18_ = FALSE;
							}
							if (_tmp18_) {
								gchar* _tmp20_;
								_tmp20_ = g_strdup (_ ("%a, %b %-e"));
								result = _tmp20_;
								return result;
							} else {
								gboolean _tmp21_ = FALSE;
								gboolean _tmp22_ = FALSE;
								if (with_weekday == FALSE) {
									_tmp22_ = with_day == FALSE;
								} else {
									_tmp22_ = FALSE;
								}
								if (_tmp22_) {
									_tmp21_ = with_year == FALSE;
								} else {
									_tmp21_ = FALSE;
								}
								if (_tmp21_) {
									gchar* _tmp23_;
									_tmp23_ = g_strdup (_ ("%b"));
									result = _tmp23_;
									return result;
								}
							}
						}
					}
				}
			}
		}
	}
	_tmp24_ = g_strdup ("");
	result = _tmp24_;
	return result;
}

UtilsDatetime*
utils_datetime_construct (GType object_type)
{
	UtilsDatetime* self = NULL;
	self = (UtilsDatetime*) g_type_create_instance (object_type);
	return self;
}

UtilsDatetime*
utils_datetime_new (void)
{
	return utils_datetime_construct (UTILS_TYPE_DATETIME);
}

static void
utils_value_datetime_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
utils_value_datetime_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		utils_datetime_unref (value->data[0].v_pointer);
	}
}

static void
utils_value_datetime_copy_value (const GValue* src_value,
                                 GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = utils_datetime_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
utils_value_datetime_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
utils_value_datetime_collect_value (GValue* value,
                                    guint n_collect_values,
                                    GTypeCValue* collect_values,
                                    guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		UtilsDatetime * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = utils_datetime_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
utils_value_datetime_lcopy_value (const GValue* value,
                                  guint n_collect_values,
                                  GTypeCValue* collect_values,
                                  guint collect_flags)
{
	UtilsDatetime ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = utils_datetime_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
utils_param_spec_datetime (const gchar* name,
                           const gchar* nick,
                           const gchar* blurb,
                           GType object_type,
                           GParamFlags flags)
{
	UtilsParamSpecDatetime* spec;
	g_return_val_if_fail (g_type_is_a (object_type, UTILS_TYPE_DATETIME), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
utils_value_get_datetime (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, UTILS_TYPE_DATETIME), NULL);
	return value->data[0].v_pointer;
}

void
utils_value_set_datetime (GValue* value,
                          gpointer v_object)
{
	UtilsDatetime * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, UTILS_TYPE_DATETIME));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, UTILS_TYPE_DATETIME));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		utils_datetime_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		utils_datetime_unref (old);
	}
}

void
utils_value_take_datetime (GValue* value,
                           gpointer v_object)
{
	UtilsDatetime * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, UTILS_TYPE_DATETIME));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, UTILS_TYPE_DATETIME));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		utils_datetime_unref (old);
	}
}

static void
utils_datetime_class_init (UtilsDatetimeClass * klass,
                           gpointer klass_data)
{
	utils_datetime_parent_class = g_type_class_peek_parent (klass);
	((UtilsDatetimeClass *) klass)->finalize = utils_datetime_finalize;
}

static void
utils_datetime_instance_init (UtilsDatetime * self,
                              gpointer klass)
{
	self->ref_count = 1;
}

static void
utils_datetime_finalize (UtilsDatetime * obj)
{
	UtilsDatetime * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, UTILS_TYPE_DATETIME, UtilsDatetime);
	g_signal_handlers_destroy (self);
}

static GType
utils_datetime_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { utils_value_datetime_init, utils_value_datetime_free_value, utils_value_datetime_copy_value, utils_value_datetime_peek_pointer, "p", utils_value_datetime_collect_value, "p", utils_value_datetime_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (UtilsDatetimeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) utils_datetime_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UtilsDatetime), 0, (GInstanceInitFunc) utils_datetime_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType utils_datetime_type_id;
	utils_datetime_type_id = g_type_register_fundamental (g_type_fundamental_next (), "UtilsDatetime", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return utils_datetime_type_id;
}

GType
utils_datetime_get_type (void)
{
	static volatile gsize utils_datetime_type_id__once = 0;
	if (g_once_init_enter (&utils_datetime_type_id__once)) {
		GType utils_datetime_type_id;
		utils_datetime_type_id = utils_datetime_get_type_once ();
		g_once_init_leave (&utils_datetime_type_id__once, utils_datetime_type_id);
	}
	return utils_datetime_type_id__once;
}

gpointer
utils_datetime_ref (gpointer instance)
{
	UtilsDatetime * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
utils_datetime_unref (gpointer instance)
{
	UtilsDatetime * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		UTILS_DATETIME_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

