本文整理匯總了Python中pytz.UTC屬性的典型用法代碼示例。如果您正苦於以下問題:Python pytz.UTC屬性的具體用法?Python pytz.UTC怎麽用?Python pytz.UTC使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類pytz
的用法示例。
在下文中一共展示了pytz.UTC屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def setup(self, db):
self.a_datetime = datetime.datetime(2018, 2, 2, tzinfo=pytz.UTC)
self.user_attributes = {
'username': 'alpha_one',
'email': 'alpha_one@example.com',
'profile__name': 'Alpha One',
'profile__country': 'CA',
'profile__gender': 'o',
'date_joined': self.a_datetime,
'profile__year_of_birth': 1989,
'profile__level_of_education': 'other',
}
self.user = UserFactory(**self.user_attributes)
self.serializer = GeneralUserDataSerializer(instance=self.user)
self.expected_fields = [
'id', 'username', 'email', 'fullname','country', 'is_active', 'gender',
'date_joined', 'year_of_birth', 'level_of_education', 'courses',
'language_proficiencies',
]
示例2: zservice_get_data
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def zservice_get_data(**kwargs):
"""Simulate what the RPC layer will get from DB """
faketime = datetime.datetime(2001, 1, 1, tzinfo=pytz.UTC)
return {
'binary': kwargs.get('binary', 'fake-binary'),
'host': kwargs.get('host', 'fake-host'),
'id': kwargs.get('id', 13),
'report_count': kwargs.get('report_count', 13),
'disabled': kwargs.get('disabled', False),
'disabled_reason': kwargs.get('disabled_reason'),
'forced_down': kwargs.get('forced_down', False),
'last_seen_up': kwargs.get('last_seen_up', faketime),
'created_at': kwargs.get('created_at', faketime),
'updated_at': kwargs.get('updated_at', faketime),
'availability_zone': kwargs.get('availability_zone', 'fake-zone'),
}
示例3: __init__
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def __init__(self, **params):
try:
timezone = pytz.timezone(params.pop('timezone', None))
except (pytz.UnknownTimeZoneError, AttributeError):
timezone = pytz.UTC
for field in self.__annotations__:
api_field = undo_snake_case_key(field)
if self.__annotations__[field] == datetime:
params[api_field] = get_datetime_from_unix(
params.get(api_field),
timezone
)
if api_field in params:
setattr(self, field, params.get(api_field))
else:
setattr(self, field, None)
示例4: test_frame_align_aware
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def test_frame_align_aware(self):
idx1 = date_range('2001', periods=5, freq='H', tz='US/Eastern')
idx2 = date_range('2001', periods=5, freq='2H', tz='US/Eastern')
df1 = DataFrame(np.random.randn(len(idx1), 3), idx1)
df2 = DataFrame(np.random.randn(len(idx2), 3), idx2)
new1, new2 = df1.align(df2)
assert df1.index.tz == new1.index.tz
assert df2.index.tz == new2.index.tz
# different timezones convert to UTC
# frame with frame
df1_central = df1.tz_convert('US/Central')
new1, new2 = df1.align(df1_central)
assert new1.index.tz == pytz.UTC
assert new2.index.tz == pytz.UTC
# frame with Series
new1, new2 = df1.align(df1_central[0], axis=0)
assert new1.index.tz == pytz.UTC
assert new2.index.tz == pytz.UTC
df1[0].align(df1_central, axis=0)
assert new1.index.tz == pytz.UTC
assert new2.index.tz == pytz.UTC
示例5: test_class_ops_pytz
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
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))
示例6: test_class_ops_dateutil
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
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))
示例7: test_nanosecond_string_parsing
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def test_nanosecond_string_parsing(self):
ts = Timestamp('2013-05-01 07:15:45.123456789')
# GH 7878
expected_repr = '2013-05-01 07:15:45.123456789'
expected_value = 1367392545123456789
assert ts.value == expected_value
assert expected_repr in repr(ts)
ts = Timestamp('2013-05-01 07:15:45.123456789+09:00', tz='Asia/Tokyo')
assert ts.value == expected_value - 9 * 3600 * 1000000000
assert expected_repr in repr(ts)
ts = Timestamp('2013-05-01 07:15:45.123456789', tz='UTC')
assert ts.value == expected_value
assert expected_repr in repr(ts)
ts = Timestamp('2013-05-01 07:15:45.123456789', tz='US/Eastern')
assert ts.value == expected_value + 4 * 3600 * 1000000000
assert expected_repr in repr(ts)
# GH 10041
ts = Timestamp('20130501T071545.123456789')
assert ts.value == expected_value
assert expected_repr in repr(ts)
示例8: check_deleted_clips
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def check_deleted_clips(period, slugs):
"""
Go through any clips we have in the DB that weren't returned from the Twitch
query, and check if they actually exist (maybe they dropped out of the "last
day" early) or if they've been deleted, in which case mark that in the DB.
"""
period = datetime.timedelta(days={'day': 1, 'week': 7, 'month': 28}[period])
start = datetime.datetime.now(pytz.UTC) - period
with engine.begin() as conn:
clips = conn.execute(sqlalchemy.select([TBL_CLIPS.c.id, TBL_CLIPS.c.slug])
.where(TBL_CLIPS.c.time >= start)
.where(TBL_CLIPS.c.slug.notin_(slugs))
.where(TBL_CLIPS.c.deleted == False))
for clipid, slug in clips:
if get_clip_info(slug, check_missing=True) is None:
conn.execute(TBL_CLIPS.update().values(deleted=True).where(TBL_CLIPS.c.id == clipid))
示例9: _manage_time
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def _manage_time(self, now):
last_run = self.last_taxii2_run
if last_run:
last_run = dt_to_millisec(datetime.strptime(self.last_taxii2_run, '%Y-%m-%dT%H:%M:%S.%fZ'))
max_back = now - (self.initial_interval * 1000)
if last_run is None or last_run < max_back:
last_run = max_back
begin = datetime.utcfromtimestamp(last_run / 1000)
begin = begin.replace(tzinfo=pytz.UTC)
end = datetime.utcfromtimestamp(now / 1000)
end = end.replace(tzinfo=pytz.UTC)
if self.lower_timestamp_precision:
end = end.replace(second=0, microsecond=0)
begin = begin.replace(second=0, microsecond=0)
return begin, end
示例10: today
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def today(self):
"""
Return the current date and time.
When the environment variable MASU_DEBUG is set to True,
the MASU_DATE_OVERRIDE environment variable can be used to
override masu's current date and time.
Args:
(None)
Returns:
(datetime.datetime): Current datetime object
example: 2018-07-24 15:47:33
"""
current_date = datetime.now(tz=pytz.UTC)
if Config.DEBUG and DateAccessor.mock_date_time:
seconds_delta = current_date - DateAccessor.date_time_last_accessed
DateAccessor.date_time_last_accessed = current_date
DateAccessor.mock_date_time = DateAccessor.mock_date_time + seconds_delta
current_date = DateAccessor.mock_date_time
return current_date
示例11: ts2date
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def ts2date(timestamp, fmt=None):
import datetime
import pytz
if not timestamp:
return "N/A"
try:
d = datetime.datetime.fromtimestamp(int(timestamp), tz=pytz.UTC)
except BaseException:
d = datetime.datetime.fromtimestamp(0, tz=pytz.UTC)
# return "{:04d}/{:02d}/{:02d} {:02d}:{:02d}".format(d.year, d.month, d.day, d.hour, d.minute)
if fmt is None:
# return d.strftime("%Y/%m/%d %I:%M %p")
return d.strftime("%Y/%m/%d %H:%M")
else:
return d.strftime(fmt)
示例12: get_access_token
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def get_access_token(self):
if not self._state["access_token"] or not self._state["access_token_expiry"] or \
self.access_token_expiry < datetime.datetime.now(tz=pytz.UTC):
try:
self.update_api_keys()
except requests.exceptions.HTTPError:
# Clear token and then try to get a new access_token
self.update_api_keys()
LOG.debug("access_token: %s" %(self._state["access_token"]))
return self._state["access_token"], self._state["access_token_expiry"]
示例13: setUp
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def setUp(self):
self.restaurant_1 = RestaurantFactory.create(opening_time=18, closing_time=23)
self.restaurant_1_table_1 = TableFactory.create(restaurant=self.restaurant_1, size=2)
self.restaurant_1_table_2 = TableFactory.create(restaurant=self.restaurant_1, size=4)
booking_date_time_start = datetime(2015, 2, 14, 19, 0, tzinfo=pytz.UTC)
minutes_slot = 90
delta = timedelta(seconds=60*minutes_slot)
booking_date_time_end = booking_date_time_start + delta
self.booking_1 = BookingFactory.create(
table=self.restaurant_1_table_2,
people=4,
booking_date_time_start=booking_date_time_start,
booking_date_time_end=booking_date_time_end)
示例14: test_get_first_table_available
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def test_get_first_table_available(self):
table = booking.get_first_table_available(
restaurant=self.restaurant_1,
booking_date_time=datetime(2015, 2, 14, 20, 0, tzinfo=pytz.UTC),
people=2)
self.assertEqual(table.id, self.restaurant_1_table_1.id)
示例15: test_get_first_table_available_unavailable_1
# 需要導入模塊: import pytz [as 別名]
# 或者: from pytz import UTC [as 別名]
def test_get_first_table_available_unavailable_1(self):
# The setup already books the 4 people table from 19:00 to 20:30
table = booking.get_first_table_available(
restaurant=self.restaurant_1,
booking_date_time=datetime(2015, 2, 14, 20, 0, tzinfo=pytz.UTC),
people=4)
self.assertEqual(table, None)