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 nditech / apollo / apollo / frontend / views_admin.py View on Github external
from flask.ext.admin.model.form import converts
from flask.ext.babel import lazy_gettext as _
from flask.ext.mongoengine.wtf import orm
from flask.ext.security import current_user
from flask.ext.security.utils import encrypt_password
from jinja2 import contextfunction
import magic
import pytz
from wtforms import FileField, PasswordField, SelectMultipleField
from apollo.core import admin
from apollo import models, settings
from apollo.frontend import forms


app_time_zone = pytz.timezone(settings.TIMEZONE)
utc_time_zone = pytz.utc

excluded_perm_actions = [u'view_forms', u'access_event']

DATETIME_FORMAT_SPEC = u'%Y-%m-%d %H:%M:%S %Z'

try:
    string_type = unicode
except NameError:
    string_type = str


class DeploymentModelConverter(CustomModelConverter):
    @converts('ParticipantPropertyName')
    def conv_PropertyField(self, model, field, kwargs):
        return orm.ModelConverter.conv_String(self, model, field, kwargs)
github insightfinder / InsightAgent / tcpdump / getlogs_tcpdump.py View on Github external
def get_timestamp_from_datetime(timestamp_datetime):
    timestamp_localize = cli_config_vars['time_zone'].localize(timestamp_datetime)

    epoch = long((timestamp_localize - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
    return epoch
github gratipay / gratipay.com / gittip / models / participant.py View on Github external
def from_session_token(cls, token):
        """Return an existing participant based on session token.
        """
        participant = cls._from_thing("session_token", token)
        if participant and participant.session_expires < pytz.utc.localize(datetime.datetime.utcnow()):
            participant = None

        return participant
github linkedin / naarad / src / naarad / utils.py View on Github external
def reconcile_timezones(begin_ts, ts_timezone, graph_timezone):
  if not graph_timezone:
    return begin_ts
  # Converting timestamp strings to be in timezone: graph_timezone
  # We only support UTC and PDT
  if graph_timezone != ts_timezone:
    utc = pytz.utc
    pst = timezone('US/Pacific')
    if graph_timezone == "UTC":
      # Assume timezone is PDT
      try:
        dt = pst.localize(datetime.datetime.strptime(begin_ts,"%Y-%m-%d %H:%M:%S"))
      except ValueError:
        dt = pst.localize(datetime.datetime.strptime(begin_ts,"%Y-%m-%d %H:%M:%S.%f"))
      begin_ts = dt.astimezone(utc).strftime("%Y-%m-%d %H:%M:%S.%f")
    else:
      # Assume timezone is UTC since graph_timezone is PDT
      try:
        dt = utc.localize(datetime.datetime.strptime(begin_ts,"%Y-%m-%d %H:%M:%S"))
      except ValueError:
        dt = utc.localize(datetime.datetime.strptime(begin_ts,"%Y-%m-%d %H:%M:%S.%f"))
      begin_ts = dt.astimezone(pst).strftime("%Y-%m-%d %H:%M:%S.%f")
  return begin_ts
github werwolfby / monitorrent / monitorrent / plugins / trackers / kinozal.py View on Github external
def check_changes(self, topic):
        last_torrent_update = self.tracker.get_last_torrent_update(topic.url)
        topic_last_torrent_update = topic.last_torrent_update
        min_date = pytz.utc.localize(datetime.datetime.min)

        if (not last_torrent_update and not topic_last_torrent_update) or (topic_last_torrent_update or min_date) < (last_torrent_update or min_date):
            topic.last_torrent_update = last_torrent_update
            return True

        return False
github baoding-fenshuajiang / GoodERP_OCC / odoo / addons / resource / models / resource.py View on Github external
def make_aware(dt):
    """ Return ``dt`` with an explicit timezone, together with a function to
        convert a datetime to the same (naive or aware) timezone as ``dt``.
    """
    if dt.tzinfo:
        return dt, lambda val: val.astimezone(dt.tzinfo)
    else:
        return dt.replace(tzinfo=utc), lambda val: val.astimezone(utc).replace(tzinfo=None)
github AwesomeFoodCoops / odoo-production / intercoop_addons / account_bank_statement_summary / report / report_bank_reconciliation_summary.py View on Github external
analysis_date = format_date.strftime("%d/%m/%Y")
        self.sheet.write(
            "B8",
            u"%s" % analysis_date,
            self.format_table_date_default
        )

        self.sheet.write(
            "B9",
            u"%s" % self.object.create_uid.name or '',
            self.format_table_bold
        )

        self.sheet.write(
            "B10",
            u"%s" % pytz.utc.localize(datetime.now(), is_dst=False).astimezone(
                pytz.timezone(self.object.create_uid.tz)).strftime("%d/%m/%Y %H:%M:%S") or '',
            self.format_table_date_default
        )

        self.sheet.write(
            "F8",
            u"%s" % self.object.journal_id.name or '',
            self.format_table_bold
        )
        currency_id = self.object.journal_id.currency_id or \
            self.object.journal_id.company_id and \
            self.object.journal_id.company_id.currency_id or False
        self.sheet.write(
            "F9",
            u"%s" % currency_id and currency_id.name or '',
            self.format_table_bold
github evewspace / eve-wspace / evewspace / Map / models.py View on Github external
def escalate(self):
        """Toggles the sig escalation."""
        if not self.lastescalated:
            self.lastescalated = datetime.now(pytz.utc)
            if not self.activated:
                self.activate()
        else:
            self.lastescalated = None
        self.save()
github enigmampc / catalyst / zipline / examples / quantopian_buy_apple.py View on Github external
from zipline.api import order, symbol


def initialize(context):
    context.test = 10
    context.aapl = symbol('AAPL')


def handle_date(context, data):
    order(context.aapl, 10)
    print(context.test)


if __name__ == '__main__':
    import pylab as pl
    start = datetime(2008, 1, 1, 0, 0, 0, 0, pytz.utc)
    end = datetime(2010, 1, 1, 0, 0, 0, 0, pytz.utc)
    data = load_from_yahoo(stocks=['AAPL'], indexes={}, start=start,
                           end=end)
    data = data.dropna()
    algo = TradingAlgorithm(initialize=initialize,
                            handle_data=handle_date,
                            identifiers=['AAPL'])
    results = algo.run(data)
    results.portfolio_value.plot()
    pl.show()
github TACC / tacc_stats / tacc_stats / pickler / MetaData.py View on Github external
def add_job(self, job, pickle_path):
        try:
            del job.acct['yesno'], job.acct['unknown']
        except: pass

        field = job.acct
        field['path'] = pickle_path
        
        field['start_epoch'] = field['start_time']
        field['end_epoch'] = field['end_time']

        utc_start = datetime.utcfromtimestamp(field['start_time']).replace(tzinfo=pytz.utc)
        utc_end = datetime.utcfromtimestamp(field['end_time']).replace(tzinfo=pytz.utc)
        tz = pytz.timezone('US/Central')
        
        field['start_time'] = utc_start.astimezone(tz) 
        field['end_time'] =  utc_end.astimezone(tz)

        field['date'] = field['end_time'].date()

        self.json[field['id']] = field