本文整理汇总了Python中DateTime.DateTime.toZone方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.toZone方法的具体用法?Python DateTime.toZone怎么用?Python DateTime.toZone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime.DateTime
的用法示例。
在下文中一共展示了DateTime.toZone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _comment_issue
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def _comment_issue(self, issue, instance_name, event):
# GOTCHA: This is kinda dumb, but Jira does not return the comments when issues are searched
# Thus, the comments for each issue have to be pulled separately
comments_res = self._request(
method='GET',
url=self.URL_TEMPLATES['comment'].format(issue=issue['key'])
)
comments = comments_res['comments']
if len([c for c in comments if instance_name in c['body']]) < 1:
self._logger.debug('Determined issue %s needs a comment', issue['key'])
start_time = DateTime(event.not_before)
end_time = DateTime(event.not_after) if event.not_after is not None else DateTime(9999, 12, 31)
body = self.COMMENT_TEMPLATE.format(
instance_name=instance_name,
# GOTCHA: Change the time to Pacific time for easier calculation
# This should handle Daylight Savings Time graciously on its own
start_time=str(start_time.toZone('US/Pacific')),
end_time=str(end_time.toZone('US/Pacific')),
)
self._request(
method='POST',
url=self.URL_TEMPLATES['comment'].format(issue=issue['key']),
json={
'body': body
}
)
self._logger.info('Added comment to issue %s: %s', issue['key'], body)
示例2: test_02_checkLineIsReindexedOnSupplyChange
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def test_02_checkLineIsReindexedOnSupplyChange(self, quiet=0, run=run_all_test):
"""
Check that Supply Line is properly reindexed (in predicate table)
when date is change on Supply.
"""
if not run: return
original_date = DateTime().earliestTime() # lower precision of date
new_date = DateTime(original_date + 10)
self.assertNotEquals(original_date, new_date)
supply = self._makeSupply(start_date_range_min=original_date)
supply_line = self._makeSupplyLine(supply)
kw = {}
kw['predicate.uid'] = supply_line.getUid()
kw['select_expression'] = 'predicate.start_date_range_min'
# check supply line in predicate table
result = self.catalog_tool(**kw)
self.assertEquals(1, len(result) )
result = result[0]
self.assertEquals(result.start_date_range_min, original_date.toZone('UTC'))
# set new date on supply...
supply.edit(start_date_range_min=new_date)
self.tic()
# ...and check supply line
kw['predicate.uid'] = supply_line.getUid()
result = self.catalog_tool(**kw)
self.assertEquals(1, len(result) )
result = result[0]
self.assertEquals(result.start_date_range_min, new_date.toZone('UTC'))
示例3: data_postprocessing
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def data_postprocessing(obj, event):
"""When setting the startDate and endDate, the value of the timezone field
isn't known, so we have to convert those timezone-naive dates into
timezone-aware ones afterwards.
For whole day events, set start time to 0:00:00 and end time toZone
23:59:59.
"""
if not IEvent.providedBy(obj):
# don't run me, if i'm not installed
return
timezone = obj.getField('timezone').get(obj)
start_field = obj.getField('startDate')
end_field = obj.getField('endDate')
# The previous_timezone is set, when the timezone has changed to another
# value. In this case we need to convert the UTC dt values to the
# previous_timezone, so that we get the datetime values, as the user
# entered them. However, this value might be always set, even when creating
# an event, since ObjectModifiedEvent is called several times when editing.
prev_tz = getattr(obj, 'previous_timezone', None)
if prev_tz: delattr(obj, 'previous_timezone')
def _fix_zone(dt, tz):
if not dt.timezoneNaive():
# The object is edited and the value alreadty stored in UTC on the
# object. In this case we want the value converted to the given
# timezone, in which the user entered the data.
dt = dt.toZone(tz)
return dt
start = _fix_zone(start_field.get(obj), prev_tz and prev_tz or timezone)
end = _fix_zone(end_field.get(obj), prev_tz and prev_tz or timezone)
def make_DT(value, timezone):
return DateTime(
value.year(),
value.month(),
value.day(),
value.hour(),
value.minute(),
value.second(),
timezone)
start = make_DT(start, timezone)
end = make_DT(end, timezone)
if obj.getWholeDay():
start = DateTime('%s 0:00:00 %s' % (start.Date(), timezone))
end = DateTime('%s 23:59:59 %s' % (end.Date(), timezone))
start_field.set(obj, start.toZone('UTC'))
end_field.set(obj, end.toZone('UTC'))
obj.reindexObject()
示例4: datehandler
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def datehandler(value):
# TODO: we might want to handle datetime and time as well;
# check the enfold.solr implementation
if value is None or value is '':
raise AttributeError
if isinstance(value, str) and not value.endswith('Z'):
try:
value = DateTime(value)
except SyntaxError:
raise AttributeError
if isinstance(value, DateTime):
v = value.toZone('UTC')
value = '%04d-%02d-%02dT%02d:%02d:%06.3fZ' % (
v.year(), v.month(), v.day(), v.hour(), v.minute(), v.second()
)
elif isinstance(value, datetime):
# Convert a timezone aware timetuple to a non timezone aware time
# tuple representing utc time. Does nothing if object is not
# timezone aware
value = datetime(*value.utctimetuple()[:7])
value = '%s.%03dZ' % (
value.strftime('%Y-%m-%dT%H:%M:%S'),
value.microsecond % 1000
)
elif isinstance(value, date):
value = '%s.000Z' % value.strftime('%Y-%m-%dT%H:%M:%S')
return value
示例5: get_job_data
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def get_job_data(self, job):
lastused = DateTime(job._p_mtime)
if len(job.args) > 3:
user = job.args[3]
else:
user = ''
if len(job.args) > 4:
intro = job.args[4]
else:
intro = {}
if isinstance(job.args[0], list):
object_path = '/'.join(job.args[0])
else:
object_path = str(job.args[0])
if job.status != 'pending-status':
timerunning = time_since(lastused)
else:
timerunning = '-'
return {
'status' : job.status,
'user' : user,
'object_path' : object_path,
'description' : (getattr(intro, '__doc__', '') or getattr(intro, '__name__', '')).strip(),
'lastused' : lastused.toZone('UTC').pCommon(),
'timerunning' : timerunning
}
示例6: testTZ2
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def testTZ2(self):
# Time zone manipulation test 2
dt = DateTime()
dt1 = dt.toZone('GMT')
s = dt.second()
s1 = dt1.second()
self.assertEqual(s, s1, (dt, dt1, s, s1))
示例7: _zope_datetime
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def _zope_datetime(self, field, zone=None):
dt = self.doc.get(field)
if dt is None:
return None
dt = DateTime(dt)
if zone is None:
zone = DateTime().localZone(localtime(dt.timeTime()))
return dt.toZone(zone)
示例8: test_pub_date
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def test_pub_date(self):
request = self.app.REQUEST
self.login('Alan')
self.portal.invokeFactory('Document', 'd1')
context = getattr(self.portal, 'd1')
# configure our portal and context to get publication date not None
properties = getToolByName(context, 'portal_properties')
site_properties = getattr(properties, 'site_properties')
site_properties.displayPublicationDateInByline = True
wtool = getToolByName(context, 'portal_workflow')
wtool.doActionFor(context, 'publish')
self.login('Ano')
viewlet = DocumentBylineViewlet(context, request, None, None)
viewlet.update()
# publication date should be not None now
self.failIf(viewlet.pub_date() is None)
# now set publication date in workflow history manually
published = DateTime('2012/03/14')
context.workflow_history[wtool.getChainFor('Document')[0]][-1]['time'] = \
published
# purge instance memoize cache
delattr(viewlet, Memojito.propname)
self.assertEqual(viewlet.pub_date(), published)
# set Effective Date and check if it'll be used
effective = DateTime('2012/03/15')
context.setEffectiveDate(effective)
# purge instance memoize cache
delattr(viewlet, Memojito.propname)
self.assertEqual(viewlet.pub_date(),
DateTime(effective.toZone(_zone).ISO8601()))
# now make document private and ensure publication date will return None
self.login('Alan')
wtool.doActionFor(context, 'retract')
self.login('Ano')
# purge instance memoize cache
delattr(viewlet, Memojito.propname)
self.assertEqual(viewlet.pub_date(), None)
# move it back to public
self.login('Alan')
wtool.doActionFor(context, 'publish')
self.login('Ano')
# purge instance memoize cache
delattr(viewlet, Memojito.propname)
self.failIf(viewlet.pub_date() is None)
# and finally check that our global site setting
# 'Display pub date in byline' works properly
# purge instance memoize cache
site_properties.displayPublicationDateInByline = False
delattr(viewlet, Memojito.propname)
self.assertEqual(viewlet.pub_date(), None)
示例9: testCFIDates
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def testCFIDates(self):
""" Test CFI Dates
"""
self.setRoles('Manager')
root = self.folder
today = DateTime()
_zone = DateTime().timezone()
cid = root.invokeFactory(type_name='CallForInterest', id="cfi",
title='Call for interest',
openDate=today,
closeDate=today,
applicationDate=today)
cfi = getattr(root, cid)
self.failIf(today.toZone(_zone).ISO() != cfi.EffectiveDate())
self.failIf(today != cfi.getEffectiveDate())
self.failIf(today != cfi.effective())
self.failIf(today != cfi.expires())
self.failIf(today.toZone(_zone).ISO() != cfi.ExpirationDate())
self.failIf(today != cfi.getExpirationDate())
tomorrow = today + 1
cfi.setCloseDate(tomorrow)
self.failIf(tomorrow != cfi.getCloseDate())
self.failIf(tomorrow != cfi.expires())
self.failIf(tomorrow.toZone(_zone).ISO() != cfi.ExpirationDate())
self.failIf(tomorrow != cfi.getExpirationDate())
yesterday = today - 1
cfi.setOpenDate(yesterday)
self.failIf(yesterday != cfi.getOpenDate())
self.failIf(yesterday != cfi.effective())
self.failIf(yesterday.toZone(_zone).ISO() != cfi.EffectiveDate())
self.failIf(yesterday != cfi.getEffectiveDate())
cfi.setExpirationDate(today)
self.failIf(today != cfi.expires())
self.failIf(today.toZone(_zone).ISO() != cfi.ExpirationDate())
self.failIf(today != cfi.getExpirationDate())
self.failIf(today != cfi.getCloseDate())
cfi.setEffectiveDate(today)
self.failIf(today.toZone(_zone).ISO() != cfi.EffectiveDate())
self.failIf(today != cfi.getEffectiveDate())
self.failIf(today != cfi.effective())
self.failIf(today != cfi.getOpenDate())
示例10: testStrftimeTZhandling
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def testStrftimeTZhandling(self):
# strftime timezone testing
# This is a test for collector issue #1127
format = '%Y-%m-%d %H:%M %Z'
dt = DateTime('Wed, 19 Nov 2003 18:32:07 -0215')
dt_string = dt.strftime(format)
dt_local = dt.toZone(_findLocalTimeZoneName(0))
dt_localstring = dt_local.strftime(format)
self.assertEqual(dt_string, dt_localstring)
示例11: toDateTime
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def toDateTime(t):
if not isinstance(t, DateTime):
t = DateTime(t)
if t.timezone() == 'GMT+0':
t = t.toZone('US/Eastern')
return t
示例12: _get_comment_body
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def _get_comment_body(self, end_time):
start_time = DateTime(self._event.not_before)
return self.COMMENT_TEMPLATE.format(
instance_name=self.INSTANCE_NAME,
# GOTCHA: Change the time to Pacific time for easier calculation
# This should handle Daylight Savings Time graciously on its own
start_time=str(start_time.toZone('US/Pacific')),
end_time=str(end_time.toZone('US/Pacific')),
)
示例13: test_21_AlarmCatalogPresence
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def test_21_AlarmCatalogPresence(self):
"""Check that alarm date is properly stored in catalog upon first reindexation"""
date = DateTime().earliestTime()
alarm = self.newAlarm(enabled=True, periodicity_start_date=date)
self.tic()
self.assertEqual(alarm.getAlarmDate(), date)
alarm_list = alarm.Alarm_zGetAlarmDate(uid=alarm.getUid())
self.assertEqual(1, len(alarm_list))
catalog_alarm_date = alarm_list[0].alarm_date
self.assertEqual(date.toZone('UTC'), catalog_alarm_date)
示例14: _setDateTimeField
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def _setDateTimeField(self, fieldName, value):
if not isinstance(value, DateTime):
value = DateTime(value)
if value.timezoneNaive():
parts = value.parts()
value = DateTime(*(parts[:-1] + ('UTC',)))
else:
value = value.toZone('UTC')
self.Schema()[fieldName].set(self, value)
示例15: test_21b_AlarmCatalogPresenceWithInitialEmptyStartDate
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import toZone [as 别名]
def test_21b_AlarmCatalogPresenceWithInitialEmptyStartDate(self):
"""Check that alarm date is properly stored in catalog if
initially the periodicity start date was not there and
then set later"""
date = DateTime().earliestTime()
alarm = self.newAlarm(enabled=True, periodicity_start_date=None)
self.tic()
alarm_list = alarm.Alarm_zGetAlarmDate(uid=alarm.getUid())
self.assertEqual(None, alarm_list[0].alarm_date)
alarm.edit(periodicity_start_date=date)
self.tic()
alarm_list = alarm.Alarm_zGetAlarmDate(uid=alarm.getUid())
self.assertEqual(date.toZone('UTC'), alarm_list[0].alarm_date)