本文整理汇总了Python中sanetime.time函数的典型用法代码示例。如果您正苦于以下问题:Python time函数的具体用法?Python time怎么用?Python time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: possibly_sharded
def possibly_sharded(self):
if self.completed_at: return None
if self.accountsyncshard_set.filter(completed_at__isnull=True).count(): return None
now = time()
locked = (self.__class__.objects.filter(id=self.id, sharded_at__isnull=True).update(sharded_at=now) == 1)
if not locked: return None
self.sharded_at = now
from webinars_web.webinars import models as wm
with wm.EventSync.delayed as d:
now = time()
for event in self.account.event_set.filter(deleted_at__isnull=True, current_sync__isnull=True, mothballed=False).select_related('account'):
d.insert(dict(event_id=event.id, parent_id=self.id, visible=self.visible, debug=self.debug, created_at=now.us))
from django.db import transaction
transaction.commit_unless_managed()
event_syncs = wm.EventSync.objects.filter(parent=self, event__account=self.account)
if not self.debug:
tasks = []
for es in event_syncs:
url = '%s%s'%(settings.APP_URL,es.kickoff_path)
uid = 'event_sync|kickoff|%s'%es.id
qid = es.event.account_id % settings.NUM_QUEUES
logging.debug('TQDEBUG: qid id %s' % qid)
tasks.append(Task(queue=settings.TASK_QUEUES[qid], url=url, method='POST', uid=uid))
Task._enqueue(tasks)
self.possibly_done()
示例2: clean_starts_at_ndt
def clean_starts_at_ndt(self):
if not self.kwargs_instance or not self.kwargs_instance.account.is_gtw:
tz = self.kwargs_instance and self.kwargs_instance.starts_at.tz or self.hub.timezone
st = time(self.cleaned_data['starts_at_ndt'], tz)
if time() > st:
raise ValidationError("This is in the past!")
return self.cleaned_data['starts_at_ndt']
示例3: get_today_local_noon_dt
def get_today_local_noon_dt(my_tz_name):
"""
Given a timezone, get a sanetime object representing today's noon in that timezone.
"""
now_dt = time(tz=my_tz_name)
local_noon_dt = time(now_dt.year, now_dt.month, now_dt.day, 12, 0, 0, 0, tz=my_tz_name)
return local_noon_dt
示例4: test_attendees
def test_attendees(self):
w = Webinar(self.organizer, key=2394, timezone='America/New_York', sessions=[])
s = Session(w, key=6043, started_at=time('2012-06-01'), attendees=[])
a1 = Registrant(webinar=w, session=s, key=9583, first_name=u'J\u00f6hn', last_name=u'Smith', email=u'[email protected]', viewings=[(time('4/1/11 12:01'), time('4/1/11 12:22'))])
a2 = Registrant(webinar=w, session=s, key=2305, first_name=u'Suzy', last_name=u'Samwell', email=u'[email protected]', viewings=[(time('4/1/11 12:02'), time('4/1/11 12:07')),(time('4/1/11 12:12'), time('4/1/11 12:17')),(time('4/1/11 12:22'), time('4/1/11 12:27'))])
with mocker(GetAttendees, text=self.attendees_json):
session = Session(w, key=6043, started_at=time('2012-06-01'))
self.assertEquals([a1,a2], session.attendees)
示例5: test_sleep
def test_sleep(self):
t1 = time()
t2 = time()
self.assertTrue(t2-t1 < delta(ms=10))
t1 = time()
delta(ms=10).sleep()
t2 = time()
self.assertTrue(t2-t1 >= delta(ms=10))
示例6: __init__
def __init__(self, start, delta=None, end=None):
super(SaneSpan,self).__init__()
self.start = time(start)
if delta is None:
end = time(end or 0)
self.start = min(self.start,end)
self.delta = end-self.start
else:
self.delta = delta
示例7: test_hashability
def test_hashability(self):
t1 = time(JAN_MICROS, tz='UTC')
t2 = time(JAN_MICROS, tz='America/New_York')
t3 = time(JAN_MICROS+1)
s = set([t1,t2,t3])
self.assertEquals(2, len(s))
self.assertIn(t1, s)
self.assertIn(t2, s)
self.assertIn(t3, s)
示例8: test_registrants
def test_registrants(self):
w = Webinar(self.organizer, key=2394, timezone='America/New_York', sessions=[])
s = Session(w, key=6043, started_at=time('2012-06-01'), attendees=[])
r1 = Registrant(webinar=w, session=s, key=9583, first_name=u'J\u00f6hn', last_name=u'Smith', email=u'[email protected]', registered_at='5/1/12 18:01', join_url='http://bit.ly/482024', status='APPROVED', viewings=[(time('4/1/11 12:01'), time('4/1/11 12:22'))])
r2 = Registrant(webinar=w, session=s, key=2305, first_name=u'Suzy', last_name=u'Samwell', email=u'[email protected]', registered_at='5/2/12 18:02', join_url='http://bit.ly/8592932', status='APPROVED', viewings=[(time('4/1/11 12:02'), time('4/1/11 12:07')),(time('4/1/11 12:12'), time('4/1/11 12:17')),(time('4/1/11 12:22'), time('4/1/11 12:27'))])
r3 = Registrant(webinar=w, session=s, key=4203, first_name=u'Todd', last_name=u'Kells', email=u'[email protected]', registered_at='5/3/12 18:03', join_url='http://bit.ly/9293842', status='WAITING', viewings=[])
with mocker(GetAttendees, text=self.attendees_json):
with mocker(GetRegistrations, text=self.registrants_json):
session = Session(w, key=6043, started_at=time('2012-06-01'))
self.assertEquals([r1,r2,r3], session.registrants)
示例9: calc_hashcode
def calc_hashcode(kls, **kwargs):
key = mget(kwargs,'remote_id', 'session_key', 'universal_key')
if key:
source = key
else:
title = mget(kwargs,'title','subject')
us_starts_at = kwargs.get('_time_starts_at',kwargs.get('starts_at',time(0)).us)
us_ends_at = kwargs.get('_time_ends_at',kwargs.get('ends_at',time(0)).us)
source = '%s|%s|%s'%(title,us_starts_at,us_ends_at)
return int(int(hashlib.md5(source).hexdigest(),16)%2**31)
示例10: lock
def lock(self, timeout=None, poll_rate=None): # poll_rate & timeout as deltas or micros
timeout = ndelta(timeout) or self.timeout or delta(0)
poll_rate = ndelta(poll_rate) or self.poll_rate
start = time()
while not self._attempt_lock():
if poll_rate:
poll_rate.sleep()
if time() > start + timeout:
break
return self.locked
示例11: test_universal_key
def test_universal_key(self):
w = Webinar(self.organizer, key=4918, timezone='America/New_York', sessions=[])
sa = Session(w, key=2058, started_at=time('2012-06-01'))
sb = Session(w, key=2023, started_at=time('2012-06-02'))
sc = Session(w, key=2084, started_at=time('2012-06-03'))
w.sessions.append(sa)
w.sessions.append(sb)
w.sessions.append(sc)
self.assertEquals('4918-1', sa.universal_key)
self.assertEquals('4918-2', sb.universal_key)
self.assertEquals('4918-3', sc.universal_key)
示例12: random
def random(kls, account, count=None):
events = []
for i in xrange(count or 1):
guid = ''.join(str(uuid.uuid4()).split('-'))
now = time(s=time().s,tz='America/New_York')
events.append( Event(
account,
title = u'unittest #%s &<>\xfc\u2603 ' % guid[:16],
description = u'#%s: An event created by unittests. If you\'re seeing this, then something went wrong. All events created by unittests are immediately cleaned up. &<>\xfc\u2603 ' % guid,
starts_at = now+15*60*10**6,
ends_at = now+30*60*10**6))
return count is None and events[0] or events
示例13: test_arithmetic
def test_arithmetic(self):
t1 = time(JAN_MICROS)
t2 = time(JAN_MICROS+1)
self.assertEquals(t2.us, (t1+1).us)
self.assertEquals(t1.us,(t2-1).us)
self.assertEquals(1, t2 - t1)
self.assertEquals(-1, t1 - t2)
self.assertEquals(t1.us,t1*1)
self.assertEquals(t1.us,t1/1)
示例14: get_fresh_last_modified_at
def get_fresh_last_modified_at(hub, guid):
leads_client = hapi.leads.LeadsClient(settings.HUBSPOT_API_KEY, hub_id=hub.id, env=settings.API_ENV)
leads = leads_client.get_leads(
time_pivot = 'lastModifiedAt',
sort = 'lastModifiedAt',
dir = 'desc',
max = 1,
form_guid = guid)
if leads:
return time(us=leads[0]['lastModifiedAt']*1000 + 1000)
else:
return time(0)
示例15: test_switching_timezones
def test_switching_timezones(self):
t1 = time(JAN_MICROS)
self.assertEquals(pytz.timezone('America/New_York'), t1.with_tz('America/New_York').tz)
self.assertEquals(t1, time(t1).set_tz('America/New_York'))
self.assertEquals(t1, t1.with_tz('America/New_York'))
self.assertNotEquals(t1.tz, time(t1).set_tz('America/New_York').tz)
self.assertNotEquals(t1.tz, t1.with_tz('America/New_York').tz)
self.assertEquals(pytz.timezone('America/New_York'), time(t1).set_tz('America/New_York').tz)
self.assertEquals(pytz.timezone('America/New_York'), t1.with_tz('America/New_York').tz)
t1_id = id(t1)
self.assertEquals(t1_id, id(t1.set_tz('America/New_York')))
self.assertNotEquals(t1_id, id(t1.with_tz('America/New_York')))