Beispiel #1
0
    def __iadd__(self, other):

        t = [
            self.t[0], self.t[1], self.t[2], self.t[4], self.t[5],
            self.t[6] + other
        ]

        self.t = list(_das2.tnorm(t[0], t[1], t[2], t[3], t[4], t[5]))

        return self
Beispiel #2
0
    def ceil(self, nSecs):
        """Find the nearest time, evenly divisible by nSec that is greater
		than the current time value."""

        if nSecs - int(nSecs) != 0:
            raise ValueError("%s is not an integer" % nSecs)
        nSecs = int(nSecs)

        if nSecs < 1:
            raise ValueError("%s is < 1" % nSecs)

        elif nSecs == 1:
            rFrac = self.t[6] - int(self.t[6])
            if rFrac > 0.0:
                self.t[6] = int(self.t[6]) + 1

        elif nSecs < 86400:

            nSecOfDay = self.t[4] * 60 * 60 + self.t[5] * 60 + int(
                M.ceil(self.t[6]))

            nFloor = (nSecOfDay // nSecs) * nSecs

            if nSecOfDay - nFloor == 0:
                nCeil = nFloor
            else:
                nCeil = nFloor + nSecs

            self.t[4] = nCeil // (60 * 60)
            nRem = nCeil - (self.t[4] * 60 * 60)

            self.t[5] = nRem // 60
            nRem = nRem - (self.t[5] * 60)

            self.t[6] = float(nRem)

        elif nSecs == 86400:
            if (self.t[4] > 0) or (self.t[5] > 0) or (self.t[6] > 0.0):
                self.t[2] += 1

            self.t[4] = 0
            self.t[5] = 0
            self.t[6] = 0.0

        else:
            raise ValueError(
                "Can't yet provide floor values for times > 1 day")

        self.t = list(
            _das2.tnorm(self.t[0], self.t[1], self.t[2], self.t[4], self.t[5],
                        self.t[6]))
Beispiel #3
0
    def adjust(self, nYear, nMonth=0, nDom=0, nHour=0, nMin=0, fSec=0.0):
        """Adjust one or more of the field, either positive or negative,
		calls self.norm internally"""

        if nYear == 0 and nMonth == 0 and nDom == 0 and nHour == 0 and \
           nMin == 0 and fSec == 0.0:
            return

        t = [
            self.t[0] + nYear, self.t[1] + nMonth, self.t[2] + nDom,
            self.t[4] + nHour, self.t[5] + nMin, self.t[6] + fSec
        ]

        self.t = list(_das2.tnorm(t[0], t[1], t[2], t[3], t[4], t[5]))
Beispiel #4
0
    def floor(self, nSecs):
        '''Find the nearest time, evenly divisable by nSec, that is 
		less that the current time value.
		'''

        if nSecs - int(nSecs) != 0:
            raise ValueError("%s is not an integer" % nSecs)
        nSecs = int(nSecs)

        if nSecs < 1:
            raise ValueError("%s is < 1" % nSecs)

        elif nSecs == 1:
            self.t[6] = int(self.t[6])

        elif nSecs < 86400:

            nFloor = self.t[4] * 60 * 60 + self.t[5] * 60 + int(self.t[6])

            nFloor = (nFloor // nSecs) * nSecs

            self.t[4] = nFloor // (60 * 60)
            nRem = nFloor - (self.t[4] * 60 * 60)

            self.t[5] = nRem // 60
            self.t[6] = float(nRem - (self.t[5] * 60))

        elif nSec == 86400:
            self.t[4] = 0
            self.t[5] = 0
            self.t[6] = 0.0

        else:
            raise ValueError(
                "Can't yet provide floor values for times > 1 day")

        self.t = list(
            _das2.tnorm(self.t[0], self.t[1], self.t[2], self.t[4], self.t[5],
                        self.t[6]))
Beispiel #5
0
    def __init__(self, nYear=0, nMonth=0, nDom=0, nHour=0, nMin=0, fSec=0.0):
        """Initalize from field values
		
		Note: If nYear is a string, and all other values are zero, then 
		      parsetime is called to generate the field values from the time
				string.
		"""

        # Handle bytes to string conversion up front
        if (sys.version_info[0] > 2) and isinstance(nYear, bytes):
            nYear = nYear.decode('utf-8')

        # Initialize from any type of string
        if isinstance(nYear, basestring):
            try:
                tTmp = _das2.parsetime(nYear)
                (nYear, nMonth, nDom, nDoy, nHour, nMin, fSec) = tTmp
            except ValueError as e:
                raise ValueError(
                    "String '%s' was not parseable as a datetime" % nYear)

        # Initialize from a python datetime
        elif isinstance(nYear, datetime.datetime):
            pdt = nYear
            nYear = pdt.year
            nMonth = pdt.month
            nDom = pdt.day
            nHour = pdt.hour
            nMin = pdt.minute
            fSec = float(pdt.second) + (pdt.microsecond / 1000000.0)

        # initialize form a numpy datetime64
        elif isinstance(nYear, numpy.datetime64):

            # Numpy's decision to print local time is very irritating.  Get epoch seconds
            nEpoch = nYear.astype(int)
            sType = nYear.dtype.str
            sType = sType[sType.find('[') +
                          1:sType.find(']')]  # Gives timestamp units

            # datetime64 always uses the unix epoch, but at different units.
            r1970 = nEpoch * g_dDt64Scale[sType]

            tTmp = _das2.parse_epoch(r1970, "t1970")
            (nYear, nMonth, nDom, nDoy, nHour, nMin, fSec) = tTmp

        # Initialize float plus das2 epoch units
        elif isinstance(nMonth, str):
            tTmp = _das2.parse_epoch(nYear, nMonth)
            (nYear, nMonth, nDom, nDoy, nHour, nMin, fSec) = tTmp

        elif isinstance(nYear, DasTime):
            # Just work as a copy constructor
            nMonth = nYear.t[1]
            nDom = nYear.t[2]
            nHour = nYear.t[4]
            nMin = nYear.t[5]
            fSec = nYear.t[6]
            nYear = nYear.t[0]

        # Assume years less than 100 but greater than 57 are old 2 digit years
        # that need to be incremented.  I don't like this but what can
        # you do when reading old data.

        if isinstance(nYear, (tuple, list)):
            self.t = [0, 0, 0, 0, 0, 0, 0.0]
            for i in xrange(0, len(nYear)):
                j = i
                if i >= 3:
                    j = i + 1
                self.t[j] = nYear[i]

            if self.t[0] < 100 and self.t[0] > 57:
                self.t[0] = self.t[0] + 1900

            self.t = list(_das2.tnorm(t[0], t[1], t[2], t[4], t[5], t[6]))
        else:
            if nYear < 100 and nYear >= 57:
                nYear += 1900

            self.t = list(_das2.tnorm(nYear, nMonth, nDom, nHour, nMin, fSec))

        if abs(self.t[0]) > 9999:
            raise OverflowError("Year value is outside range +/- 9999")
Beispiel #6
0
 def norm(self):
     """Normalize the time fields so that all contain legal values."""
     tNew = _das2.tnorm(self.t[0], self.t[1], self.t[2], self.t[4],
                        self.t[5], self.t[6])
     self.t = list(tNew)