[gnome-calendar/gbsneto/range: 8/12] utils: Make date comparison follow time comparison semantics
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/gbsneto/range: 8/12] utils: Make date comparison follow time comparison semantics
- Date: Tue, 14 Apr 2020 14:30:48 +0000 (UTC)
commit 13e40de65f43c8b9a252fab55bda1e85695550b2
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Apr 13 19:16:54 2020 -0300
utils: Make date comparison follow time comparison semantics
Right now, comparing dates with gcal_date_time_compare_date() gives
the exact opposite result of when comparing using g_date_time_compare().
As shown by this patch, this was a source of *many* bugs.
src/core/gcal-event.c | 4 ++--
src/gui/gcal-edit-dialog.c | 2 +-
src/gui/gcal-quick-add-popover.c | 2 +-
src/utils/gcal-date-time-utils.c | 4 ++--
src/views/gcal-month-view.c | 8 ++++----
5 files changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/src/core/gcal-event.c b/src/core/gcal-event.c
index a35ae48f..187cbb58 100644
--- a/src/core/gcal-event.c
+++ b/src/core/gcal-event.c
@@ -1884,8 +1884,8 @@ gcal_event_is_within_range (GcalEvent *self,
if (gcal_event_get_all_day (self))
{
- return gcal_date_time_compare_date (range_end, event_start) < 0 &&
- gcal_date_time_compare_date (range_start, event_end) > 0;
+ return gcal_date_time_compare_date (range_end, event_start) > 0 &&
+ gcal_date_time_compare_date (event_end, range_start) > 0;
}
return g_date_time_compare (range_end, event_start) > 0 &&
diff --git a/src/gui/gcal-edit-dialog.c b/src/gui/gcal-edit-dialog.c
index 993f868b..8c96fe80 100644
--- a/src/gui/gcal-edit-dialog.c
+++ b/src/gui/gcal-edit-dialog.c
@@ -402,7 +402,7 @@ format_datetime_for_display (GDateTime *date,
string = g_string_new ("");
now = g_date_time_new_now_local ();
- days_diff = gcal_date_time_compare_date (now, date);
+ days_diff = gcal_date_time_compare_date (date, now);
switch (days_diff)
{
diff --git a/src/gui/gcal-quick-add-popover.c b/src/gui/gcal-quick-add-popover.c
index 42c0a108..6852e147 100644
--- a/src/gui/gcal-quick-add-popover.c
+++ b/src/gui/gcal-quick-add-popover.c
@@ -1,6 +1,6 @@
/* gcal-quick-add-popover.c
*
- * Copyright (C) 2016 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ * Copyright (C) 2016-2020 Georges Basile Stavracas Neto <georges stavracas gmail com>
*
* 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
diff --git a/src/utils/gcal-date-time-utils.c b/src/utils/gcal-date-time-utils.c
index ac2791be..733e4109 100644
--- a/src/utils/gcal-date-time-utils.c
+++ b/src/utils/gcal-date-time-utils.c
@@ -1,6 +1,6 @@
/* gcal-date-time-utils.c
*
- * Copyright 2019 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ * Copyright 2019-2020 Georges Basile Stavracas Neto <georges stavracas gmail com>
*
* 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
@@ -148,7 +148,7 @@ gcal_date_time_compare_date (GDateTime *dt1,
g_date_time_get_month (dt2),
g_date_time_get_year (dt2));
- return g_date_days_between (&d1, &d2);
+ return g_date_days_between (&d2, &d1);
}
/**
diff --git a/src/views/gcal-month-view.c b/src/views/gcal-month-view.c
index 23c69dd0..c231a291 100644
--- a/src/views/gcal-month-view.c
+++ b/src/views/gcal-month-view.c
@@ -1,7 +1,7 @@
/* gcal-month-view.c
*
* Copyright © 2015 Erick Pérez Castellanos
- * 2017 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ * 2017-2020 Georges Basile Stavracas Neto <georges stavracas gmail com>
*
* 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
@@ -1000,15 +1000,15 @@ update_month_cells (GcalMonthView *self)
selection_end = selection_start;
/* Swap dates if end is before start */
- if (gcal_date_time_compare_date (selection_end, selection_start) < 0)
+ if (gcal_date_time_compare_date (selection_start, selection_end) < 0)
{
GDateTime *aux = selection_end;
selection_end = selection_start;
selection_start = aux;
}
- selected = gcal_date_time_compare_date (gcal_month_cell_get_date (cell), selection_start) >= 0
&&
- gcal_date_time_compare_date (gcal_month_cell_get_date (cell), selection_end) <= 0;
+ selected = gcal_date_time_compare_date (selection_start, gcal_month_cell_get_date (cell)) >= 0
&&
+ gcal_date_time_compare_date (selection_end, gcal_month_cell_get_date (cell)) <= 0;
}
gcal_month_cell_set_selected (cell, selected);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]