Ejemplo n.º 1
0
def datematch(indate, dateRangeStart, dateRangeEnd, delta):
    """Determine if date stamp match search crieterias
        doesmatch = Fstdc.datematch(indate, dateRangeStart, dateRangeEnd, delta)
        @param indate Date to be check against, CMC datetime stamp (int)
        @param dateRangeStart, CMC datetime stamp (int) 
        @param dateRangeEnd, CMC datetime stamp (int)
        @param delta (float)
        @return 1:if date match; 0 otherwise
        @exception TypeError
    """
    if dateRangeEnd != -1:
        if _rmn.difdatr(indate, dateRangeEnd) > 0.:
            return 0
    toler  = 0.00023 #tolerance d'erreur de 5 sec
    nhours = 0.
    if dateRangeStart != -1:
        nhours = _rmn.difdatr(indate, dateRangeStart)
        if nhours < 0.:
            return 0
    else:
        if dateRangeEnd == -1:
            return 1
        nhours = _rmn.difdatr(dateRangeEnd, indate)
    modulo = nhours % delta
    if modulo < toler or (delta - modulo) < toler:
        return 1
    else:
        return 0
Ejemplo n.º 2
0
def datematch(indate, dateRangeStart, dateRangeEnd, delta):
    """Determine if date stamp match search crieterias
        doesmatch = Fstdc.datematch(indate, dateRangeStart, dateRangeEnd, delta)
        @param indate Date to be check against, CMC datetime stamp (int)
        @param dateRangeStart, CMC datetime stamp (int) 
        @param dateRangeEnd, CMC datetime stamp (int)
        @param delta (float)
        @return 1:if date match; 0 otherwise
        @exception TypeError
    """
    if dateRangeEnd != -1:
        if _rmn.difdatr(indate, dateRangeEnd) > 0.:
            return 0
    toler  = 0.00023 #tolerance d'erreur de 5 sec
    nhours = 0.
    if dateRangeStart != -1:
        nhours = _rmn.difdatr(indate, dateRangeStart)
        if nhours < 0.:
            return 0
    else:
        if dateRangeEnd == -1:
            return 1
        nhours = _rmn.difdatr(dateRangeEnd, indate)
    modulo = nhours % delta
    if modulo < toler or (delta - modulo) < toler:
        return 1
    else:
        return 0
Ejemplo n.º 3
0
 def testDifdateToPrintKnownValues(self):
     """Difdatr to print should give known result with known input"""
     for yyyymmdd,hhmmsshh,nhours,hhmmsshh2 in self.knownValues:
         idate1 = rmn.newdate(rmn.NEWDATE_PRINT2STAMP,yyyymmdd,hhmmsshh)
         idate2 = rmn.newdate(rmn.NEWDATE_PRINT2STAMP,yyyymmdd,hhmmsshh2)
         nhours2 = rmn.difdatr(idate2,idate1)
         self.assertEqual(nhours2,nhours,repr(nhours2)+' != '+repr(nhours))
Ejemplo n.º 4
0
def difdatr(date1, date2):
    """Compute differenc between 2 CMC datatime stamps (Interface to difdatr)
    nhours = Fstdc.difdatr(date1, date2)
    @param date1 CMC datatime stamp (int)
    @param date2 CMC datatime stamp (int)
    @return number of hours = date2-date1 (float)
    @exception TypeError
    """
    return _rmn.difdatr(date1, date2)
Ejemplo n.º 5
0
def difdatr(date1, date2):
    """Compute differenc between 2 CMC datatime stamps (Interface to difdatr)
    nhours = Fstdc.difdatr(date1, date2)
    @param date1 CMC datatime stamp (int)
    @param date2 CMC datatime stamp (int)
    @return number of hours = date2-date1 (float)
    @exception TypeError
    """
    return _rmn.difdatr(date1, date2)
Ejemplo n.º 6
0
    def test_7(self):
        """
        Manipulating Dates

        Dates in FSTD files are encoded integers. Conversion to more human friendly formats
        and manipulation can be done using the RPNDate and RPNDateRange classes or with the newdate function.
        
        See also:
        rpnpy.rpndate.RPNDate
        rpnpy.rpndate.RPNDateRange
        rpnpy.librmn.base.newdate
        rpnpy.librmn.base.incdatr
        rpnpy.librmn.base.difdatr
        rpnpy.librmn.const
        """
        from rpnpy.rpndate import RPNDate, RPNDateRange

        d1 = RPNDate(20030423, 11453500)
        d2 = RPNDate(d1)
        d2 = d2.incr(48)
        dr = RPNDateRange(d1, d2, 6)
        print(str(dr.lenght()))
        # 48.0

        for d3 in dr:
            print(str(d3))
        # RPNDate(20030423,11453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=     0.0)
        # RPNDate(20030423,17453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=     6.0)
        # RPNDate(20030423,23453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    12.0)
        # RPNDate(20030424,05453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    18.0)
        # RPNDate(20030424,11453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    24.0)
        # RPNDate(20030424,17453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    30.0)
        # RPNDate(20030424,23453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    36.0)
        # RPNDate(20030425,05453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    42.0)
        # RPNDate(20030425,11453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    48.0)

        ## Lower level functions can also be used wherever more convenient.
        import rpnpy.librmn.all as rmn

        yyyymmdd = 20150102  #Jan 2nd, 2015
        hhmmsshh = 13141500  #13h 14min 15sec
        cmcdate = rmn.newdate(rmn.NEWDATE_PRINT2STAMP, yyyymmdd, hhmmsshh)

        nhours = 6.
        cmcdate2 = rmn.incdatr(cmcdate, nhours)

        (yyyymmdd2, hhmmsshh2) = rmn.newdate(rmn.NEWDATE_STAMP2PRINT, cmcdate2)
        print("%06d.%06d + %4.1fh = %06d.%06d" %
              (yyyymmdd, hhmmsshh, nhours, yyyymmdd2, hhmmsshh2))
        # 20150102.13141500 +  6.0h = 20150102.19141500

        nhours2 = rmn.difdatr(cmcdate2, cmcdate)
        print("%06d.%06d - %06d.%06d = %4.1fh" %
              (yyyymmdd2, hhmmsshh2, yyyymmdd, hhmmsshh, nhours2))
Ejemplo n.º 7
0
 def __sub__(self, other):
     "Time difference between 2 dates [hours] or Decrease time by nhours"
     if isinstance(other, RPNDate):
         return _rmn.difdatr(self.datev, other.datev)
     elif type(other) == type(1) or type(other) == type(1.0):
         nhours = -other
         mydate = RPNDate(self)
         mydate += nhours
         return mydate
     else:
         raise TypeError('RPNDate: Cannot substract object of type ' +
                         str(type(other)))
Ejemplo n.º 8
0
    def test_7(self):
        """
        Manipulating Dates

        Dates in FSTD files are encoded integers. Conversion to more human friendly formats
        and manipulation can be done using the RPNDate and RPNDateRange classes or with the newdate function.
        
        See also:
        rpnpy.rpndate.RPNDate
        rpnpy.rpndate.RPNDateRange
        rpnpy.librmn.base.newdate
        rpnpy.librmn.base.incdatr
        rpnpy.librmn.base.difdatr
        rpnpy.librmn.const
        """
        from rpnpy.rpndate import RPNDate, RPNDateRange
 
        d1 = RPNDate(20030423, 11453500)
        d2 = RPNDate(d1)
        d2 = d2.incr(48)
        dr = RPNDateRange(d1, d2, 6)
        print(str(dr.lenght()))
        # 48.0
 
        for d3 in dr:
            print(str(d3))
        # RPNDate(20030423,11453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=     0.0)
        # RPNDate(20030423,17453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=     6.0)
        # RPNDate(20030423,23453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    12.0)
        # RPNDate(20030424,05453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    18.0)
        # RPNDate(20030424,11453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    24.0)
        # RPNDate(20030424,17453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    30.0)
        # RPNDate(20030424,23453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    36.0)
        # RPNDate(20030425,05453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    42.0)
        # RPNDate(20030425,11453500) ; RPNDate(20030423,11453500,dt=  3600.0,nstep=    48.0)

        ## Lower level functions can also be used wherever more convenient.
        import rpnpy.librmn.all as rmn
 
        yyyymmdd = 20150102 #Jan 2nd, 2015
        hhmmsshh = 13141500 #13h 14min 15sec
        cmcdate  = rmn.newdate(rmn.NEWDATE_PRINT2STAMP, yyyymmdd, hhmmsshh)
 
        nhours   = 6.
        cmcdate2 = rmn.incdatr(cmcdate, nhours)
 
        (yyyymmdd2, hhmmsshh2) = rmn.newdate(rmn.NEWDATE_STAMP2PRINT, cmcdate2)
        print("%06d.%06d + %4.1fh = %06d.%06d" % (yyyymmdd, hhmmsshh, nhours, yyyymmdd2, hhmmsshh2))
        # 20150102.13141500 +  6.0h = 20150102.19141500
 
        nhours2 = rmn.difdatr(cmcdate2, cmcdate)
        print("%06d.%06d - %06d.%06d = %4.1fh" % (yyyymmdd2, hhmmsshh2, yyyymmdd, hhmmsshh, nhours2))