def test_class_ops_dateutil(self): def compare(x, y): assert ( int( np.round(Timestamp(x).value / 1e9) - np.round(Timestamp(y).value / 1e9) ) == 0 ) compare(Timestamp.now(), datetime.now()) compare(Timestamp.now("UTC"), datetime.now(tzutc())) compare(Timestamp.utcnow(), datetime.utcnow()) compare(Timestamp.today(), datetime.today()) current_time = calendar.timegm(datetime.now().utctimetuple()) compare( Timestamp.utcfromtimestamp(current_time), datetime.utcfromtimestamp(current_time), ) compare( Timestamp.fromtimestamp(current_time), datetime.fromtimestamp(current_time) ) date_component = datetime.utcnow() time_component = (date_component + timedelta(minutes=10)).time() compare( Timestamp.combine(date_component, time_component), datetime.combine(date_component, time_component), )
async def get_kline_histories(self, symbol: str, from_ts: Optional[int] = None, limit: Optional[int] = None): market, code = symbol.split('.') if market == 'FOREX': local_tz = tzlocal.get_localzone() _end = local_tz.localize(Timestamp.now()) if from_ts: _start = local_tz.localize( Timestamp.fromtimestamp(from_ts / 1000)) else: _start = _end - Timedelta(minutes=limit - 1) if _start >= _end: return [] _start = _start.astimezone(self._server_tz) _end = _end.astimezone(self._server_tz) self._kline_resp[code] = Queue() await self._connector._DWX_MTX_SEND_HIST_REQUEST_( _symbol=code, _timeframe=1, _start=_start.strftime('%Y.%m.%d %H:%M:00'), _end=_end.strftime('%Y.%m.%d %H:%M:00')) klines = [ self._parse_kline(kline_raw) for kline_raw in await self._kline_resp[code].get() ] del self._kline_resp[code] return klines else: return []
def test_class_ops_dateutil(self): def compare(x, y): assert (int( np.round(Timestamp(x).value / 1e9) - np.round(Timestamp(y).value / 1e9)) == 0) compare(Timestamp.now(), datetime.now()) compare(Timestamp.now("UTC"), datetime.now(tzutc())) compare(Timestamp.utcnow(), datetime.utcnow()) compare(Timestamp.today(), datetime.today()) current_time = calendar.timegm(datetime.now().utctimetuple()) msg = "timezone-aware Timestamp with UTC" with tm.assert_produces_warning(FutureWarning, match=msg): # GH#22451 ts_utc = Timestamp.utcfromtimestamp(current_time) compare( ts_utc, datetime.utcfromtimestamp(current_time), ) compare(Timestamp.fromtimestamp(current_time), datetime.fromtimestamp(current_time)) date_component = datetime.utcnow() time_component = (date_component + timedelta(minutes=10)).time() compare( Timestamp.combine(date_component, time_component), datetime.combine(date_component, time_component), )
def test_add_mtime(self, app): input_amount = 10 test_input = pandas.DataFrame({'seq': range(0, input_amount)}) test_mtime = int(time.time()) expected_mtime = Timestamp.fromtimestamp(test_mtime).tz_localize( LOCAL_TZ).tz_convert(pytz.UTC).replace(tzinfo=None) with app.app_context(): result = fruits._add_mtime(test_input, test_mtime) assert len(result[result['mtime'] == expected_mtime]) == input_amount
def test_class_ops_pytz(self): def compare(x, y): assert int((Timestamp(x).value - Timestamp(y).value) / 1e9) == 0 compare(Timestamp.now(), datetime.now()) compare(Timestamp.now("UTC"), datetime.now(timezone("UTC"))) compare(Timestamp.utcnow(), datetime.utcnow()) compare(Timestamp.today(), datetime.today()) current_time = calendar.timegm(datetime.now().utctimetuple()) msg = "timezone-aware Timestamp with UTC" with tm.assert_produces_warning(FutureWarning, match=msg): # GH#22451 ts_utc = Timestamp.utcfromtimestamp(current_time) compare( ts_utc, datetime.utcfromtimestamp(current_time), ) compare( Timestamp.fromtimestamp(current_time), datetime.fromtimestamp(current_time) ) compare( # Support tz kwarg in Timestamp.fromtimestamp Timestamp.fromtimestamp(current_time, "UTC"), datetime.fromtimestamp(current_time, utc), ) compare( # Support tz kwarg in Timestamp.fromtimestamp Timestamp.fromtimestamp(current_time, tz="UTC"), datetime.fromtimestamp(current_time, utc), ) date_component = datetime.utcnow() time_component = (date_component + timedelta(minutes=10)).time() compare( Timestamp.combine(date_component, time_component), datetime.combine(date_component, time_component), )
def test_class_ops_pytz(self): def compare(x, y): assert (int(Timestamp(x).value / 1e9) == int( Timestamp(y).value / 1e9)) compare(Timestamp.now(), datetime.now()) compare(Timestamp.now('UTC'), datetime.now(timezone('UTC'))) compare(Timestamp.utcnow(), datetime.utcnow()) compare(Timestamp.today(), datetime.today()) current_time = calendar.timegm(datetime.now().utctimetuple()) compare(Timestamp.utcfromtimestamp(current_time), datetime.utcfromtimestamp(current_time)) compare(Timestamp.fromtimestamp(current_time), datetime.fromtimestamp(current_time)) date_component = datetime.utcnow() time_component = (date_component + timedelta(minutes=10)).time() compare(Timestamp.combine(date_component, time_component), datetime.combine(date_component, time_component))
def test_class_ops_dateutil(self): def compare(x, y): assert (int(np.round(Timestamp(x).value / 1e9)) == int(np.round(Timestamp(y).value / 1e9))) compare(Timestamp.now(), datetime.now()) compare(Timestamp.now('UTC'), datetime.now(tzutc())) compare(Timestamp.utcnow(), datetime.utcnow()) compare(Timestamp.today(), datetime.today()) current_time = calendar.timegm(datetime.now().utctimetuple()) compare(Timestamp.utcfromtimestamp(current_time), datetime.utcfromtimestamp(current_time)) compare(Timestamp.fromtimestamp(current_time), datetime.fromtimestamp(current_time)) date_component = datetime.utcnow() time_component = (date_component + timedelta(minutes=10)).time() compare(Timestamp.combine(date_component, time_component), datetime.combine(date_component, time_component))
def time_fromtimestamp(self): Timestamp.fromtimestamp(1515448538)