本文整理汇总了Python中mx.DateTime.now方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.now方法的具体用法?Python DateTime.now怎么用?Python DateTime.now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mx.DateTime
的用法示例。
在下文中一共展示了DateTime.now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __verify_detect_packet
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def __verify_detect_packet(self, packet):
lines = string.split(packet, cClinitek50.EOL)
# product ID: 6510 = Clinitek 50
tmp = lines[1][:4]
if tmp != cClinitek50.dev_id:
_log.Log(gmLog.lErr, 'device does not seem to be a Clinitek 50, product ID is [%s], expected [%s]' % (tmp, cClinitek50.dev_id))
_log.Log(gmLog.lData, lines)
return None
# product revision
tmp = lines[1][4:6]
if tmp not in cClinitek50.known_good_dev_revs:
_log.Log(gmLog.lWarn, 'product revision [%s] untested, trying to continue anyways' % tmp)
# software version
tmp = lines[1][6:11]
if tmp not in cClinitek50.known_good_sw_versions:
_log.Log(gmLog.lWarn, 'software version [%s] untested, trying to continue anyways' % tmp)
# date/time
timestamp = mxDT.strptime(lines[1][12:22], self.__date_format + cClinitek50.time_format)
_log.Log(gmLog.lInfo, 'device timestamp: %s' % timestamp)
_log.Log(gmLog.lInfo, 'system timestamp: %s' % mxDT.now())
age = mxDT.Age(mxDT.now(), timestamp)
if age.hours > 6:
_log.Log(gmLog.lErr, 'device time is off by %s, please correct that' % age)
return None
# language-unit profile
(lang, units) = string.split(lines[2], ' - ')
_log.Log(gmLog.lInfo, 'language: %s' % lang)
_log.Log(gmLog.lInfo, 'unit system: %s' % units)
# STIX type
stix_type = string.strip(lines[3])
if not stix_type in cClinitek50.known_stix_types:
_log.Log(gmLog.lErr, "don't know how to handle stix of type %s" % stix_type)
return None
# seems valid
return 1
示例2: test_reldat
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def test_reldat(self):
# Picking values for relative datetime tests is difficult - the clock
# is running, and first-of-month (etc) change the result.
ds = self._get_reldate_ds()
self.assertRaises(ValueError, Filter.DatasetFilter, ds, 'test_filter',
'a >= reldate(days=-1, months=-1)')
self.assertRaises(TypeError, Filter.DatasetFilter, ds, 'test_filter',
'a >= reldate(poo=1)')
self.assertRaises(ValueError, Filter.DatasetFilter, ds, 'test_filter',
'a >= reldate(align="xxx")')
self._test(ds, 'a >= reldate(days=+1)', [0])
self._test(ds, 'a >= reldate()', [0, 1])
self._test(ds, 'a >= reldate(days=0)', [0, 1])
self._test(ds, 'a >= reldate(days=-1)', [0, 1, 2])
if DateTime.now().day_of_week == 0:
self._test(ds, 'a >= reldate(days=-7)', [0, 1, 2, 3, 4]) # this fails on Mondays!
else:
self._test(ds, 'a >= reldate(days=-7)', [0, 1, 2, 3]) # this fails on Mondays!
self._test(ds, 'a >= reldate(days=-7, align="monday")', [0, 1, 2, 3, 4])
if DateTime.now().day == 1:
expect = [0, 1, 2, 3, 4, 5, 6]
else:
expect = [0, 1, 2, 3, 4, 5]
self._test(ds, 'a >= reldate(months=-1)', expect)
self._test(ds, 'a >= reldate(months=-1, align="bom")', [0, 1, 2, 3, 4, 5, 6])
if DateTime.now().day == 1 and DateTime.now().month == DateTime.January:
expect = [0, 1, 2, 3, 4, 5, 6, 7, 8]
else:
expect = [0, 1, 2, 3, 4, 5, 6, 7]
self._test(ds, 'a >= reldate(years=-1)', expect)
self._test(ds, 'a >= reldate(years=-1, align="boy")', [0, 1, 2, 3, 4, 5, 6, 7, 8])
if DateTime.now().day_of_week == 0:
self._test(ds, 'a between(reldate(days=-7), reldate(days=-2))', [3, 4]) # also fails on Mondays
else:
self._test(ds, 'a between(reldate(days=-7), reldate(days=-2))', [3])
示例3: IsScriptValid
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def IsScriptValid(self, script):
hasAccess = self.access
if hasAccess:
self.SetAccessToFunctionality(0)
self.output.AppendText("*** Begin Validation - %s ***\n" % str(DateTime.now()))
isValid, error = self.GetDocument().IsScriptValid(script, self.output)
if not isValid:
self.SetStatus(ILLICIT)
for e in error[-4:]:
self.output.AppendText(e + "\n")
else:
self.SetStatus(VALID)
if isValid:
self.output.AppendText("\nYour observing script is syntactically correct!\n\n")
self.output.AppendText("*** End Validation - %s ***\n" % str(DateTime.now()))
self.output.AppendText("\n\n")
if hasAccess:
self.SetAccessToFunctionality(1)
return isValid
示例4: test_get_quarantine
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def test_get_quarantine(entity, initial_account, quar_x, quar_y):
entity.add_entity_quarantine(quar_x,
initial_account.entity_id,
start=dt.now() + 1)
quars = entity.get_entity_quarantine()
assert len(quars) == 1
quars = entity.get_entity_quarantine(qtype=quar_y)
assert len(quars) == 0
entity.add_entity_quarantine(quar_y,
initial_account.entity_id,
start=dt.now() - 1)
entity.disable_entity_quarantine(quar_y, dt.now() + 1)
quars = entity.get_entity_quarantine()
assert len(quars) == 2
quars = entity.get_entity_quarantine(qtype=quar_x)
assert len(quars) == 1
assert quars[0]['quarantine_type'] == quar_x
quars = entity.get_entity_quarantine(qtype=quar_x, only_active=True)
assert len(quars) == 0
quars = entity.get_entity_quarantine(qtype=quar_y,
filter_disable_until=True)
assert len(quars) == 0
示例5: date_today
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def date_today(self, cr, uid, ids, context):
for sheet in self.browse(cr, uid, ids, context):
if DateTime.now() <= DateTime.strptime(sheet.date_from, "%Y-%m-%d"):
self.write(cr, uid, [sheet.id], {"date_current": sheet.date_from})
elif DateTime.now() >= DateTime.strptime(sheet.date_to, "%Y-%m-%d"):
self.write(cr, uid, [sheet.id], {"date_current": sheet.date_to})
else:
self.write(cr, uid, [sheet.id], {"date_current": time.strftime("%Y-%m-%d")})
return True
示例6: _default_date_to
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def _default_date_to(self, cr, uid, context={}):
user = self.pool.get("res.users").browse(cr, uid, uid, context)
r = user.company_id and user.company_id.timesheet_range or "month"
if r == "month":
return (DateTime.now() + DateTime.RelativeDateTime(months=+1, day=1, days=-1)).strftime("%Y-%m-%d")
elif r == "week":
return (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Sunday, 0))).strftime("%Y-%m-%d")
elif r == "year":
return time.strftime("%Y-12-31")
return time.strftime("%Y-%m-%d")
示例7: _get_out
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def _get_out(self, cr, uid, data, context):
args = {}
pool = pooler.get_pool(cr.dbname)
statement_obj= pool.get('account.bank.statement')
product_obj= pool.get('product.template')
productp_obj= pool.get('product.product')
res_obj = pool.get('res.users')
curr_company = res_obj.browse(cr,uid,uid).company_id.id
statement_id = statement_obj.search(cr,uid, [('journal_id','=',data['form']['journal_id']),('company_id','=',curr_company),('user_id','=',uid),('state','=','open')])
monday = (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Monday,0))).strftime('%Y-%m-%d')
sunday = (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Sunday,0))).strftime('%Y-%m-%d')
done_statmt = statement_obj.search(cr,uid, [('date','>=',monday+' 00:00:00'),('date','<=',sunday+' 23:59:59'),('journal_id','=',data['form']['journal_id']),('company_id','=',curr_company),('user_id','=',uid)])
stat_done = statement_obj.browse(cr,uid, done_statmt)
address_u = pool.get('res.users').browse(cr,uid,uid).address_id
am = 0.0
amount_check = productp_obj.browse(cr,uid,data['form']['product_id']).am_out or False
for st in stat_done:
for s in st.line_ids:
if address_u and s.partner_id==address_u.partner_id and s.am_out:
am+=s.amount
if (-data['form']['amount'] or 0.0)+ am <-(res_obj.browse(cr,uid,uid).company_id.max_diff or 0.0) and amount_check:
val = (res_obj.browse(cr,uid,uid).company_id.max_diff or 0.0)+ am
raise wizard.except_wizard(_('Error !'), _('The maximum value you can still withdraw is exceeded. \n Remaining value is equal to %d ')%(val))
acc_id = product_obj.browse(cr,uid,data['form']['product_id']).property_account_income
if not acc_id:
raise wizard.except_wizard(_('Error !'), _('please check that account is set to %s')%(product_obj.browse(cr,uid,data['form']['product_id']).name))
if not statement_id:
raise wizard.except_wizard(_('Error !'), _('You have to open at least one cashbox'))
if statement_id:
statement_id = statement_id[0]
if not statement_id:
statement_id = statement_obj.create(cr,uid,{'date':time.strftime('%Y-%m-%d 00:00:00'),
'journal_id':data['form']['journal_id'],
'company_id':curr_company,
'user_id':uid,
})
args['statement_id']= statement_id
args['journal_id']= data['form']['journal_id']
if acc_id:
args['account_id']= acc_id.id
amount= data['form']['amount'] or 0.0
if data['form']['amount'] > 0:
amount= -data['form']['amount']
args['amount'] = amount
if productp_obj.browse(cr,uid,data['form']['product_id']).am_out:
args['am_out'] = True
args['ref'] = data['form']['ref'] or ''
args['name'] = "%s: %s "%(product_obj.browse(cr,uid,data['form']['product_id']).name, data['form']['name'].decode('utf8'))
address_u = pool.get('res.users').browse(cr,uid,uid).address_id
if address_u:
partner_id = address_u.partner_id and address_u.partner_id.id or None
args['partner_id'] = partner_id
statement_line_id = pool.get('account.bank.statement.line').create(cr, uid, args)
return {}
示例8: writeContent
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def writeContent(self, trans=None):
#
# this servlet creates Vendor data
#
account = self.transaction.request().field('account','')
page = self.transaction.request().field('page','Main')
#
# create vendor object
#
globalSetVars = self._globalSetVars
store = globalSetVars['store']
if self.transaction.request().field('VendorNr',None)[-1:] == "0":
storeObjects = store.fetchObjectsOfClass('IDs','WHERE %s = "%s"' % ('Tablename',self.storeName))
if (len(storeObjects) == 1) and self.transaction.request().field('ID',None):
id = storeObjects[0]
id.setLastID(int(self.transaction.request().field('VendorNr',None)))
vendor = AccountsVE()
#
# change vendor object
#
for attr in vendorAttrs:
if attr not in standardAttrs:
if vendorFields[attr][vendorType] == 'string':
vendor.setValueForKey(attr, string.strip(self.transaction.request().field(attr,'')))
elif vendorFields[attr][vendorType] == 'float':
vendor.setValueForKey(attr, float(string.replace(self.transaction.request().field(attr,'0,0'),',','.')))
elif (vendorFields[attr][vendorType] == 'datetime') and self.request.field(attr,''):
vendor.setValueForKey(attr, DateTime.DateTimeFrom(self.transaction.request().field(attr,'')))
elif (vendorFields[attr][vendorType] == 'date') and self.transaction.request().field(attr,''):
vendor.setValueForKey(attr, DateTime.DateTimeFrom(self.transaction.request().field(attr,'')))
#
# set standard attributes
#
vendor.setErsteingabeAm(DateTime.now())
vendor.setChangedBy(self.transaction.session().value('authenticated_user',''))
vendor.setChangedAt(DateTime.now())
vendor.setChangedOn(self.getSite())
#
# store vendor in database
#
store.addObject(vendor)
try:
store.saveChanges()
#
# back to vendor page
#
self.transaction.response().sendRedirect('VendorView?index=' + account[2:])
except OperationalError,x:
store.discardEverything()
errorCode,errorText = x
#
# back to error page
#
self.transaction.response().sendRedirect('Error?problem=Daten+konnten+nicht+gespeichert+werden!&reason=' + urlEncode(str(errorText)))
示例9: writeContent
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def writeContent(self, trans=None):
#
# this servlet creates Expenses data
#
page = self.transaction.request().field('page','Main')
#
# create Expenses object
#
globalSetVars = self._globalSetVars
store = globalSetVars['store']
ExpensesNr=self.transaction.request().field('Nr','')
Expenses = AccountsAK()
#
# change Expenses object
#
for attr in ExpensesAttrs:
if attr not in standardAttrs:
if ExpensesFields[attr][ExpensesType] == 'string':
print self.transaction.request().field(attr,'')
Expenses.setValueForKey(attr, self.transaction.request().field(attr,''))
elif ExpensesFields[attr][ExpensesType] == 'float':
Expenses.setValueForKey(attr, float(string.replace(self.transaction.request().field(attr,'0,0'),',','.')))
elif (ExpensesFields[attr][ExpensesType] == 'datetime') and self.request.field(attr,''):
Expenses.setValueForKey(attr, DateTime.DateTimeFrom(self.transaction.request().field(attr,'')))
elif (ExpensesFields[attr][ExpensesType] == 'date') and self.transaction.request().field(attr,''):
Expenses.setValueForKey(attr, DateTime.DateTimeFrom(self.transaction.request().field(attr,'')))
#
# set standard attributes
#
Expenses.setID('AK'+ExpensesNr)
Expenses.setErsteingabeAm(DateTime.now())
Expenses.setChangedBy(self.transaction.session().value('authenticated_user',''))
Expenses.setChangedAt(DateTime.now())
Expenses.setChangedOn(self.getSite())
#
# store Expenses in database
#
store.addObject(Expenses)
try:
store.saveChanges()
#
# back to Expenses page
#
self.transaction.response().sendRedirect('ExpensesView?index=' + ExpensesNr)
except OperationalError,x:
store.discardEverything()
errorCode,errorText = x
#
# back to error page
#
self.transaction.response().sendRedirect('Error?problem=Daten+konnten+nicht+gespeichert+werden!&reason=' + urlEncode(str(errorText)))
示例10: OnPlotBeam
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def OnPlotBeam(self, event):
try:
self.output.AppendText("*** Begin Plot Beam - %s ***\n" % str(DateTime.now()))
pts = self.GetDocument().PlotBeam(self.editor.GetText(), self.output)
# This will fail, currently, because of incompatible versions of matplotlib
# but *should* work in theory once that is fixed
mapper = BeamMap(pts)
mapper.main()
self.output.AppendText("\n\n*** End Plot Beam - %s ***\n" % str(DateTime.now()))
self.output.AppendText("\n\n")
except:
exc = sys.exc_info()
print "WHOOPS %s, %s, %s"%(exc[0],exc[1],exc[2].tb_lineno)
示例11: writeContent
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def writeContent(self, trans=None):
#
# this servlet creates Member data
#
account = self.transaction.request().field('account','')
page = self.transaction.request().field('page','Main')
#
# create personal object
#
globalSetVars = self._globalSetVars
store = globalSetVars['store']
personal = AccountsTR()
#
# change personal object
#
for attr in personalAttrs:
if attr not in standardAttrs:
if personalFields[attr][personalType] == 'string':
print self.transaction.request().field(attr,'')
personal.setValueForKey(attr, self.transaction.request().field(attr,''))
elif personalFields[attr][personalType] == 'float':
if string.strip(self.transaction.request().field(attr,'')):
personal.setValueForKey(attr, float(string.replace(self.transaction.request().field(attr,'0,00'),',','.')))
else:
personal.setValueForKey(attr, None)
elif (personalFields[attr][personalType] == 'datetime') and self.request.field(attr,''):
personal.setValueForKey(attr, DateTime.DateTimeFrom(self.transaction.request().field(attr,'')))
elif (personalFields[attr][personalType] == 'date') and self.transaction.request().field(attr,''):
personal.setValueForKey(attr, DateTime.DateTimeFrom(self.transaction.request().field(attr,'')))
#
# set standard attributes
#
personal.setErsteingabeAm(DateTime.now())
personal.setChangedBy(self.transaction.session().value('authenticated_user',''))
personal.setChangedAt(DateTime.now())
personal.setChangedOn(self.getSite())
#
# store personal in database
#
store.addObject(personal)
try:
store.saveChanges()
except OperationalError,x:
store.discardEverything()
errorCode,errorText = x
#
# back to error page
#
self.transaction.response().sendRedirect('Error?problem=Daten+konnten+nicht+gespeichert+werden!&reason=' + urlEncode(str(errorText)))
示例12: init_report
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def init_report(self, lab=None):
self.report_id = None
self.notes = ''
self.completed = None
self.lab_options = list(labs)
self.lab_options.insert(0, choose)
if lab:
for name, label in labs:
if name.lower() == lab.lower():
lab = name
break
else:
lab = None
if lab:
self.lab = lab
self.lab_readonly = True
else:
self.lab = self.lab_options[0][0]
self.lab_readonly = False
prev_week = DateTime.RelativeDateTime(weeks=-1)
self.week_options = []
d = DateTime.now() + \
DateTime.RelativeDateTime(days=-4, weekday=(DateTime.Friday, 0),
hour=0, minute=0, second=0)
for n in range(8):
self.week_options.append(d.strftime('%Y-%m-%d'))
d += prev_week
self.week_options.reverse()
self.week = self.week_options[-1]
self.__monitor = Monitor(self, *self.report_cols)
示例13: _ac_add_new_traits
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def _ac_add_new_traits(ac):
"""Give an account new traits, as defined in
procconf.NEW_ACCOUNT_TRAITS. This method should be called when creating
and restoring accounts.
"""
for trait in getattr(procconf, 'NEW_ACCOUNT_TRAITS', ()):
ac.populate_trait(code=trait, date=DateTime.now())
示例14: OnButtonClick
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def OnButtonClick( self, event ):
if self.radio12to24.GetValue():
self.time24.SetValue( self.time12.GetValue() )
elif self.radio24to12.GetValue():
self.time12.SetValue( self.time24.GetValue() )
elif self.radioWx.GetValue():
now = wx.DateTime_Now()
self.time12.SetValue( now )
# (demonstrates that G/SetValue returns/takes a wx.DateTime)
self.time24.SetValue( self.time12.GetValue(as_wxDateTime=True) )
# (demonstrates that G/SetValue returns/takes a wx.TimeSpan)
self.spinless_ctrl.SetValue( self.time12.GetValue(as_wxTimeSpan=True) )
elif self.radioMx.GetValue():
from mx import DateTime
now = DateTime.now()
self.time12.SetValue( now )
# (demonstrates that G/SetValue returns/takes a DateTime)
self.time24.SetValue( self.time12.GetValue(as_mxDateTime=True) )
# (demonstrates that G/SetValue returns/takes a DateTimeDelta)
self.spinless_ctrl.SetValue( self.time12.GetValue(as_mxDateTimeDelta=True) )
示例15: get_requests
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import now [as 别名]
def get_requests(self, request_id=None, operator_id=None, entity_id=None,
operation=None, destination_id=None, given=False,
only_runnable=False):
cols = {}
if request_id is not None:
cols['request_id'] = request_id
if entity_id is not None:
cols['entity_id'] = entity_id
if operator_id is not None:
cols['requestee_id'] = operator_id
if operation is not None:
cols['operation'] = int(operation)
if destination_id is not None:
cols['destination_id'] = int(destination_id)
where = ["%s = :%s" % (x, x) for x in cols.keys()]
if only_runnable:
cols['now'] = DateTime.now()
where.append("run_at <= :now")
qry = """
SELECT request_id, requestee_id, run_at, operation, entity_id,
destination_id, state_data
FROM [:table schema=cerebrum name=bofhd_request]
WHERE """
ret = self._db.query(qry + " AND ".join(where), cols)
if given:
group = Factory.get('Group')(self._db)
tmp = [str(x["group_id"])
for x in group.search(member_id=operator_id,
indirect_members=True)]
extra_where = ""
if len(tmp) > 0:
extra_where = "AND destination_id IN (%s)" % ", ".join(tmp)
ret.extend(self._db.query(qry + "operation=:op %s" % extra_where,
{'op': int(self.co.bofh_move_give)}))
return ret