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


Python Delorean.shift方法代码示例

本文整理汇总了Python中delorean.Delorean.shift方法的典型用法代码示例。如果您正苦于以下问题:Python Delorean.shift方法的具体用法?Python Delorean.shift怎么用?Python Delorean.shift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在delorean.Delorean的用法示例。


在下文中一共展示了Delorean.shift方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_reply

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
def generate_reply(text, user_id):
    if not is_valid(text):
        reply_text = "Incorrect Format - Should be HH:MM (eg. 09:00 or 16:45)"
        return create_json(reply_text, user_id)

    hours   = text[0:2]
    minutes = text[3:5]

    # Handle timezone
    now = Delorean()
    now.shift("Europe/London")  # Currently only supports UK timezone

    # If today is Monday and before our target time
    if now.datetime.weekday() == 0 and (now.datetime.hour < int(hours) or (now.datetime.hour == int(hours) and now.datetime.minute < int(minutes))):
        monday = now.datetime
    else:
        monday = now.next_monday().datetime

    target = Delorean(datetime.datetime(monday.year, monday.month, monday.day, int(hours), int(minutes)), timezone='Europe/London')

    # Calculate time
    result        = (target - now)
    days_until    = result.days
    hours_until   = result.seconds / 60 / 60
    minutes_until = (result.seconds / 60) - (hours_until * 60)

    # Format message
    days_format    = "day"    if days_until == 1    else "days"
    hours_format   = "hour"   if hours_until == 1   else "hours"
    minutes_format = "minute" if minutes_until == 1 else "minutes"
    reply_text = "{} {}, {} {} and {} {} until Monday at {}:{}.".format(days_until, days_format, hours_until, hours_format, minutes_until, minutes_format, hours, minutes)
    return create_json(reply_text, user_id)
开发者ID:danstewart,项目名称:mondaybot,代码行数:34,代码来源:response.py

示例2: get_next_trading_dt

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
def get_next_trading_dt(current, interval):
    naive = current.replace(tzinfo=None)
    delo = Delorean(naive, pytz.utc.zone)
    ex_tz = trading.environment.exchange_tz
    next_dt = delo.shift(ex_tz).datetime

    while True:
        next_dt = next_dt + interval
        next_delo = Delorean(next_dt.replace(tzinfo=None), ex_tz)
        next_utc = next_delo.shift(pytz.utc.zone).datetime
        if trading.environment.is_market_hours(next_utc):
            break

    return next_utc
开发者ID:BroadBeard,项目名称:zipline,代码行数:16,代码来源:factory.py

示例3: __init__

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
class MongoConnect:
    def __init__(self, config):
        self.client = MongoClient(config["mongo"]["uris"])
        self.db = self.client[config["mongo"]["database"]]
        self.collection = self.db[config["mongo"]["collection"]]
        self.d = Delorean()
        self.d = self.d.shift("Europe/Amsterdam")
开发者ID:redvox,项目名称:hard-starboard,代码行数:9,代码来源:mongo_connect.py

示例4: get_local_time

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
def get_local_time(date, ip):
    reader = geoip2.database.Reader('/Users/scoward/Downloads/GeoIP2-City_20140930/GeoIP2-City.mmdb')
    
    if ip == '127.0.0.1':
        ip = '71.224.243.72'
        # ip = '167.29.0.143'
        # ip = '85.158.202.2'

    response = reader.city(ip)
    local_time_zone = response.location.time_zone

    shifted_date = Delorean(date, 'UTC')
    shifted_date.shift(local_time_zone)
    shifted_date = shifted_date.datetime.strftime('%Y-%m-%d %H:%M:%S')

    return shifted_date
开发者ID:idkwim,项目名称:ctf-manager,代码行数:18,代码来源:utils.py

示例5: parse_query_value

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
def parse_query_value(query_str, tf):
    """ Return value for the query string """
    try:
        query_str = str(query_str).strip('"\' ')
        if query_str == 'now':
            d = Delorean(timezone=tf)
        else:
            # Parse datetime string or timestamp
            try:
                d = epoch(float(query_str))
                d.shift(tf);
            except ValueError:
                d = parse(str(query_str))
                d.shift(tf);
    except (TypeError, ValueError):
        d = None
    return d
开发者ID:hellowangit,项目名称:alfred-datetime-format-converter,代码行数:19,代码来源:process.py

示例6: test_delorean_with_timezone

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
 def test_delorean_with_timezone(self):
     dt = datetime.utcnow()
     d = Delorean(datetime=dt, timezone=UTC)
     d = d.shift("US/Eastern")
     dt = utc.localize(dt)
     dt = est.normalize(dt)
     self.assertEqual(dt, d._dt)
     self.assertEqual(est, timezone(d._tz))
开发者ID:shussain,项目名称:delorean,代码行数:10,代码来源:test_data.py

示例7: get_open_and_close

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
    def get_open_and_close(self, next_open):

        # creating a naive datetime with the correct hour,
        # minute, and date. this will allow us to use Delorean to
        # shift the time between EST and UTC.
        next_open = next_open.replace(
            hour=9,
            minute=30,
            second=0,
            tzinfo=None
        )
        # create a new Delorean with the next_open naive date and
        # the correct timezone for the exchange.
        open_delorean = Delorean(next_open, self.exchange_tz)
        open_utc = open_delorean.shift("UTC").datetime

        market_open = open_utc
        market_close = market_open + self.get_trading_day_duration(open_utc)

        return market_open, market_close
开发者ID:aeppert,项目名称:zipline,代码行数:22,代码来源:trading.py

示例8: __init__

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
class MongoConnect:
    def __init__(self, config):
        self.client = MongoClient(config['mongo']['uris'])
        self.db = self.client[config['mongo']['database']]
        self.collection = self.db[config['mongo']['services_collection']]
        self.tickets = self.db[config['mongo']['tickets_collection']]
        self.queue = self.db['queue']
        self.d = Delorean()
        self.d = self.d.shift('Europe/Amsterdam')

    def get_environment_structure(self, environment_list):
        data = dict()
        for env in environment_list:
            env = env.strip()
            data[env] = dict()
            data[env]['state'] = 'open'
            data[env]['state_timestamp'] = self.get_formatted_timestamp()
            data[env]['message'] = ''
            data[env]['message_timestamp'] = ''
            data[env]['queue'] = []
        return data

    def create_new_gate(self, group, name, request):
        if not name or '.' in name:
            raise ServiceNameNotValid
        if not group or '.' in group:
            raise GroupNameNotValid

        if self.check_existence(group, name):
            raise ServiceAlreadyExists

        if 'environments' not in request or not request['environments'] or '' in request['environments'] or type(
                request['environments']) != list:
            raise JsonStructureError("Invalid environments.")
        try:
            data = dict()
            data['_id'] = str(uuid.uuid4())
            data['document_version'] = 2.2
            data['name'] = name.strip()
            data['group'] = group.strip()
            data['environments'] = self.get_environment_structure(request['environments'])

            self.collection.insert_one(data)
            data.pop('_id')  # do not return _id  
            return data
        except pymongo.errors.NotMasterError as error:
            raise NotMasterError(error.message)

    def remove_gate(self, group, name):
        if not self.check_existence(group, name):
            raise NotFound
        try:
            self.collection.remove({"name": name, "group": group})
        except pymongo.errors.NotMasterError as error:
            raise NotMasterError(error.message)

    def update_gate(self, group, name, entry):
        try:
            self.collection.update({"name": name, "group": group}, {'$set': entry}, upsert=False)
        except pymongo.errors.ConnectionFailure as error:
            raise ConnectionFailure(error.message)
        except pymongo.errors.OperationFailure as error:
            raise OperationFailure(error.message)

    def get_gate(self, group, name):
        entry = self.check_existence(group, name)
        if not entry:
            raise NotFound
        for env, info in entry['environments'].iteritems():
            tickets = []
            for ticket_id in info['queue']:
                ticket = self.get_ticket(ticket_id)
                if ticket:
                    tickets.append(ticket)
                else:
                    self.remove_ticket_link(group, name, env, ticket_id)
            entry['environments'][env]['queue'] = tickets
        return entry

    def legacy_get_gate(self, name):
        entry = self.legacy_check_existence(name)
        if not entry:
            raise NotFound
        for env, info in entry['environments'].iteritems():
            tickets = []
            for ticket_id in info['queue']:
                ticket = self.get_ticket(ticket_id)
                if ticket:
                    tickets.append(ticket)
                else:
                    self.legacy_remove_ticket_link(name, env, ticket_id)
            entry['environments'][env]['queue'] = tickets
        return entry

    def set_gate(self, group, name, environment, state):
        entry = self.check_existence(group, name)
        self.validate_environment_state(entry, environment, state)
        try:
            current_state = entry['environments'][environment]['state']
            if current_state != state:
#.........这里部分代码省略.........
开发者ID:otto-de,项目名称:gatekeeper,代码行数:103,代码来源:mongo_connect.py

示例9: exchange_dt_in_utc

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
 def exchange_dt_in_utc(self, dt):
     delorean = Delorean(dt, self.exchange_tz)
     return delorean.shift(pytz.utc.zone).datetime
开发者ID:c0mpsc1,项目名称:zipline,代码行数:5,代码来源:trading.py

示例10: utc_dt_in_exchange

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
 def utc_dt_in_exchange(self, dt):
     delorean = Delorean(dt, pytz.utc.zone)
     return delorean.shift(self.exchange_tz).datetime
开发者ID:c0mpsc1,项目名称:zipline,代码行数:5,代码来源:trading.py

示例11: datetime

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import pandas as pd
import pytz

from datetime import datetime, timedelta
from dateutil import rrule
from delorean import Delorean

start = datetime(1990, 1, 1, tzinfo=pytz.utc)
end_dln = Delorean(datetime.utcnow(), pytz.utc.zone)
end_dln.shift('US/Eastern').truncate('day').shift(pytz.utc.zone)
end = end_dln.datetime - timedelta(days=1)


def get_non_trading_days(start, end):
    non_trading_rules = []

    weekends = rrule.rrule(
        rrule.YEARLY,
        byweekday=(rrule.SA, rrule.SU),
        cache=True,
        dtstart=start,
        until=end
    )
    non_trading_rules.append(weekends)
开发者ID:Vanza1,项目名称:zipline,代码行数:32,代码来源:tradingcalendar.py

示例12: datetime

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import pandas as pd
import pytz

from datetime import datetime, timedelta
from dateutil import rrule
from delorean import Delorean

start = datetime(1990, 1, 1, tzinfo=pytz.utc)
end_dln = Delorean(datetime.utcnow(), 'UTC')
end_dln.shift('US/Eastern').truncate('day').shift('UTC')
end = end_dln.datetime - timedelta(days=1)


def get_non_trading_days(start, end):
    non_trading_rules = []

    weekends = rrule.rrule(
        rrule.YEARLY,
        byweekday=(rrule.SA, rrule.SU),
        cache=True,
        dtstart=start,
        until=end
    )
    non_trading_rules.append(weekends)
开发者ID:aeppert,项目名称:zipline,代码行数:32,代码来源:tradingcalendar.py

示例13: datetime_in_timezone

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
 def datetime_in_timezone(self, the_timezone):
     """Gets the UTC timezone """
     the_timezone = self._get_timezone_parameter(the_timezone)
     tmp_delorean = Delorean(datetime=self._delorean.datetime)
     return tmp_delorean.shift(the_timezone).datetime
开发者ID:biicode,项目名称:bii-server,代码行数:7,代码来源:utc_datetime.py

示例14: timestamp_as_timezone

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
 def timestamp_as_timezone(self, timezone_desc):
     d = Delorean(datetime=self.timestamp, timezone="UTC")
     d.shift(timezone_desc)
     return d.datetime.strftime("%b. %d, %Y at %I:%M %p")
开发者ID:roeske,项目名称:codecolab,代码行数:6,代码来源:models.py

示例15: exchange_dt_in_utc

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import shift [as 别名]
def exchange_dt_in_utc(dt):
    delorean = Delorean(dt, dt.tzinfo)
    return delorean.shift(pytz.utc.zone).datetime
开发者ID:twmeggs,项目名称:zipline,代码行数:5,代码来源:trading.py


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