utils: gained compare API
This commit is contained in:
@@ -409,6 +409,43 @@ icaltime_compare_date (const icaltimetype *date1,
|
|||||||
time_day_of_year (date2->day, date2->month - 1, date2->year);
|
time_day_of_year (date2->day, date2->month - 1, date2->year);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint
|
||||||
|
icaltime_compare_with_current (const icaltimetype *date1,
|
||||||
|
const icaltimetype *date2,
|
||||||
|
time_t *current_time_t)
|
||||||
|
{
|
||||||
|
gint result;
|
||||||
|
|
||||||
|
time_t start1, start2, diff1, diff2;
|
||||||
|
start1 = icaltime_as_timet_with_zone (*date1, date1->zone != NULL ? date1->zone : e_cal_util_get_system_timezone ());
|
||||||
|
start2 = icaltime_as_timet_with_zone (*date2, date2->zone != NULL ? date2->zone : e_cal_util_get_system_timezone ());
|
||||||
|
diff1 = start1 - *current_time_t;
|
||||||
|
diff2 = start2 - *current_time_t;
|
||||||
|
|
||||||
|
if (diff1 == diff2)
|
||||||
|
{
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (diff1 == 0)
|
||||||
|
result = -1;
|
||||||
|
else if (diff2 == 0)
|
||||||
|
result = 1;
|
||||||
|
|
||||||
|
if (diff1 > 0 && diff2 < 0)
|
||||||
|
result = -1;
|
||||||
|
else if (diff2 > 0 && diff1 < 0)
|
||||||
|
result = 1;
|
||||||
|
else if (diff1 < 0 && diff2 < 0)
|
||||||
|
result = ABS (diff1) - ABS (diff2);
|
||||||
|
else if (diff1 > 0 && diff2 > 0)
|
||||||
|
result = diff1 - diff2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* Function to do a last minute fixup of the AM/PM stuff if the locale
|
/* Function to do a last minute fixup of the AM/PM stuff if the locale
|
||||||
* and gettext haven't done it right. Most English speaking countries
|
* and gettext haven't done it right. Most English speaking countries
|
||||||
* except the USA use the 24 hour clock (UK, Australia etc). However
|
* except the USA use the 24 hour clock (UK, Australia etc). However
|
||||||
|
|||||||
@@ -83,6 +83,10 @@ ECalComponent* build_component_from_details (const gchar
|
|||||||
gint icaltime_compare_date (const icaltimetype *date1,
|
gint icaltime_compare_date (const icaltimetype *date1,
|
||||||
const icaltimetype *date2);
|
const icaltimetype *date2);
|
||||||
|
|
||||||
|
gint icaltime_compare_with_current (const icaltimetype *date1,
|
||||||
|
const icaltimetype *date2,
|
||||||
|
time_t *current_time_t);
|
||||||
|
|
||||||
/* code brought from evolution */
|
/* code brought from evolution */
|
||||||
gsize e_strftime_fix_am_pm (gchar *str,
|
gsize e_strftime_fix_am_pm (gchar *str,
|
||||||
gsize max,
|
gsize max,
|
||||||
|
|||||||
Reference in New Issue
Block a user