本文整理汇总了Python中DateTime.DateTime.hour方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.hour方法的具体用法?Python DateTime.hour怎么用?Python DateTime.hour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime.DateTime
的用法示例。
在下文中一共展示了DateTime.hour方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: showTimeFrame
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def showTimeFrame(self,obj):
s = DateTime(obj.getValue('start-date'))
e = DateTime(obj.getValue('end-date'))
if s.year() == e.year() and s.month() == e.month() and \
s.day() == e.day() and s.hour() == e.hour() and s.minute() == e.minute():
return False
return True
示例2: render_view
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def render_view(self, field, value):
if value is None:
return ''
use_ampm = field.get_value('ampm_time_style')
if not isinstance(value, DateTime):
value = DateTime(value)
year = "%04d" % value.year()
month = "%02d" % value.month()
day = "%02d" % value.day()
if use_ampm:
hour = "%02d" % value.h_12()
else:
hour = "%02d" % value.hour()
minute = "%02d" % value.minute()
ampm = value.ampm()
order = field.get_value('input_order')
if order == 'ymd':
output = [year, month, day]
elif order == 'dmy':
output = [day, month, year]
elif order == 'mdy':
output = [month, day, year]
date_result = string.join(output, field.get_value('date_separator'))
if not field.get_value('date_only'):
time_result = hour + field.get_value('time_separator') + minute
if use_ampm:
time_result += ' ' + ampm
return date_result + ' ' + time_result
else:
return date_result
示例3: _getNextMinute
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def _getNextMinute(self, date, timezone):
if timezone is not None:
new_date = DateTime(date.timeTime() + 60.0, timezone)
else:
new_date = DateTime(date.timeTime() + 60.0)
return DateTime(new_date.year(), new_date.month(), new_date.day(),
new_date.hour(), new_date.minute(), 0, timezone)
示例4: test_04_Every3Hours
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def test_04_Every3Hours(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = 'Test Every 3 Hours'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
alarm = self.newAlarm(enabled=True)
now = DateTime().toZone('UTC')
hour_to_remove = now.hour() % 3
now = addToDate(now,hour=-hour_to_remove)
date = addToDate(now,day=2)
alarm.setPeriodicityStartDate(date)
alarm.setPeriodicityHourFrequency(3)
self.tic()
alarm.setNextAlarmDate(current_date=now)
self.assertEqual(alarm.getAlarmDate(),date)
LOG(message + ' now :',0,now)
now = addToDate(now,day=2)
LOG(message + ' now :',0,now)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(date,hour=3)
self.assertEqual(alarm.getAlarmDate(),next_date)
now = addToDate(now,hour=3,minute=7,second=4)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(next_date,hour=3)
self.assertEqual(alarm.getAlarmDate(),next_date)
示例5: _dt_setter
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def _dt_setter(self, fieldtoset, value, **kwargs):
# Always set the date in UTC, saving the timezone in another field.
# But since the timezone value isn't known at the time of saving the
# form, we have to save it timezone-naive first and let
# timezone_handler convert it to the target zone afterwards.
# Note: The name of the first parameter shouldn't be field, because
# it's already in kwargs in some case.
if not isinstance(value, DateTime): value = DateTime(value)
# Get microseconds from seconds, which is a floating value. Round it
# up, to bypass precision errors.
micro = int(round(value.second()%1 * 1000000))
value = DateTime('%04d-%02d-%02dT%02d:%02d:%02d%sZ' % (
value.year(),
value.month(),
value.day(),
value.hour(),
value.minute(),
value.second(),
micro and '.%s' % micro or ''
)
)
self.getField(fieldtoset).set(self, value, **kwargs)
示例6: now_no_seconds
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def now_no_seconds(self):
""" return current date and time with the seconds truncated
"""
now = DateTime()
return DateTime(str(now.year())+'/'+str(now.month())+'/'+\
str(now.day())+' '+str(now.hour())+':'+str(now.minute())+' '+\
str(now.timezone()))
示例7: testConstructor7
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def testConstructor7(self):
"""Constructor from parts"""
dt = DateTime()
dt1 = DateTime(dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute(), dt.second(), dt.timezone())
# Compare representations as it's the
# only way to compare the dates to the same accuracy
self.assertEqual(repr(dt), repr(dt1))
示例8: testSubtraction
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def testSubtraction(self):
"""Reconstruction of a DateTime from its parts, with subtraction"""
dt = DateTime()
dt1 = dt - 3.141592653
dt2 = DateTime(dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute(), dt.second())
dt3 = dt2 - 3.141592653
self.assertEqual(dt1, dt3, (dt, dt1, dt2, dt3))
示例9: render_hidden
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def render_hidden(self, field, key, value, REQUEST):
result = []
if value is None and field.get_value('default_now'):
value = DateTime()
sub_values = {}
subfields = ['year','month','day']
if value is not None:
if not isinstance(value, DateTime):
value = DateTime(value)
sub_values['year'] = '%04d' % value.year()
sub_values['month'] = "%02d" % value.month()
sub_values['day'] = "%02d" % value.day()
if not field.get_value('date_only'):
use_ampm = field.get_value('ampm_time_style')
subfields.extend(['hour','minute'])
if use_ampm: subfields.append('ampm')
if value is not None:
if use_ampm:
sub_values['hour'] = "%02d" % value.h_12()
sub_values['ampm'] = value.ampm()
else:
sub_values['hour'] = "%02d" % value.hour()
sub_values['minute'] = "%02d" % value.minute()
for subfield in subfields:
# XXX it would be nicer to pass the hidden value somewhere
# to the subfields, but ...
sub_key = field.generate_subfield_key(subfield)
sub_field = field.sub_form.get_field(subfield)
result.append(sub_field.widget.render_hidden(sub_field,
sub_key, sub_values.get(subfield), REQUEST))
return ''.join(result)
示例10: strptime
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def strptime(self, value):
if not value:
return None
if not isinstance(value, basestring):
return value
dt = DateTime(value)
return time(dt.hour(), dt.minute())
示例11: testSubtraction
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def testSubtraction(self):
# Reconstruction of a DateTime from its parts, with subtraction
# this also tests the accuracy of addition and reconstruction
dt = DateTime()
dt1 = dt - 3.141592653
dt2 = DateTime(
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second())
dt3 = dt2 - 3.141592653
self.assertEqual(dt1, dt3, (dt, dt1, dt2, dt3))
示例12: testConstructor3
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def testConstructor3(self):
# Constructor from date/time string
dt = DateTime()
dt1s = '%d/%d/%d %d:%d:%f %s' % (
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second(),
dt.timezone())
dt1 = DateTime(dt1s)
# Compare representations as it's the
# only way to compare the dates to the same accuracy
self.assertEqual(repr(dt), repr(dt1))
示例13: fromLineFrom
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def fromLineFrom(self,email,date):
"""
Generate a conformant mbox From line from email and date strings.
(unless date is unparseable, in which case we omit that part)
"""
# "email" is in fact a real name or zwiki username - adapt it
email = re.sub(r'\s','',email) or 'unknown'
try:
d = DateTime(date)
return 'From %s %s %s %d %02d:%02d:%02d %s %d\n' % (
email,d.aDay(),d.aMonth(),d.day(),d.hour(),
d.minute(),d.second(),d.timezone(),d.year())
except (DateTimeSyntaxError,AttributeError,IndexError):
return 'From %s\n' % email
示例14: test_04_Every3Hours
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def test_04_Every3Hours(self):
alarm = self.newAlarm(enabled=True)
now = DateTime().toZone('UTC')
hour_to_remove = now.hour() % 3
now = addToDate(now,hour=-hour_to_remove)
date = addToDate(now,day=2)
alarm.setPeriodicityStartDate(date)
alarm.setPeriodicityHourFrequency(3)
self.tic()
alarm.setNextAlarmDate(current_date=now)
self.assertEqual(alarm.getAlarmDate(),date)
now = addToDate(now,day=2)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(date,hour=3)
self.assertEqual(alarm.getAlarmDate(),next_date)
now = addToDate(now,hour=3,minute=7,second=4)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(next_date,hour=3)
self.assertEqual(alarm.getAlarmDate(),next_date)
示例15: _dt_setter
# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import hour [as 别名]
def _dt_setter(self, fieldtoset, value, **kwargs):
# Always set the date in UTC, saving the timezone in another field.
# But since the timezone value isn't known at the time of saving the
# form, we have to save it timezone-naive first and let
# timezone_handler convert it to the target zone afterwards.
# Note: The name of the first parameter shouldn't be field, because
# it's already in kwargs in some case.
if not isinstance(value, DateTime): value = DateTime(value)
value = DateTime('%04d-%02d-%02dT%02d:%02d:%02dZ' % (
value.year(),
value.month(),
value.day(),
value.hour(),
value.minute(),
value.second())
)
self.getField(fieldtoset).set(self, value, **kwargs)