Split C{interval} into a series of event type and timestamp tuples.
        An exaple of the input is "R1283008245P1283008268".
        Returns events in reversed order (latest first).
435003
def _interval_split(interval, only=None, context=None, event_re=re.compile("[A-Z][0-9]+")):
    
    def split_event(event):
        "Helper to parse events."
        kind, val = event[:1], event[1:]
        try:
            return kind, float(val)
        except (TypeError, ValueError):
            return None, 0

    if hasattr(interval, "fetch"):
        interval = interval.fetch("custom_activations")
    ##import sys; print >>sys.stderr, "!!!!!isplit", interval, event_re.findall(interval)

    return list(reversed([split_event(i) for i in event_re.findall(interval) if not only or i.startswith(only)]))
900705
def get_results(self, stream, time_interval):
        
        return [StreamInstance(t, self.data[stream.stream_id][t])
                for t in sorted(self.data[stream.stream_id]) if t in time_interval]
296712
def read_cz_lsm_event_list(fd, byte_order):
    """"""
    count = struct.unpack(byte_order+'II', fd.read(8))[1]
    events = []
    while count > 0:
        esize, etime, etype = struct.unpack(byte_order+'IdI', fd.read(16))
        etext = stripnull(fd.read(esize - 16))
        events.append((etime, etype, etext))
        count -= 1
    return events
875029
def convert_timespan(timespan):
    """"""
    start, end = timespan.split('-->')
    start = convert_timestamp(start)
    end = convert_timestamp(end)
    return start, end
310491
function parseDoubleGroupedInterval(){
  var options = Array.prototype.slice.call(arguments);
  if (!options[0]) throw 'Requested parser requires a sequential list (array) of properties to target as a second argument';
  return function(res){
    var dataset = new Dataset()
      .type('double-grouped-interval');
    each(res.result, function(record, i){
      var index = options[1] && options[1] === 'timeframe.end' ? record.timeframe.end : record.timeframe.start;
      each(record['value'], function(value, j){
        var label = value[options[0][0]] + ' ' + value[options[0][1]];
        dataset.set([ label, index ], value.result);
      });
    });
    return dataset;
  }
}
66982
private int getTimeSlice(Instant timestamp) {
        long value = times.getTime(timestamp) / TIMESLICE_INTERVAL;
        if (value>Integer.MAX_VALUE || value<0) throw new IllegalArgumentException("Timestamp overflow detected: " + timestamp);
        return (int)value;
    }
1208155
def getIntervalRange(data_type_oid, type_modifier):
    """"""

    if data_type_oid not in (VerticaType.INTERVAL, VerticaType.INTERVALYM):
        raise ValueError("Invalid data type OID: {}".format(data_type_oid))

    if type_modifier == -1:   # assume the default
        if data_type_oid == VerticaType.INTERVALYM:
            return "Year to Month"
        elif data_type_oid == VerticaType.INTERVAL:
            return "Day to Second"

    if data_type_oid == VerticaType.INTERVALYM: # Year/Month intervals
        if (type_modifier & INTERVAL_MASK_YEAR2MONTH) == INTERVAL_MASK_YEAR2MONTH:
            return "Year to Month"
        elif (type_modifier & INTERVAL_MASK_YEAR) == INTERVAL_MASK_YEAR:
            return "Year"
        elif (type_modifier & INTERVAL_MASK_MONTH) == INTERVAL_MASK_MONTH:
            return "Month"
        else:
            return "Year to Month"

    if data_type_oid == VerticaType.INTERVAL:  # Day/Time intervals
        if (type_modifier & INTERVAL_MASK_DAY2SEC) == INTERVAL_MASK_DAY2SEC:
            return "Day to Second"
        elif (type_modifier & INTERVAL_MASK_DAY2MIN) == INTERVAL_MASK_DAY2MIN:
            return "Day to Minute"
        elif (type_modifier & INTERVAL_MASK_DAY2HOUR) == INTERVAL_MASK_DAY2HOUR:
            return "Day to Hour"
        elif (type_modifier & INTERVAL_MASK_DAY) == INTERVAL_MASK_DAY:
            return "Day"
        elif (type_modifier & INTERVAL_MASK_HOUR2SEC) == INTERVAL_MASK_HOUR2SEC:
            return "Hour to Second"
        elif (type_modifier & INTERVAL_MASK_HOUR2MIN) == INTERVAL_MASK_HOUR2MIN:
            return "Hour to Minute"
        elif (type_modifier & INTERVAL_MASK_HOUR) == INTERVAL_MASK_HOUR:
            return "Hour"
        elif (type_modifier & INTERVAL_MASK_MIN2SEC) == INTERVAL_MASK_MIN2SEC:
            return "Minute to Second"
        elif (type_modifier & INTERVAL_MASK_MINUTE) == INTERVAL_MASK_MINUTE:
            return "Minute"
        elif (type_modifier & INTERVAL_MASK_SECOND) == INTERVAL_MASK_SECOND:
            return "Second"
        else:
            return "Day to Second"
882714
def parse(s, return_type=int):
    '''
    
    '''
    RE_DAY = r'([0-9]+)d(ay)?'
    RE_HOUR = r'([0-9]+)h(our)?'
    RE_MINUTE = r'([0-9]+)m(in(ute)?)?'
    RE_SECOND = r'([0-9]+)(s(ec(ond)?)?)?'

    def _parse_time_with_unit(s):
        retval = 0
        md = re.match(RE_DAY, s)
        mh = re.match(RE_HOUR, s)
        mm = re.match(RE_MINUTE, s)
        ms = re.match(RE_SECOND, s)
        if md:
            retval = 86400 * int(md.group(1))
        elif mh:
            retval = 3600 * int(mh.group(1))
        elif mm:
            retval = 60 * int(mm.group(1))
        elif ms:
            retval = int(ms.group(1))
        return retval

    if isinstance(s, (type(None), int, float)):
        return s

    if s[-1] in '0123456789':
        s += 's'

    m = re.match(r'^(%s)?(%s)?(%s)?(%s)?$' % (RE_DAY, RE_HOUR,
                                              RE_MINUTE, RE_SECOND),
                 s)
    if not m:
        raise ParseError('invalid string: "%s"' % s)

    times = [x for x in m.groups() if isinstance(x, str) and
             re.match(r'[0-9]+[a-z]+', x)]
    seconds = sum(_parse_time_with_unit(z) for z in times)

    if return_type is int:
        return seconds
    elif return_type is timedelta:
        return timedelta(seconds=seconds)
    else:
        raise TypeError('return_type "{}" is not supported.'.format(
            return_type.__name__))
1255577
def datetime2unix(T):
    
    T = atleast_1d(T)

    ut1_unix = empty(T.shape, dtype=float)
    for i, t in enumerate(T):
        if isinstance(t, (datetime, datetime64)):
            pass
        elif isinstance(t, str):
            try:
                ut1_unix[i] = float(t)  # it was ut1_unix in a string
                continue
            except ValueError:
                t = parse(t)  # datetime in a string
        elif isinstance(t, (float, int)):  # assuming ALL are ut1_unix already
            return T
        else:
            raise TypeError('I only accept datetime or parseable date string')

        # ut1 seconds since unix epoch, need [] for error case
        ut1_unix[i] = forceutc(t).timestamp()

    return ut1_unix
970919
def build_re_pattern_from_intervals(intervals: IntervalListType) -> BuiltInReType:
    

    inner = [f'{chr(lb)}-{chr(ub)}' for lb, ub in intervals]
    joined_inner = ''.join(inner)
    pattern = f'[{joined_inner}]+'

    return re.compile(pattern, re.UNICODE)
648576
def convert_timestamp(timestamp):
    """"""
    timestamp = timestamp.strip()
    chunk, millis = timestamp.split(',')
    hours, minutes, seconds = chunk.split(':')
    hours = int(hours)
    minutes = int(minutes)
    seconds = int(seconds)
    seconds = seconds + hours * 60 * 60 + minutes * 60 + float(millis) / 1000
    return seconds
456290
def get_timestamp(length):
    """"""
    s = '%.6f' % time.time()
    whole, frac = map(int, s.split('.'))
    res = '%d%d' % (whole, frac)
    return res[:length]
1325237
static TimingInterval merge(Iterable<TimingInterval> intervals, int maxSamples, long start)
    {
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        long operationCount = 0, partitionCount = 0, rowCount = 0, errorCount = 0;
        long maxLatency = 0, totalLatency = 0;
        List<SampleOfLongs> latencies = new ArrayList<>();
        long end = 0;
        long pauseStart = 0, pauseEnd = Long.MAX_VALUE;
        for (TimingInterval interval : intervals)
        {
            if (interval != null)
            {
                end = Math.max(end, interval.end);
                operationCount += interval.operationCount;
                maxLatency = Math.max(interval.maxLatency, maxLatency);
                totalLatency += interval.totalLatency;
                partitionCount += interval.partitionCount;
                rowCount += interval.rowCount;
                errorCount += interval.errorCount;
                latencies.addAll(Arrays.asList(interval.sample));
                if (interval.pauseLength > 0)
                {
                    pauseStart = Math.max(pauseStart, interval.pauseStart);
                    pauseEnd = Math.min(pauseEnd, interval.pauseStart + interval.pauseLength);
                }
            }
        }

        if (pauseEnd < pauseStart || pauseStart <= 0)
        {
            pauseEnd = pauseStart = 0;
        }

        return new TimingInterval(start, end, maxLatency, pauseStart, pauseEnd - pauseStart, partitionCount, rowCount,
                                  totalLatency, operationCount, errorCount, SampleOfLongs.merge(rnd, latencies, maxSamples));

    }
385569
def timestamp_normalized(self):
        
        if not self.timestamp:
            return None

        if isinstance(self.timestamp, six.integer_types):
            return self.timestamp

        if isinstance(self.timestamp, timedelta):
            tmp = datetime.now() + self.timestamp
        else:
            tmp = self.timestamp

        return int(time.mktime(tmp.timetuple()) * 1e+6 + tmp.microsecond)
633831
def datetime2utsec(t: Union[str, datetime.date, datetime.datetime, np.datetime64]) -> float:
    
    if isinstance(t, (tuple, list, np.ndarray)):
        return np.asarray([datetime2utsec(T) for T in t])
    elif isinstance(t, datetime.date) and not isinstance(t, datetime.datetime):
        return 0.
    elif isinstance(t, np.datetime64):
        t = t.astype(datetime.datetime)
    elif isinstance(t, str):
        t = parse(t)

    return datetime.timedelta.total_seconds(t - datetime.datetime.combine(t.date(),
                                                                          datetime.datetime.min.time()))
81172
def get_csv_event_start(event_buffer):
    

    (start, end) = get_csv_next_event_start(0, event_buffer)
    if start < 0:
        return (-1, -1, "")

    print(event_buffer[start:end])

    tstart = event_buffer.find(",", start)
    tend = event_buffer.find(",", tstart+1)
    print(event_buffer[tstart:tend])
    last_time = event_buffer[tstart+1:tend].replace('"',"")

    while end > 0:
        (start, end) = get_csv_next_event_start(start, event_buffer)
        if end < 0:
            return (-1, -1, "")
        tstart = event_buffer.find(",", start)
        tend = event_buffer.find(",", tstart+1)
        this_time = event_buffer[tstart+1:tend].replace('"',"")
        if this_time != last_time:
            return (start, end + 1, last_time)

    return (-1, -1, "")
1341597
def events(self):
        ''''''
        ret = []
        while True:
            e = self.poll()
            if e is None:
                break
            ret.append(e)
        return ret