当前位置: 首页>>代码示例>>Python>>正文


Python pytz.UTC属性代码示例

本文整理汇总了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',
        ] 
开发者ID:appsembler,项目名称:figures,代码行数:23,代码来源:test_serializers.py

示例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'),
    } 
开发者ID:openstack,项目名称:zun,代码行数:18,代码来源:utils.py

示例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) 
开发者ID:Detrous,项目名称:darksky,代码行数:20,代码来源:base.py

示例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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:test_timezones.py

示例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)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_timestamp.py

示例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)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_timestamp.py

示例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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:test_timestamp.py

示例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)) 
开发者ID:mrphlip,项目名称:lrrbot,代码行数:18,代码来源:find_clips.py

示例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 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:21,代码来源:taxii2.py

示例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 
开发者ID:project-koku,项目名称:koku,代码行数:26,代码来源:date_accessor.py

示例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) 
开发者ID:Kivou-2000607,项目名称:yata,代码行数:19,代码来源:app_filters.py

示例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"] 
开发者ID:kmac,项目名称:mlbv,代码行数:14,代码来源:mlbsession.py

示例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) 
开发者ID:andreagrandi,项目名称:booking-example,代码行数:17,代码来源:test_booking.py

示例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) 
开发者ID:andreagrandi,项目名称:booking-example,代码行数:8,代码来源:test_booking.py

示例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) 
开发者ID:andreagrandi,项目名称:booking-example,代码行数:9,代码来源:test_booking.py


注:本文中的pytz.UTC属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。