How to use the pytz.UTC function in pytz

To help you get started, we’ve selected a few pytz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openeemeter / eemeter / tests / structures / test_intervention.py View on Github external
def test_ok_start_only():
    intervention = Intervention(datetime(2000, 1, 1, tzinfo=pytz.UTC))
    assert intervention.start_date == datetime(2000, 1, 1, tzinfo=pytz.UTC)
    assert intervention.end_date is None
github inducer / relate / tests / test_models.py View on Github external
def test_last_activity(self):
        fs = factories.FlowSessionFactory(participation=self.participation)
        fpdata = factories.FlowPageDataFactory(flow_session=fs)
        factories.FlowPageVisitFactory(
            page_data=fpdata, answer=None,
            visit_time=datetime(2019, 1, 1, tzinfo=pytz.UTC)
        )
        factories.FlowPageVisitFactory(
            page_data=fpdata, answer=None,
            visit_time=datetime(2019, 1, 2, tzinfo=pytz.UTC)
        )
        self.assertEqual(fs.last_activity(), None)

        fpv = factories.FlowPageVisitFactory(
            page_data=fpdata, answer={"answer": "hi"},
            visit_time=datetime(2018, 12, 31, tzinfo=pytz.UTC)
        )

        self.assertEqual(fs.last_activity(), fpv.visit_time)
github opentok / Opentok-Python-SDK / tests / test_archive_api.py View on Github external
expect(httpretty.last_request().headers[u('content-type')]).to(equal(u('application/json')))
        # non-deterministic json encoding. have to decode to test it properly
        if PY2:
            body = json.loads(httpretty.last_request().body)
        if PY3:
            body = json.loads(httpretty.last_request().body.decode('utf-8'))
        expect(body).to(have_key(u('sessionId'), u('SESSIONID')))
        expect(body).to(have_key(u('name'), u('ARCHIVE NAME')))
        expect(archive).to(be_an(Archive))
        expect(archive).to(have_property(u('id'), u('30b3ebf1-ba36-4f5b-8def-6f70d9986fe9')))
        expect(archive).to(have_property(u('name'), ('ARCHIVE NAME')))
        expect(archive).to(have_property(u('status'), u('started')))
        expect(archive).to(have_property(u('session_id'), u('SESSIONID')))
        expect(archive).to(have_property(u('partner_id'), 123456))
        if PY2:
            created_at = datetime.datetime.fromtimestamp(1395183243, pytz.UTC)
        if PY3:
            created_at = datetime.datetime.fromtimestamp(1395183243, datetime.timezone.utc)
        expect(archive).to(have_property(u('created_at'), equal(created_at)))
        expect(archive).to(have_property(u('size'), equal(0)))
        expect(archive).to(have_property(u('duration'), equal(0)))
        expect(archive).to(have_property(u('url'), equal(None)))
github openeemeter / eemeter / tests / modeling / test_caltrack_formatter.py View on Github external
def daily_trace():
    data = {"value": np.ones(60) * 1}
    columns = ["value", "estimated"]
    index = pd.date_range('2000-01-01', periods=60, freq='D', tz=pytz.UTC)
    df = pd.DataFrame(data, index=index, columns=columns)
    return EnergyTrace("ELECTRICITY_CONSUMPTION_SUPPLIED", df, unit="KWH")
github flectra-hq / flectra / flectra / addons / base / ir / ir_fields.py View on Github external
def _str_to_datetime(self, model, field, value):
        try:
            parsed_value = fields.Datetime.from_string(value)
        except ValueError:
            raise self._format_import_error(
                ValueError,
                _(u"'%s' does not seem to be a valid datetime for field '%%(field)s'"),
                value,
                {'moreinfo': _(u"Use the format '%s'") % u"2012-12-31 23:59:59"}
            )

        input_tz = self._input_tz()# Apply input tz to the parsed naive datetime
        dt = input_tz.localize(parsed_value, is_dst=False)
        # And convert to UTC before reformatting for writing
        return fields.Datetime.to_string(dt.astimezone(pytz.UTC)), []
github LonamiWebs / Lonabot / lonabot / bot.py View on Github external
if not due:
            if msg.chat.type == 'private':
                await self.sendMessage(
                    chat_id=chat_id,
                    text=f'What time is that?\n\n{TEACH_USAGE}',
                    parse_mode='markdown'
                )
            else:
                await self.sendMessage(
                    chat_id=chat_id,
                    text=f'What time is that? ([Start me in private]'
                         f'(https://t.me/{self._me.username}?start=help) for help)',
                    parse_mode='markdown',
                    disable_web_page_preview=True
                )
        elif due > int(datetime.now(tz=pytz.UTC).timestamp() + MAX_DELAY_TIME):
            await self.sendSticker(chat_id=chat_id,
                                   sticker=CAN_U_DONT)
        else:
            reminder_id = self.db.add_reminder(
                update=update,
                due=due,
                text=text,
                file_type=file_type,
                file_id=file_id,
                reply_id=reply_id
            )
            self._sched_reminder(reminder_id, due)
            spelt = utils.spell_due(due, utc_now, time_delta)
            await self.sendMessage(chat_id=chat_id,
                                   text=f'Got it! New reminder {spelt} saved')
github apache / incubator-sdap-nexus / client / nexuscli / nexuscli.py View on Github external
ISO_FORMAT),
                                                                                          end_datetime.strftime(
                                                                                              ISO_FORMAT),
                                                                                          dataset)

    time_series_result = []

    key_to_index = {k: x for x, k in enumerate(data[0].keys())}

    time_series_data = np.array([tuple(each.values()) for each in [entry for entry in data]])

    if len(time_series_data) > 0:
        time_series_result.append(
            TimeSeries(
                dataset=dataset,
                time=np.array([datetime.utcfromtimestamp(t).replace(tzinfo=UTC) for t in
                               time_series_data[:, key_to_index['time']]]),
                mean=time_series_data[:, key_to_index['mean']],
                standard_deviation=time_series_data[:, key_to_index['std']],
                count=None,
                minimum=None,
                maximum=None,
            )
        )

    return time_series_result
github BrainPad / FindYourCandy / webapp / candysorter / ext / google / cloud / ml / job.py View on Github external
def _rfc3339_to_datetime(dt_str):
    return datetime.datetime.strptime(dt_str, _RFC3339_SECONDS).replace(tzinfo=UTC)
github pimutils / khal / khal / utils.py View on Github external
def to_naive_utc(dtime):
    """convert a datetime object to UTC and than remove the tzinfo, if
    datetime is naive already, return it
    """
    if not hasattr(dtime, 'tzinfo') or dtime.tzinfo is None:
        return dtime

    dtime_utc = dtime.astimezone(pytz.UTC)
    dtime_naive = dtime_utc.replace(tzinfo=None)
    return dtime_naive
github ClusterHQ / flocker / flocker / control / _persistence.py View on Github external
def _expire(self):
        now = datetime.fromtimestamp(self._reactor.seconds(), tz=UTC)

        def expire(leases):
            updated_leases = leases.expire(now)
            for dataset_id in set(leases) - set(updated_leases):
                _LOG_EXPIRE(dataset_id=dataset_id,
                            node_id=leases[dataset_id].node_id).write()
            return updated_leases
        return update_leases(expire, self._persistence_service)