Exemplo n.º 1
0
    def years_months_days(self):
        """

        :return:
        """
        years, months = symmetric_divmod(self[0], 12)
        return years, months, self[1]
Exemplo n.º 2
0
 def __new__(cls,
             years=0,
             months=0,
             weeks=0,
             days=0,
             hours=0,
             minutes=0,
             seconds=0,
             subseconds=0,
             milliseconds=0,
             microseconds=0,
             nanoseconds=0):
     mo = int(12 * years + months)
     if mo < MIN_INT64 or mo > MAX_INT64:
         raise ValueError("Months value out of range")
     d = int(7 * weeks + days)
     if d < MIN_INT64 or d > MAX_INT64:
         raise ValueError("Days value out of range")
     s = (int(3600000000000 * hours) + int(60000000000 * minutes) +
          int(1000000000 * seconds) + int(1000000000 * subseconds) +
          int(1000000 * milliseconds) + int(1000 * microseconds) +
          int(nanoseconds))
     s, ss = symmetric_divmod(s, 1000000000)
     if s < MIN_INT64 or s > MAX_INT64:
         raise ValueError("Seconds value out of range")
     return tuple.__new__(cls, (mo, d, s, ss / 1000000000))
Exemplo n.º 3
0
 def __add__(self, other):
     if isinstance(other, timedelta):
         t = self.to_clock_time() + ClockTime(86400 * other.days + other.seconds, other.microseconds * 1000)
         days, seconds = symmetric_divmod(t.seconds, 86400)
         date_ = Date.from_ordinal(days + 1)
         time_ = Time.from_ticks(seconds + (t.nanoseconds / 1000000000))
         return self.combine(date_, time_)
     return NotImplemented
Exemplo n.º 4
0
 def __mod__(self, other):
     if isinstance(other, int):
         seconds, subseconds = symmetric_divmod(
             nano_add(self[2], self[3]) % other, 1)
         return Duration(months=round_half_to_even(self[0] % other),
                         days=round_half_to_even(self[1] % other),
                         seconds=seconds,
                         subseconds=subseconds)
     return NotImplemented
Exemplo n.º 5
0
 def add_months(d, months):
     years, months = symmetric_divmod(months, 12)
     year = d.__year + years
     month = d.__month + months
     while month > 12:
         year += 1
         month -= 12
     while month < 1:
         year -= 1
         month += 12
     d.__year = year
     d.__month = month
Exemplo n.º 6
0
 def hours_minutes_seconds(self):
     """ A 3-tuple of (hours, minutes, seconds).
     """
     minutes, seconds = symmetric_divmod(self[2], 60)
     hours, minutes = symmetric_divmod(minutes, 60)
     return hours, minutes, float(seconds) + self[3]