def time_to_unix_timestamp(t): if t.tzinfo: return (t - _epoch).total_seconds() else: return long( time.mktime( (t.year, t.month, t.day, t.hour, t.minute, t.second, -1, -1, -1))) + long(local_tz.utcoffset(t).total_seconds())
def convert_time_couple_to_qdb_filtered_range_t(time_couple): rng = impl.qdb_ts_filtered_range_t() rng.range.begin.tv_sec = time_to_unix_timestamp(time_couple[0]) rng.range.begin.tv_nsec = time_couple[0].microsecond * long(1000) rng.range.end.tv_sec = time_to_unix_timestamp(time_couple[1]) rng.range.end.tv_nsec = time_couple[1].microsecond * long(1000) rng.filter.type = TSFilter.none return rng
def make_qdb_ts_timestamp_point_vector(time_points): vec = TimestampPointsVector() c = len(time_points) vec.resize(c) for i in xrange(c): vec[i].timestamp.tv_sec = time_to_unix_timestamp(time_points[i][0]) vec[i].timestamp.tv_nsec = time_points[i][0].microsecond * long(1000) vec[i].value.tv_sec = time_to_unix_timestamp(time_points[i][1]) vec[i].value.tv_nsec = time_points[i][1].microsecond * long(1000) return vec
def convert_time_to_qdb_timespec(python_time): res = impl.qdb_timespec_t() res.tv_sec = time_to_unix_timestamp(python_time) res.tv_nsec = python_time.microsecond * long(1000) return res
def t_ANY_int(t): t.type = 'PP_NUMBER' m = t.lexer.lexmatch if "L" in m.group(3) or "l" in m.group(2): prefix = "l" else: prefix = "i" g1 = m.group(2) if g1.startswith("0x"): # Convert base from hexadecimal g1 = str(long(g1[2:], 16)) elif g1[0] == "0": # Convert base from octal g1 = str(long(g1, 8)) t.value = prefix + g1 return t
def _to_timestamp(v): # Expects Value to be either date or datetime try: converted = calendar.timegm(v.utctimetuple()) converted = converted * 1e3 + getattr(v, 'microsecond', 0) / 1e3 except AttributeError: # Ints and floats are valid timestamps too if type(v) not in _number_types: raise TypeError('DateType arguments must be a datetime or timestamp') converted = v * 1e3 return long(converted)
def convert_to_wrap_ts_blop_points_vector(tuples): vec = BlobPointsVector() c = len(tuples) vec.resize(c) for i in xrange(c): vec[i].timestamp.tv_sec = time_to_unix_timestamp(tuples[i][0]) vec[i].timestamp.tv_nsec = tuples[i][0].microsecond * long(1000) vec[i].data = tuples[i][1] return vec
def _to_timestamp(v, use_micros=False): # Expects Value to be either date or datetime if use_micros: scale = 1e6 micro_scale = 1.0 else: scale = 1e3 micro_scale = 1e3 try: converted = calendar.timegm(v.utctimetuple()) converted = (converted * scale) + \ (getattr(v, 'microsecond', 0) / micro_scale) except AttributeError: # Ints and floats are valid timestamps too if type(v) not in marshal._number_types: raise TypeError('DateType arguments must be a datetime or timestamp') converted = v * scale return long(converted)
def p_constant(p): '''constant : CONSTANT | CHARACTER_CONSTANT ''' constant = p[1] if constant[0] == "'": # Character constant value = constant[1:-1] else: # This is a value formatted the way that the preprocessor formats # numeric constants. It puts a prefix "l", "i", or "f" to indicate # if it should be converted into an integer, long or float. prefix = constant[0] constant = constant[1:] if prefix == "i": value = int(constant) elif prefix == "l": value = long(constant) else: value = float(constant) p[0] = expressions.ConstantExpressionNode(value)
def __long__(self): return long(self.data) def __float__(self): return float(self.data)
def convert_expiry_time(expiry_time): return time_to_qdb_timestamp(expiry_time) if expiry_time != None else long( 0)
def time_to_qdb_timestamp(t): return time_to_unix_timestamp(t) * long(1000) + t.microsecond / long(1000)
def duration_to_timeout_ms(duration): seconds_in_day = long(24) * long(60) * long(60) return ((duration.days * seconds_in_day + duration.seconds) * long(1000) + (duration.microseconds // long(1000)))