Python pytz.FixedOffset() Examples
The following are 30
code examples of pytz.FixedOffset().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pytz
, or try the search function
.
Example #1
Source File: location.py From pvlib-python with BSD 3-Clause "New" or "Revised" License | 7 votes |
def __init__(self, latitude, longitude, tz='UTC', altitude=0, name=None, **kwargs): self.latitude = latitude self.longitude = longitude if isinstance(tz, str): self.tz = tz self.pytz = pytz.timezone(tz) elif isinstance(tz, datetime.timezone): self.tz = 'UTC' self.pytz = pytz.UTC elif isinstance(tz, datetime.tzinfo): self.tz = tz.zone self.pytz = tz elif isinstance(tz, (int, float)): self.tz = tz self.pytz = pytz.FixedOffset(tz*60) else: raise TypeError('Invalid tz specification') self.altitude = altitude self.name = name
Example #2
Source File: simp_le.py From simp_le with GNU General Public License v3.0 | 6 votes |
def asn1_generalizedtime_to_dt(timestamp): """Convert ASN.1 GENERALIZEDTIME to datetime. Useful for deserialization of `OpenSSL.crypto.X509.get_notAfter` and `OpenSSL.crypto.X509.get_notAfter` outputs. TODO: Implement remaining two formats: *+hhmm, *-hhmm. >>> asn1_generalizedtime_to_dt('201511150803Z') datetime.datetime(2015, 11, 15, 8, 0, 3, tzinfo=<UTC>) >>> asn1_generalizedtime_to_dt('201511150803+1512') datetime.datetime(2015, 11, 15, 8, 0, 3, tzinfo=pytz.FixedOffset(912)) >>> asn1_generalizedtime_to_dt('201511150803-1512') datetime.datetime(2015, 11, 15, 8, 0, 3, tzinfo=pytz.FixedOffset(-912)) """ dt = datetime.datetime.strptime( # pylint: disable=invalid-name timestamp[:12], '%Y%m%d%H%M%S') # tzinfo, pylint bug | pylint: disable=redefined-variable-type if timestamp.endswith('Z'): tzinfo = pytz.utc else: sign = -1 if timestamp[-5] == '-' else 1 tzinfo = pytz.FixedOffset( sign * (int(timestamp[-4:-2]) * 60 + int(timestamp[-2:]))) return tzinfo.localize(dt)
Example #3
Source File: brother2.py From trader with Apache License 2.0 | 6 votes |
def update_position(self): for _, pos in self.__shares.items(): inst = Instrument.objects.filter( exchange=pos['ExchangeID'], product_code=re.findall('[A-Za-z]+', pos['InstrumentID'])[0]).first() tick = json.loads(self.redis_client.get(pos['InstrumentID'])) if pos['Direction'] == ApiStruct.D_Buy: profit = Decimal(tick['LastPrice']) - Decimal(pos['OpenPrice']) else: profit = Decimal(pos['OpenPrice']) - Decimal(tick['LastPrice']) profit = profit * Decimal(pos['Volume']) * inst.volume_multiple Trade.objects.update_or_create( broker=self.__broker, strategy=self.__strategy, instrument=inst, code=pos['InstrumentID'], direction=DirectionType.LONG if pos['Direction'] == ApiStruct.D_Buy else DirectionType.SHORT, close_time__isnull=True, defaults={ 'open_time': datetime.datetime.strptime( pos['OpenDate']+'09', '%Y%m%d%H').replace(tzinfo=pytz.FixedOffset(480)), 'shares': pos['Volume'], 'filled_shares': pos['Volume'], 'avg_entry_price': Decimal(pos['OpenPrice']), 'cost': pos['Volume'] * Decimal(pos['OpenPrice']) * inst.fee_money * inst.volume_multiple + pos['Volume'] * inst.fee_volume, 'profit': profit, 'frozen_margin': Decimal(pos['Margin'])})
Example #4
Source File: brother2.py From trader with Apache License 2.0 | 6 votes |
def start(self): self.redis_client.set('HEARTBEAT:TRADER', 1, ex=61) await self.query('TradingAccount') self.__shares.clear() await self.query('InvestorPositionDetail') # await self.collect_tick_stop() # await self.collect_quote() # day = datetime.datetime.strptime('20161031', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480)) # for inst in self.__strategy.instruments.all(): # # self.calc_signal(inst, day) # self.process_signal(inst) # order_list = await self.query('Order') # if order_list: # for order in order_list: # if order['OrderStatus'] == ApiStruct.OST_NotTouched and \ # order['OrderSubmitStatus'] == ApiStruct.OSS_InsertSubmitted: # self.__activeOrders[order['OrderRef']] = order # logger.info("未成交订单: %s", self.__activeOrders) # inst_set = list() # for inst in Instrument.objects.all(): # inst_set += inst.all_inst.split(',') # await self.SubscribeMarketData(inst_set)
Example #5
Source File: test_parse_dates.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_parse_timezone(all_parsers): # see gh-22256 parser = all_parsers data = """dt,val 2018-01-04 09:01:00+09:00,23350 2018-01-04 09:02:00+09:00,23400 2018-01-04 09:03:00+09:00,23400 2018-01-04 09:04:00+09:00,23400 2018-01-04 09:05:00+09:00,23400""" result = parser.read_csv(StringIO(data), parse_dates=["dt"]) dti = pd.date_range(start="2018-01-04 09:01:00", end="2018-01-04 09:05:00", freq="1min", tz=pytz.FixedOffset(540)) expected_data = {"dt": dti, "val": [23350, 23400, 23400, 23400, 23400]} expected = DataFrame(expected_data) tm.assert_frame_equal(result, expected)
Example #6
Source File: fetch_data.py From trader with Apache License 2.0 | 6 votes |
def fetch_bar2(): day = datetime.datetime.strptime('20160114', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480)) end = datetime.datetime.strptime('20160914', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480)) while day <= end: day, trading = await is_trading_day(day) if trading: print('process ', day) tasks = [ asyncio.ensure_future(update_from_shfe(day)), asyncio.ensure_future(update_from_dce(day)), asyncio.ensure_future(update_from_czce(day)), asyncio.ensure_future(update_from_cffex(day)), ] await asyncio.wait(tasks) day += datetime.timedelta(days=1) print('all done!') # asyncio.get_event_loop().run_until_complete(fetch_bar2()) # create_main_all() # fetch_from_quandl_all() # clean_dailybar() # load_kt_data()
Example #7
Source File: test_query_builder.py From pysnow with MIT License | 6 votes |
def test_query_cond_less_than_or_equal(self): # Make sure type checking works q1 = pysnow.QueryBuilder().field("test") self.assertRaises(QueryTypeError, q1.less_than_or_equal, "a") # Make sure a valid operation works q2 = pysnow.QueryBuilder().field("test").less_than_or_equal(1) self.assertEqual(str(q2), "test<=1") # Make sure naive dates are assumed as UTC q3 = pysnow.QueryBuilder().field("test").less_than_or_equal(dt(2016, 2, 1)) self.assertEqual(str(q3), "test<=2016-02-01 00:00:00") # Make sure tz-aware dates are converted to UTC (UTC+1) q3 = ( pysnow.QueryBuilder() .field("test") .less_than_or_equal(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60))) ) self.assertEqual(str(q3), "test<=2016-02-01 02:00:00")
Example #8
Source File: test_query_builder.py From pysnow with MIT License | 6 votes |
def test_query_cond_less_than(self): # Make sure type checking works q1 = pysnow.QueryBuilder().field("test") self.assertRaises(QueryTypeError, q1.less_than, "a") # Make sure a valid operation works q2 = pysnow.QueryBuilder().field("test").less_than(1) self.assertEqual(str(q2), "test<1") # Make sure naive dates are assumed as UTC q3 = pysnow.QueryBuilder().field("test").less_than(dt(2016, 2, 1)) self.assertEqual(str(q3), "test<2016-02-01 00:00:00") # Make sure tz-aware dates are converted to UTC (UTC+1) q3 = ( pysnow.QueryBuilder() .field("test") .less_than(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60))) ) self.assertEqual(str(q3), "test<2016-02-01 02:00:00")
Example #9
Source File: test_query_builder.py From pysnow with MIT License | 6 votes |
def test_query_cond_greater_than(self): # Make sure type checking works q1 = pysnow.QueryBuilder().field("test") self.assertRaises(QueryTypeError, q1.greater_than, "a") # Make sure a valid operation works q2 = pysnow.QueryBuilder().field("test").greater_than(1) self.assertEqual(str(q2), "test>1") # Make sure naive dates are assumed as UTC q3 = pysnow.QueryBuilder().field("test").greater_than(dt(2016, 2, 1)) self.assertEqual(str(q3), "test>2016-02-01 00:00:00") # Make sure tz-aware dates are converted to UTC (UTC+1) q4 = ( pysnow.QueryBuilder() .field("test") .greater_than(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60))) ) self.assertEqual(str(q4), "test>2016-02-01 02:00:00")
Example #10
Source File: brother2.py From trader with Apache License 2.0 | 6 votes |
def update_equity(self): today, trading = await is_trading_day(datetime.datetime.today().replace(tzinfo=pytz.FixedOffset(480))) if trading: logger.info('更新资金净值 %s %s', today, trading) dividend = Performance.objects.filter( broker=self.__broker, day__lt=today.date()).aggregate(Sum('dividend'))['dividend__sum'] if dividend is None: dividend = Decimal(0) perform = Performance.objects.filter( broker=self.__broker, day__lt=today.date()).order_by('-day').first() if perform is None: unit = Decimal(1000000) else: unit = perform.unit_count nav = self.__current / unit accumulated = (self.__current - dividend) / (unit - dividend) Performance.objects.update_or_create(broker=self.__broker, day=today.date(), defaults={ 'used_margin': self.__margin, 'capital': self.__current, 'unit_count': unit, 'NAV': nav, 'accumulated': accumulated})
Example #11
Source File: test_criterion.py From pysnow with MIT License | 6 votes |
def test_query_cond_less_than_or_equal(self): # Make sure type checking works q1 = Field("test") self.assertRaises(QueryTypeError, q1.lte, "a") # Make sure a valid operation works q2 = Field("test").lte(1) self.assertEqual(str(q2), "test<=1") # Make sure naive dates are assumed as UTC q3 = Field("test").lte(dt(2016, 2, 1)) self.assertEqual(str(q3), 'test<=javascript:gs.dateGenerate("2016-02-01 00:00:00")') # Make sure tz-aware dates are converted to UTC (UTC+1) q3 = ( Field("test") .lte(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60))) ) self.assertEqual(str(q3), 'test<=javascript:gs.dateGenerate("2016-02-01 02:00:00")')
Example #12
Source File: test_criterion.py From pysnow with MIT License | 6 votes |
def test_query_cond_greater_than_or_equal(self): # Make sure type checking works q1 = Field("test") self.assertRaises(QueryTypeError, q1.gte, "a") # Make sure a valid operation works q2 = Field("test").gte(1) self.assertEqual(str(q2), "test>=1") # Make sure naive dates are assumed as UTC q3 = Field("test").gte(dt(2016, 2, 1)) self.assertEqual(str(q3), 'test>=javascript:gs.dateGenerate("2016-02-01 00:00:00")') # Make sure tz-aware dates are converted to UTC (UTC+1) q4 = ( Field("test") .gte(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60))) ) self.assertEqual(str(q4), 'test>=javascript:gs.dateGenerate("2016-02-01 02:00:00")')
Example #13
Source File: test_criterion.py From pysnow with MIT License | 6 votes |
def test_query_cond_less_than(self): # Make sure type checking works q1 = Field("test") self.assertRaises(QueryTypeError, q1.lt, "a") # Make sure a valid operation works q2 = Field("test").lt(1) self.assertEqual(str(q2), "test<1") # Make sure naive dates are assumed as UTC q3 = Field("test").lt(dt(2016, 2, 1)) self.assertEqual(str(q3), 'test<javascript:gs.dateGenerate("2016-02-01 00:00:00")') # Make sure tz-aware dates are converted to UTC (UTC+1) q3 = ( Field("test") .lt(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60))) ) self.assertEqual(str(q3), 'test<javascript:gs.dateGenerate("2016-02-01 02:00:00")')
Example #14
Source File: test_criterion.py From pysnow with MIT License | 6 votes |
def test_query_cond_greater_than(self): # Make sure type checking works q1 = Field("test") self.assertRaises(QueryTypeError, q1.gt, "a") # Make sure a valid operation works q2 = Field("test").gt(1) self.assertEqual(str(q2), "test>1") # Make sure naive dates are assumed as UTC q3 = Field("test").gt(dt(2016, 2, 1)) self.assertEqual(str(q3), 'test>javascript:gs.dateGenerate("2016-02-01 00:00:00")') # Make sure tz-aware dates are converted to UTC (UTC+1) q4 = ( Field("test") .gt(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60))) ) self.assertEqual(str(q4), 'test>javascript:gs.dateGenerate("2016-02-01 02:00:00")')
Example #15
Source File: test_parse_dates.py From recruit with Apache License 2.0 | 6 votes |
def test_parse_timezone(all_parsers): # see gh-22256 parser = all_parsers data = """dt,val 2018-01-04 09:01:00+09:00,23350 2018-01-04 09:02:00+09:00,23400 2018-01-04 09:03:00+09:00,23400 2018-01-04 09:04:00+09:00,23400 2018-01-04 09:05:00+09:00,23400""" result = parser.read_csv(StringIO(data), parse_dates=["dt"]) dti = pd.date_range(start="2018-01-04 09:01:00", end="2018-01-04 09:05:00", freq="1min", tz=pytz.FixedOffset(540)) expected_data = {"dt": dti, "val": [23350, 23400, 23400, 23400, 23400]} expected = DataFrame(expected_data) tm.assert_frame_equal(result, expected)
Example #16
Source File: test_timestamp.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_construct_with_different_string_format(self, arg): # GH 12064 result = Timestamp(arg) expected = Timestamp(datetime(2013, 1, 1), tz=pytz.FixedOffset(540)) assert result == expected
Example #17
Source File: __init__.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def __reduce__(self): return FixedOffset, (self._minutes, )
Example #18
Source File: tools.py From Computable with MIT License | 5 votes |
def _maybe_get_tz(tz): if isinstance(tz, compat.string_types): import pytz tz = pytz.timezone(tz) if com.is_integer(tz): import pytz tz = pytz.FixedOffset(tz / 60) return tz
Example #19
Source File: __init__.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def __repr__(self): return 'pytz.FixedOffset(%d)' % self._minutes
Example #20
Source File: __init__.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def __reduce__(self): return FixedOffset, (self._minutes, )
Example #21
Source File: __init__.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def __reduce__(self): return FixedOffset, (self._minutes, )
Example #22
Source File: __init__.py From bioforum with MIT License | 5 votes |
def __repr__(self): return 'pytz.FixedOffset(%d)' % self._minutes
Example #23
Source File: __init__.py From bioforum with MIT License | 5 votes |
def __reduce__(self): return FixedOffset, (self._minutes, )
Example #24
Source File: tests.py From django-postgres-queue with BSD 2-Clause "Simplified" License | 5 votes |
def test_every_dow_different_time_zones(self): now = tztime('UTC', 2019, 11, 4, 0, 0, 0) n = every_dow_at(6, datetime.time(22), pytz.FixedOffset(-180))(now) self.assertEqual(n, tztime(pytz.FixedOffset(-180), 2019, 11, 3, 22))
Example #25
Source File: tests.py From django-postgres-queue with BSD 2-Clause "Simplified" License | 5 votes |
def test_every_day_different_time_zones(self): now = tztime('UTC', 2019, 11, 3, 0, 0, 0) n = every_day_at(datetime.time(22), pytz.FixedOffset(-180))(now) self.assertEqual(n, tztime(pytz.FixedOffset(-180), 2019, 11, 2, 22))
Example #26
Source File: mailnotify.py From sndlatr with Apache License 2.0 | 5 votes |
def _get_localtime(send_job): timezone = pytz.FixedOffset(-send_job.utc_offset) time = pytz.utc.localize(send_job.scheduled_at) localtime = time.astimezone(timezone) return localtime
Example #27
Source File: __init__.py From sndlatr with Apache License 2.0 | 5 votes |
def __repr__(self): return 'pytz.FixedOffset(%d)' % self._minutes
Example #28
Source File: __init__.py From sndlatr with Apache License 2.0 | 5 votes |
def __reduce__(self): return FixedOffset, (self._minutes, )
Example #29
Source File: __init__.py From vnpy_crypto with MIT License | 5 votes |
def __repr__(self): return 'pytz.FixedOffset(%d)' % self._minutes
Example #30
Source File: __init__.py From pmatic with GNU General Public License v2.0 | 5 votes |
def __reduce__(self): return FixedOffset, (self._minutes, )