Check if this PRE-PREPARE is not older than (not checking for greater
        than since batches maybe sent in less than 1 second) last PRE-PREPARE
        and in a sufficient range of local clock's UTC time.
        :param pp:
        :return:
510478
def is_pre_prepare_time_correct(self, pp: PrePrepare, sender: str) -> bool:
        
        tpcKey = (pp.viewNo, pp.ppSeqNo)

        if (self.last_accepted_pre_prepare_time and
                pp.ppTime < self.last_accepted_pre_prepare_time):
            return False
        elif ((tpcKey not in self.pre_prepare_tss) or
                ((pp, sender) not in self.pre_prepare_tss[tpcKey])):
            return False
        else:
            return (
                abs(pp.ppTime - self.pre_prepare_tss[tpcKey][pp, sender]) <=
                self.config.ACCEPTABLE_DEVIATION_PREPREPARE_SECS
            )
139069
def time_before_caveat(t):
    '''
    '''

    return _first_party(COND_TIME_BEFORE,
                        pyrfc3339.generate(t, accept_naive=True,
                                           microseconds=True))
84494
def prevmonday(num):
    
    today = get_today()
    lastmonday = today - timedelta(days=today.weekday(), weeks=num)
    return lastmonday
745184
def preprocess(self, dt):
        
        # Process
        try:  # this block should not raise errors, and if it does -- they should not be wrapped with `Invalid`
            # localize
            if self.localize and dt.tzinfo is None:
                dt = self.localize(dt)

            # astimezone
            if self.astz and dt.tzinfo is not None:
                dt = self.astz(dt)

            # Finish
            return dt
        except Exception as e:
            if isinstance(e, Invalid):
                raise
            six.reraise(RuntimeError, e)
1249311
def pp_timestamp(t):
    
    if t is None:
        return ''
    h, m, s = int(t / 3600), int(t / 60 % 60), t % 60
    return "%02d:%02d:%05.2f" % (h, m, s)
1207389
def _validate_time_range(trange, status, msg):
    '''
    
    '''
    # If trange is empty, just return the current status & msg
    if not trange:
        return status, msg

    if not isinstance(trange, dict):
        status = False
        msg = ('The time_range parameter for '
               'wtmp beacon must '
               'be a dictionary.')

    if not all(k in trange for k in ('start', 'end')):
        status = False
        msg = ('The time_range parameter for '
               'wtmp beacon must contain '
               'start & end options.')

    return status, msg
946497
def hasExpired(self):
        
        return (datetime.datetime.utcnow() - self.lastUpdateTime).total_seconds() > self.maxAgeSeconds
1315116
def future(self,in_days=None,in_hours=None,in_minutes=None,in_seconds=None):
        
        future = None

        # Initialize variables to 0
        dd, hh, mm, ss = [0 for i in range(4)]
        if (in_days != None):
            dd = dd + in_days
        if (in_hours != None):
            hh = hh + in_hours
        if (in_minutes != None):
            mm = mm + in_minutes
        if (in_seconds != None):
            ss = ss + in_seconds

        # Set the hours, minutes and seconds from now (minus the days)
        dnow = datetime.datetime.utcnow()  # Now
        d = dnow + \
            datetime.timedelta(hours=hh, minutes=mm, seconds = ss)
        # Time from midnight
        for_total_seconds = d - \
            d.replace(hour=0, minute=0, second=0, microsecond=0)

        # Convert into minutes since midnight
        try:
            msm = for_total_seconds.total_seconds()/60.
        except:
            # For versions before 2.7
            msm = self.timedelta_total_seconds(for_total_seconds)/60.

        if (dd<len(self.days)):
            for timestep in self.days[dd].timesteps:
                if timestep.name >= msm:
                    future = timestep
                    return future
        else:
            print('ERROR: requested date is outside the forecast range selected,' + str(len(self.days)))
            return False
1192938
def _onOffset(self, dt, businesshours):
        
        # if self.normalize and not _is_normalized(dt):
        #     return False
        # Valid BH can be on the different BusinessDay during midnight
        # Distinguish by the time spent from previous opening time
        if self.n >= 0:
            op = self._prev_opening_time(dt)
        else:
            op = self._next_opening_time(dt)
        span = (dt - op).total_seconds()
        if span <= businesshours:
            return True
        else:
            return False
519183
def previous(time, base)
      current = time
      until match?(current, base) && current < time
        pot_prev = align(potential_previous(current, base), base)
        pot_prev -= min_step if pot_prev == current

        current = pot_prev
      end

      current
    end
545879
protected boolean prePrepare() {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "prePrepare");

        //
        // Cancel timeout prior to completion phase
        //
        cancelAlarms();

        //
        // Inform the Synchronisations we are about to complete
        //
        if (!_rollbackOnly) {
            if (_syncs != null) {
                _syncs.distributeBefore();
            }
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, "prePrepare", !_rollbackOnly);
        return !_rollbackOnly;
    }
594844
def is_processed(self, db_versions):
        
        return self.number in (v.number for v in db_versions if v.date_done)
386642
def date_in_past(self):
        
        now = datetime.datetime.now()
        return (now.date() > self.date)
524577
def before(point):
    
    if not point:
        return True

    if isinstance(point, six.string_types):
        point = str_to_time(point)
    elif isinstance(point, int):
        point = time.gmtime(point)

    return time.gmtime() <= point
282977
def now(cls, tzinfo=None):
    """"""
    obj = cls.utcnow()
    if tzinfo is None:
      tzinfo = localtz()
    return obj.astimezone(tzinfo)
1259315
def is_tradetime_now():
    
    cal = Calendar('china.sse')
    now_time = time.localtime()
    today = Date(now_time[0], now_time[1], now_time[2])
    if not cal.isBizDay(today):
        return False
    now = (now_time.tm_hour, now_time.tm_min, now_time.tm_sec)
    if (9, 15, 0) <= now <= (11, 30, 0) or (13, 0, 0) <= now <= (15, 0, 0):
        return True
    return False
1205256
def last_update_time(self, value):
        
        if isinstance(value, (datetime.datetime,)):
            self._last_update_time = value
        else:
            raise ValueError("Expect last_update_time to be a datetime")