示例#1
0
文件: gpstime.py 项目: kundor/gpsdata
 def __lt__(self, other):
     if self.utcoffset() is None and other.utcoffset() is None:
         return datetime.__lt__(self, other)
     elif self.utcoffset() is not None and other.utcoffset() is not None:
         us = datetime.__sub__(self.replace(tzinfo=None), self.utcoffset())
         uo = datetime.__sub__(other.replace(tzinfo=None), other.utcoffset())
         return us < uo
     else:
         raise TypeError("Can't compare naive and aware datetimes")
示例#2
0
文件: gpstime.py 项目: kundor/gpsdata
 def __eq__(self, other):
     if self.utcoffset() is None and other.utcoffset() is None:
         return datetime.__eq__(self, other)
     elif self.utcoffset() is None or other.utcoffset() is None:
         raise TypeError('Cannot compare naive and aware datetimes')
     else:
         us = datetime.__sub__(self.replace(tzinfo=None), self.utcoffset())
         uo = datetime.__sub__(other.replace(tzinfo=None), other.utcoffset())
         return us == uo
示例#3
0
 def __eq__(self, other):
     if self.utcoffset() is None and other.utcoffset() is None:
         return datetime.__eq__(self, other)
     elif self.utcoffset() is None or other.utcoffset() is None:
         raise TypeError('Cannot compare naive and aware datetimes')
     else:
         us = datetime.__sub__(self.replace(tzinfo=None), self.utcoffset())
         uo = datetime.__sub__(other.replace(tzinfo=None),
                               other.utcoffset())
         return us == uo
示例#4
0
 def __lt__(self, other):
     if self.utcoffset() is None and other.utcoffset() is None:
         return datetime.__lt__(self, other)
     elif self.utcoffset() is not None and other.utcoffset() is not None:
         us = datetime.__sub__(self.replace(tzinfo=None), self.utcoffset())
         uo = datetime.__sub__(other.replace(tzinfo=None),
                               other.utcoffset())
         return us < uo
     else:
         raise TypeError("Can't compare naive and aware datetimes")
示例#5
0
 def __sub__(self, other):
     if isinstance(other, timedelta):
         # Use __add__ implementation if it's datetime and timedelta
         return self + (-1) * other
     else:
         return datetime.__sub__(self.replace(tzinfo=None),
                                 other.replace(tzinfo=None))
示例#6
0
 def __sub__(self, other):
     if isinstance(other, timedelta):
         # Use __add__ implementation if it's datetime and timedelta
         return self + (-1) * other
     else:
         return datetime.__sub__(self.astimezone(UTC),
                                 other.astimezone(UTC))
示例#7
0
 def __sub__(self, arg):
     if isinstance(arg, AbsTime):
         return self.unixTime() - arg.unixTime()
     elif isinstance(arg, int) or isinstance(arg, long) or isinstance(arg, float):
         offset = arg 
     key = {"seconds": offset}
     dt = datetime.__sub__(self, timedelta(**key))
     return self._fromDateTime(dt)
示例#8
0
 def __sub__(self, arg):
     if isinstance(arg, AbsTime):
         return self.unixTime() - arg.unixTime()
     elif isinstance(arg, int) or isinstance(arg, long) or isinstance(arg, float):
         offset = arg 
     key = {"seconds": offset}
     dt = datetime.__sub__(self, timedelta(**key))
     return self._fromDateTime(dt)
示例#9
0
    def __sub__(self, other):
        result = datetime.__sub__(self, other)

        if result is NotImplemented:
            return result

        if isinstance(result, datetime):
            return self.from_datetime(result)
        else:
            return result
示例#10
0
 def __sub__(self, t):
     if isinstance(t, (Date, datetime)):
         # Subtracting two dates returns a Time.
         t = datetime.__sub__(self, t)
         return Time(+t.days, +t.seconds, microseconds=+t.microseconds)
     if isinstance(t, (Time, timedelta)):
         return self + Time(-t.days,
                            -t.seconds,
                            microseconds=-t.microseconds,
                            months=-getattr(t, "months", 0),
                            years=-getattr(t, "years", 0))
示例#11
0
文件: gpstime.py 项目: kundor/gpsdata
    def __sub__(self, other):
        """Subtract other gpsdatetime or datetime to produce timedelta,
        or subtract timedelta to produce gpsdatetime.
        
        If one or both timezones are TAIOffset, leap seconds are included
        in the difference. Otherwise they're not.
        """
        if not isinstance(other, datetime):
            if isinstance(other, timedelta):
                return self.__add__(-other)
            return NotImplemented
            
        if isnaive(self) != isnaive(other):
            raise TypeError('Cannot mix naive and timezone-aware datetimes')
        
        if isnaive(self) or (not isinstance(self.tzinfo, TAIOffset)
                             and not isinstance(other.tzinfo, TAIOffset)):
            return datetime.__sub__(self, other)

        off = datetime.__sub__(self.replace(tzinfo=None), other.replace(tzinfo=None))
        off += taioffset(other) - taioffset(self)
        return off
示例#12
0
    def __sub__(self, other):
        """Subtract other gpsdatetime or datetime to produce timedelta,
        or subtract timedelta to produce gpsdatetime.
        
        If one or both timezones are TAIOffset, leap seconds are included
        in the difference. Otherwise they're not.
        """
        if not isinstance(other, datetime):
            if isinstance(other, timedelta):
                return self.__add__(-other)
            return NotImplemented

        if isnaive(self) != isnaive(other):
            raise TypeError('Cannot mix naive and timezone-aware datetimes')

        if isnaive(self) or (not isinstance(self.tzinfo, TAIOffset)
                             and not isinstance(other.tzinfo, TAIOffset)):
            return datetime.__sub__(self, other)

        off = datetime.__sub__(self.replace(tzinfo=None),
                               other.replace(tzinfo=None))
        off += taioffset(other) - taioffset(self)
        return off
示例#13
0
 def __sub__(self, x):
     """
     Sottrae 'x' dalla data; se x è di tipo numerico (int/float/long) viene
     restituita la data defalcata di 'x' giorni, altrimenti funzionalità
     standard della sottrazioe da un datetime.date di altro (timdelta)
     """
     if isinstance(x, (int, float, long)):
         #sottraggo un numero dalla data, detraggo in giorni
         return _datetime(self.year, self.month, self.day, self.hour, self.minute, self.second)-timedelta(days=x)
     d = dtime.__sub__(self, x)
     if isinstance(x, (_date, _datetime)):
         # data-data = timedelta, lo restituisco
         return d
     #sottrazione standard
     return _datetime(d.year, d.month, d.day, d.hour, d.minute, d.second)
示例#14
0
 def __sub__(self, x):
     """
     Sottrae 'x' dalla data; se x è di tipo numerico (int/float/long) viene
     restituita la data defalcata di 'x' giorni, altrimenti funzionalità
     standard della sottrazioe da un datetime.date di altro (timdelta)
     """
     if isinstance(x, (int, float, long)):
         #sottraggo un numero dalla data, detraggo in giorni
         return _datetime(self.year, self.month, self.day, self.hour,
                          self.minute, self.second) - timedelta(days=x)
     d = dtime.__sub__(self, x)
     if isinstance(x, (_date, _datetime)):
         # data-data = timedelta, lo restituisco
         return d
     #sottrazione standard
     return _datetime(d.year, d.month, d.day, d.hour, d.minute, d.second)
示例#15
0
 def __sub__(self, other):
     return datetimedict.fromdatetime(datetime.__sub__(self, other))
示例#16
0
 def __sub__(self, other):
     return datetimedict.fromdatetime(datetime.__sub__(self, other))
示例#17
0
 def _sub_and_convert(a, b):
     d = datetime.__sub__(a, b)
     if isinstance(d, datetime):
         return T(d)
     else:
         return d
示例#18
0
                    title="Upcoming Events! :alarm_clock:",
                    description="See what's happening in the next hour!",
                    color=discord.Colour.dark_purple(),
                )

                #assumes events in list are in chronological order
                for num, event in enumerate(events):
<<<<<<< HEAD
                    event_time, event_name, link = event
                    left = dt.strptime(f"2021 October {day} {event_time}", "%Y %b %d %I:%M %p").replace(tzinfo=cst)
=======
                    event_time, event_name, link = event                  
                    left = dt.strptime(f"2021 May {day} {event_time}", "%Y %b %d %I:%M %p").replace(tzinfo=cst)
>>>>>>> fb1d025f3d8eed90f94d9173a47e8da755c3bba1
                    if left > austin(): #check that event hasn't passed
                        if (dt.__sub__(left, austin()).total_seconds()) <= 60:  # event happening in the next minute
                            text = f"{event_name} starting now!"
                            embed.add_field(
                                name=f"{val}. {event_name} at {event_time} CT",
                                value=("in < 1 minute" + (f", [**link**]({link})" if link else "")),
                                inline=False,
                            )
                        elif (dt.__sub__(left, austin()).total_seconds()) <= 3600:  # event happening in the next hour 
                            embed.add_field(
                                name=f"{val}. {event_name} at {event_time} CT",
                                value=(f"in {time_left(left)}" + (f", [**link**]({link})" if link else "")),
                                inline=False,
                            )
                            val = val + 1
                        else: 
                            break
示例#19
0
 def __sub__(self, td):
     newdt = datetime.__sub__(self, td)
     if isinstance(newdt, datetime):
         return ApexDatetime.from_iso(newdt.isoformat())
     return newdt # actually a timedelta