Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Rickard Lindberg, Roger Lindberg 2 # 3 # This file is part of Timeline. 4 # 5 # Timeline is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # Timeline is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with Timeline. If not, see <http://www.gnu.org/licenses/>. 17 18 19 from timelinelib.calendar.time import ComparableValue 20 from timelinelib.calendar.time import GenericDeltaMixin 21 from timelinelib.calendar.time import GenericTimeMixin 22 23 24 SECONDS_IN_DAY = 24 * 60 * 6028 29 MIN_JULIAN_DAY = 0 30 31 @property10933 return GregorianDelta34 35 @classmethod37 return cls(cls.MIN_JULIAN_DAY, 0)38 39 @classmethod41 if allow_negative_julian_yeras: 42 cls.MIN_JULIAN_DAY = -1000000000000000000000000000000000000000000000000 43 else: 44 cls.MIN_JULIAN_DAY = 04547 if julian_day < self.MIN_JULIAN_DAY: 48 raise ValueError("julian_day must be >= %d" % self.MIN_JULIAN_DAY) 49 if seconds < 0 or seconds >= SECONDS_IN_DAY: 50 raise ValueError("seconds must be >= 0 and <= 24*60*60") 51 self.julian_day = julian_day 52 self.seconds = seconds5355 return (isinstance(time, self.__class__) and 56 self.julian_day == time.julian_day and 57 self.seconds == time.seconds)5860 return not (self == time)6163 if isinstance(delta, self.DeltaClass): 64 seconds = self.seconds + delta.seconds 65 return self.__class__(self.julian_day + seconds / SECONDS_IN_DAY, seconds % SECONDS_IN_DAY) 66 raise TypeError( 67 "%s + %s not supported" % (self.__class__.__name__, type(delta)) 68 )6971 if isinstance(other, self.DeltaClass): 72 seconds = self.seconds - other.seconds 73 if seconds < 0: 74 if seconds % SECONDS_IN_DAY == 0: 75 days = abs(seconds) / SECONDS_IN_DAY 76 seconds = 0 77 else: 78 days = abs(seconds) / SECONDS_IN_DAY + 1 79 seconds = SECONDS_IN_DAY - abs(seconds) % SECONDS_IN_DAY 80 return self.__class__(self.julian_day - days, seconds) 81 else: 82 return self.__class__(self.julian_day, seconds) 83 else: 84 days_diff = self.julian_day - other.julian_day 85 seconds_diff = self.seconds - other.seconds 86 return self.DeltaClass(days_diff * SECONDS_IN_DAY + seconds_diff)87 90 93 9698 return "{0}({1!r}, {2!r})".format( 99 self.__class__.__name__, 100 self.julian_day, 101 self.seconds 102 )103112 113 @classmethod151115 return cls(seconds)116 117 @classmethod119 return cls(SECONDS_IN_DAY * days)120 121 @property123 return self.value124126 if isinstance(value, self.__class__): 127 return float(self.seconds) / float(value.seconds) 128 else: 129 return self.__class__(self.seconds / value)130 133 136 139141 return (self.seconds / (60 * 60)) % 24142144 return (self.seconds / 60) % 60145
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Aug 19 01:55:20 2018 | http://epydoc.sourceforge.net |