[gnome-music/wip/jfelder/datetime-compare] coremodel: Use g_date_time_compare to sort playlists




commit 3ebf64648899e1a3d53846df871cca99a0931b91
Author: Jean Felder <jfelder src gnome org>
Date:   Mon Mar 15 13:59:56 2021 +0100

    coremodel: Use g_date_time_compare to sort playlists
    
    The correct annotation to use this function has been introduced in
    GLib 2.67.1.

 gnomemusic/coremodel.py | 11 +++--------
 meson.build             |  1 +
 2 files changed, 4 insertions(+), 8 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 1c109a50c..b9110a8d4 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -24,12 +24,11 @@
 
 from __future__ import annotations
 from typing import Optional, Union
-import math
 import typing
 
 import gi
 gi.require_version("Gfm", "0.1")
-from gi.repository import GObject, Gio, Gfm, Gtk
+from gi.repository import GLib, GObject, Gio, Gfm, Gtk
 
 from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.coreartist import CoreArtist
@@ -205,12 +204,8 @@ class CoreModel(GObject.GObject):
         if playlist_b.props.is_smart:
             return 1
 
-        # cannot use GLib.DateTime.compare
-        # https://gitlab.gnome.org/GNOME/pygobject/issues/334
-        # newest first
-        date_diff = playlist_b.props.creation_date.difference(
-            playlist_a.props.creation_date)
-        return math.copysign(1, date_diff)
+        return GLib.DateTime.compare(
+            playlist_b.props.creation_date, playlist_a.props.creation_date)
 
     def _set_player_model(self, playlist_type, model):
         """Set the model for PlayerPlaylist to use
diff --git a/meson.build b/meson.build
index 90ae29db7..c9f54f396 100644
--- a/meson.build
+++ b/meson.build
@@ -41,6 +41,7 @@ PKGDATA_DIR = join_paths(get_option('prefix'), get_option('datadir'), APPLICATIO
 PKGLIB_DIR = join_paths(get_option('prefix'), get_option('libdir'), APPLICATION_ID)
 
 # Dependencies
+dependency('glib-2.0', version: '>= 2.67.1')
 dependency('goa-1.0', version: '>= 3.35.90')
 dependency('gobject-introspection-1.0', version: '>= 1.35.0')
 dependency('gtk+-3.0', version: '>= 3.24.13')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]