~huxuan/gtg/port-to-gtk3-py3

« back to all changes in this revision

Viewing changes to GTG/tools/dates.py

  • Committer: huxuan
  • Date: 2013-09-01 08:11:28 UTC
  • Revision ID: i@huxuan.org-20130901081128-t4n3gz2ivu52xhbl
resolve some cmp related bug

Show diffs side-by-side

added added

removed removed

Lines of Context:
153
153
        else:
154
154
            return other - self.date()
155
155
 
156
 
    def __cmp__(self, other):
157
 
        """ Compare with other Date instance """
158
 
        if isinstance(other, Date):
159
 
            comparison = cmp(self.date(), other.date())
160
 
 
161
 
            # Keep fuzzy dates below normal dates
162
 
            if comparison == 0:
163
 
                if self.is_fuzzy() and not other.is_fuzzy():
164
 
                    return 1
165
 
                elif not self.is_fuzzy() and other.is_fuzzy():
166
 
                    return -1
167
 
 
168
 
            return comparison
169
 
        elif isinstance(other, datetime.date):
170
 
            return cmp(self.date(), other)
171
 
        else:
172
 
            raise NotImplementedError
 
156
    def __lt__(self, other):
 
157
        """ Judge whehter less than other Date instance """
 
158
        if isinstance(other, Date):
 
159
            td = self.date() - other.date()
 
160
 
 
161
            # Keep fuzzy dates below normal dates
 
162
            if td == datetime.timedelta(0):
 
163
                if self.is_fuzzy() and not other.is_fuzzy():
 
164
                    return True
 
165
                elif not self.is_fuzzy() and other.is_fuzzy():
 
166
                    return False
 
167
 
 
168
            return self.date() < other.date()
 
169
        elif isinstance(other, datetime.date):
 
170
            return self.date() < other
 
171
        else:
 
172
            raise NotImplementedError
 
173
        pass
 
174
 
 
175
    def __gt__(self, other):
 
176
        """ Judge whehter greater than other Date instance """
 
177
        if isinstance(other, Date):
 
178
            td = other.date() - self.date()
 
179
 
 
180
            # Keep fuzzy dates below normal dates
 
181
            if td == datetime.timedelta(0):
 
182
                if self.is_fuzzy() and not other.is_fuzzy():
 
183
                    return False
 
184
                elif not self.is_fuzzy() and other.is_fuzzy():
 
185
                    return True
 
186
 
 
187
            return other.date() < self.date()
 
188
        elif isinstance(other, datetime.date):
 
189
            return other < self.date()
 
190
        else:
 
191
            raise NotImplementedError
 
192
        pass
173
193
 
174
194
    def __str__(self):
175
195
        if self._fuzzy is not None: