mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
datetime: Fix hashing
Convert to the epoch, just like we do when checking for equality, so that timezones are correctly handled. https://bugzilla.gnome.org/show_bug.cgi?id=50076
This commit is contained in:
parent
3e9fb52214
commit
909289c763
@ -1516,43 +1516,6 @@ g_date_time_difference (const GDateTime *begin,
|
||||
* USEC_PER_DAY) + ((gint64) end->usec - (gint64) begin->usec);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_date_time_equal:
|
||||
* @dt1: a #GDateTime
|
||||
* @dt2: a #GDateTime
|
||||
*
|
||||
* Checks to see if @dt1 and @dt2 are equal.
|
||||
*
|
||||
* Equal here means that they represent the same moment after converting
|
||||
* them to the same timezone.
|
||||
*
|
||||
* Return value: %TRUE if @dt1 and @dt2 are equal
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
gboolean
|
||||
g_date_time_equal (gconstpointer dt1,
|
||||
gconstpointer dt2)
|
||||
{
|
||||
const GDateTime *a, *b;
|
||||
GDateTime *a_utc, *b_utc;
|
||||
gint64 a_epoch, b_epoch;
|
||||
|
||||
a = dt1;
|
||||
b = dt2;
|
||||
|
||||
a_utc = g_date_time_to_utc (a);
|
||||
b_utc = g_date_time_to_utc (b);
|
||||
|
||||
a_epoch = g_date_time_to_epoch (a_utc);
|
||||
b_epoch = g_date_time_to_epoch (b_utc);
|
||||
|
||||
g_date_time_unref (a_utc);
|
||||
g_date_time_unref (b_utc);
|
||||
|
||||
return a_epoch == b_epoch;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_date_time_get_day_of_week:
|
||||
* @datetime: a #GDateTime
|
||||
@ -1994,7 +1957,51 @@ g_date_time_get_year (const GDateTime *datetime)
|
||||
guint
|
||||
g_date_time_hash (gconstpointer datetime)
|
||||
{
|
||||
return (guint) (*((guint64 *) datetime));
|
||||
GDateTime *dt_utc;
|
||||
gint64 epoch;
|
||||
|
||||
dt_utc = g_date_time_to_utc (datetime);
|
||||
epoch = g_date_time_to_epoch (dt_utc);
|
||||
g_date_time_unref (dt_utc);
|
||||
|
||||
return (guint) epoch;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_date_time_equal:
|
||||
* @dt1: a #GDateTime
|
||||
* @dt2: a #GDateTime
|
||||
*
|
||||
* Checks to see if @dt1 and @dt2 are equal.
|
||||
*
|
||||
* Equal here means that they represent the same moment after converting
|
||||
* them to the same timezone.
|
||||
*
|
||||
* Return value: %TRUE if @dt1 and @dt2 are equal
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
gboolean
|
||||
g_date_time_equal (gconstpointer dt1,
|
||||
gconstpointer dt2)
|
||||
{
|
||||
const GDateTime *a, *b;
|
||||
GDateTime *a_utc, *b_utc;
|
||||
gint64 a_epoch, b_epoch;
|
||||
|
||||
a = dt1;
|
||||
b = dt2;
|
||||
|
||||
a_utc = g_date_time_to_utc (a);
|
||||
b_utc = g_date_time_to_utc (b);
|
||||
|
||||
a_epoch = g_date_time_to_epoch (a_utc);
|
||||
b_epoch = g_date_time_to_epoch (b_utc);
|
||||
|
||||
g_date_time_unref (a_utc);
|
||||
g_date_time_unref (b_utc);
|
||||
|
||||
return a_epoch == b_epoch;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user