本文整理汇总了Python中mx.DateTime.strptime方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.strptime方法的具体用法?Python DateTime.strptime怎么用?Python DateTime.strptime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mx.DateTime
的用法示例。
在下文中一共展示了DateTime.strptime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _dateConvertFromDB
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def _dateConvertFromDB(d):
if d==None:
return None
for format in ('%Y-%m-%d', # Y/M/D
'%H:%M:%S', # hh:mm:ss
'%H:%M', # hh:mm
'%Y-%m'): # Y-M
try:
return DateTime.strptime(d, format)
except:
pass
dashind = max(d.rfind('-'), d.rfind('+'))
tz = d[dashind:]
d = d[:dashind]
#maybe it has a miliseconds ?
dotind = string.rfind(d, '.')
if dotind > 0:
d = d[:dotind]
try:
return DateTime.strptime(d, '%H:%M:%S'), tz # timetz
except:
pass
if 1:#try:
# why is tz returned above and not here?
return DateTime.strptime(d, '%Y-%m-%d %H:%M:%S') # full date
示例2: get_internal_seniority
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def get_internal_seniority(self,cr,uid,ids,*args):
start_date = datetime.date.today()
end_date = datetime.date.today() # if the last contract has no en date, en date = today
internal_seniority = 0.0
internal_year_seniority = 0.0
internal_month_seniority = 0.0
# Get contracts for employee
contract_pool = self.pool.get('hr.contract')
contract_ids = contract_pool.search(cr,uid,[('employee_id','=',ids[0])],order='date_start desc') # contracts from today to first based on start date
contracts = contract_pool.browse(cr, uid, contract_ids)
# Get seniority for each contract
for contract in contracts:
seniority_rate = 1 # default seniority
start_date = DateTime.strptime(contract.date_start,'%Y-%m-%d')
if contract.seniority_rate:
seniority_rate = contract.seniority_rate
if contract.date_end:
end_date = DateTime.strptime(contract.date_end,'%Y-%m-%d')
internal_year_seniority += (end_date.year - start_date.year)*seniority_rate*1.0 # *1.0 to get a float
internal_month_seniority += (end_date.month - start_date.month + 1)*seniority_rate*1.0 # +1 : a started month is counted as a full month
end_date = start_date # if previous contract (in time scale) has no end date, its supposed end date is the current contract start date
# set seniority in years
internal_seniority = internal_year_seniority + internal_month_seniority/12 + internal_month_seniority//12
# Update internal seniority field
self.write(cr,uid,ids,{'internal_seniority':internal_seniority})
return True
示例3: button_dummy
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def button_dummy(self, cr, uid, ids, context):
for sheet in self.browse(cr, uid, ids, context):
if DateTime.strptime(sheet.date_current, "%Y-%m-%d") <= DateTime.strptime(sheet.date_from, "%Y-%m-%d"):
self.write(cr, uid, [sheet.id], {"date_current": sheet.date_from})
elif DateTime.strptime(sheet.date_current, "%Y-%m-%d") >= DateTime.strptime(sheet.date_to, "%Y-%m-%d"):
self.write(cr, uid, [sheet.id], {"date_current": sheet.date_to})
return True
示例4: date_today
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [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
示例5: calcular_edad
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def calcular_edad(date_start, format=1, date_end="now"):
try:
if date_end == "now":
date_end = DateTime.now()
else:
date_end = DateTime.strptime(date_end, '%Y-%m-%d')
dob = DateTime.strptime(date_start, '%Y-%m-%d')
delta = DateTime.Age (date_end, dob)
if format == 1:
return str(delta.years)
elif format == 2:
return str(delta.years) + " A/" + str(delta.months) + " M"
elif format == 3:
return str(delta.years) + " A/" + str(delta.months) + " M/" + str(delta.days) + " D "
elif format == 4:
str_year = ""
if delta.years < 1:
str_year = u""
elif delta.years == 1:
str_year = u"%s %s" % (str(delta.years), u'año')
if delta.months > 0:
str_year = str_year + ','
else:
str_year = u"%s %s" % (str(delta.years), u'años')
if delta.months > 0:
str_year = str_year + ','
str_month = ""
if delta.months < 1:
str_month = ""
else:
if delta.months == 1:
str_month = u"%s %s" % (str(delta.months), u'mes')
else:
str_month = u"%s %s" % (str(delta.months), u'meses')
str_day = ""
if (delta.days < 1 and delta.months > 0) or (delta.days < 1 and delta.years > 0):
str_day = ""
else:
if delta.days == 1:
str_day = u"%s %s" % (str(delta.days), u'día')
else:
str_day = u"%s %s" % (str(delta.days), u'días')
if delta.months > 0 or delta.years > 0:
str_day = 'y ' + str_day
res = "%s %s %s" % (str_year, str_month, str_day)
return res.strip()
except: return "0"
示例6: create_chained_picking
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def create_chained_picking(self, cr, uid, moves, context):
new_moves = []
for picking, todo in self._chain_compute(cr, uid, moves, context).items():
ptype = self.pool.get('stock.location').picking_type_get(cr, uid, todo[0][0].location_dest_id, todo[0][1][0])
pickid = self.pool.get('stock.picking').create(cr, uid, {
'name': picking.name,
'origin': str(picking.origin or ''),
'type': ptype,
'note': picking.note,
'move_type': picking.move_type,
'auto_picking': todo[0][1][1] == 'auto',
'address_id': picking.address_id.id,
'invoice_state': 'none'
})
for move, (loc, auto, delay) in todo:
# Is it smart to copy ? May be it's better to recreate ?
new_id = self.pool.get('stock.move').copy(cr, uid, move.id, {
'location_id': move.location_dest_id.id,
'location_dest_id': loc.id,
'date_moved': time.strftime('%Y-%m-%d'),
'picking_id': pickid,
'state': 'waiting',
'move_history_ids': [],
'date_planned': (DateTime.strptime(move.date_planned, '%Y-%m-%d %H:%M:%S') + DateTime.RelativeDateTime(days=delay or 0)).strftime('%Y-%m-%d'),
'move_history_ids2': []}
)
self.pool.get('stock.move').write(cr, uid, [move.id], {
'move_dest_id': new_id,
'move_history_ids': [(4, new_id)]
})
new_moves.append(self.browse(cr, uid, [new_id])[0])
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'stock.picking', pickid, 'button_confirm', cr)
if new_moves:
create_chained_picking(self, cr, uid, new_moves, context)
示例7: __verify_detect_packet
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [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
示例8: burndown_chart
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def burndown_chart(cr, uid, tasks_id, date_start, date_stop):
latest = False
cr.execute('select id,date_start,state,planned_hours from project_task where id in %s order by date_start', (tuple(tasks_id),))
tasks = cr.fetchall()
cr.execute('select id,date_close,state,planned_hours*progress/100 from project_task where id in %s and state in (%s,%s) order by date_close', (tuple(tasks_id), 'progress','done'))
tasks2 = cr.fetchall()
current_date = date_start
total = 0
done = 0
result = []
while current_date<=date_stop:
while len(tasks) and tasks[0][1] and tasks[0][1][:10]<=current_date:
total += tasks.pop(0)[3]
while len(tasks2) and tasks2[0][1] and tasks2[0][1][:10]<=current_date:
t2 = tasks2.pop(0)
if t2[2]<>'cancel':
done += t2[3]
else:
total -= t2[3]
result.append( (int(time.mktime(time.strptime(current_date,'%Y-%m-%d'))), total-done) )
current_date = (DateTime.strptime(current_date, '%Y-%m-%d') + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d')
if not len(tasks) and not len(tasks2):
break
result.append( (int(time.mktime(time.strptime(date_stop,'%Y-%m-%d'))), 0) )
return result
示例9: date_next
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def date_next(self, cr, uid, ids, context):
for sheet in self.browse(cr, uid, ids, context):
if DateTime.strptime(sheet.date_current, "%Y-%m-%d") >= 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": (
DateTime.strptime(sheet.date_current, "%Y-%m-%d") + DateTime.RelativeDateTime(days=1)
).strftime("%Y-%m-%d")
},
)
return True
示例10: __xform_8433
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def __xform_8433(self, result_data):
self.__request['sampled_when'] = mxDT.strptime(
result_data['8433'][0],
'%H%M',
self.__request['sampled_when']
)
self.__request.save_payload()
示例11: action_produce_assign_product
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def action_produce_assign_product(self, cr, uid, ids, context={}):
produce_id = False
company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
for procurement in self.browse(cr, uid, ids):
res_id = procurement.move_id.id
loc_id = procurement.location_id.id
newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S') - DateTime.RelativeDateTime(days=procurement.product_id.product_tmpl_id.produce_delay or 0.0)
newdate = newdate - DateTime.RelativeDateTime(days=company.manufacturing_lead)
produce_id = self.pool.get('mrp.production').create(cr, uid, {
'origin': procurement.origin,
'product_id': procurement.product_id.id,
'product_qty': procurement.product_qty,
'product_uom': procurement.product_uom.id,
'product_uos_qty': procurement.product_uos and procurement.product_uos_qty or False,
'product_uos': procurement.product_uos and procurement.product_uos.id or False,
'location_src_id': procurement.location_id.id,
'location_dest_id': procurement.location_id.id,
'bom_id': procurement.bom_id and procurement.bom_id.id or False,
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
'move_prod_id': res_id,
'product_line_origin' : procurement.product_line_origin and procurement.product_line_origin.id or False,
})
self.write(cr, uid, [procurement.id], {'state':'running'})
bom_result = self.pool.get('mrp.production').action_compute(cr, uid,
[produce_id], properties=[x.id for x in procurement.property_ids])
# wf_service = netsvc.LocalService("workflow")
# wf_service.trg_validate(uid, 'mrp.production', produce_id, 'button_confirm', cr)
self.pool.get('stock.move').write(cr, uid, [res_id],
{'location_id':procurement.location_id.id})
return produce_id
示例12: get_date
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def get_date(self, payment, line):
"""Return the right OPAE Line date"""
if not line :
return unicode(DateTime.today().strftime("%y%m%d"))
to_return = DateTime.today()
if payment.date_prefered == 'due' and line.ml_maturity_date :
to_return = DateTime.strptime(line.ml_maturity_date, '%Y-%m-%d')
if payment.date_prefered == 'fixed' and payment.date_planned :
to_return = DateTime.strptime(payment.date_planned, '%Y-%M-%d')
if to_return < DateTime.today():
raise wizard.except_wizard(
_('Error'),
_('Payment date must be at least today\n \
Today used instead.')
)
return unicode(to_return.strftime("%y%m%d"))
示例13: process_data
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def process_data(field, value, fields_def):
if not value or field not in fields_def:
return
if '.' not in field:
# type datetime, date, bool, int, float
if fields_def[field]['type'] == 'boolean':
value = value.lower() not in ('0', 'false', 'off','-', 'no', 'n')
elif fields_def[field]['type'] == 'selection':
if impobj == 'product.product' and self._cache[dbname].get('product.product.%s.%s' % (field, value), False):
value = self._cache[dbname]['product.product.%s.%s' % (field, value)]
else:
for key, val in fields_def[field]['selection']:
if value.lower() in [tools.ustr(key).lower(), tools.ustr(val).lower()]:
value = key
if impobj == 'product.product':
self._cache[dbname].setdefault('product.product.%s' % field, {})
self._cache[dbname]['product.product.%s.%s' % (field, value)] = key
break
elif fields_def[field]['type'] == 'date':
dt = DateTime.strptime(value,"%d/%m/%Y")
value = dt.strftime("%Y-%m-%d")
elif fields_def[field]['type'] == 'float':
# remove space and unbreakable space
value = re.sub('[ ]+', '', value)
value = float(value.replace(',', '.'))
return value
else:
if fields_def[field.split('.')[0]]['type'] in 'many2one':
return _get_obj(field, value, fields_def)
raise osv.except_osv(_('Warning !'), _('%s does not exist')%(value,))
示例14: Ymd
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def Ymd(date=None):
if date is None:
return DateTime.today()
elif type(date) in (str, unicode):
return DateTime.strptime(date, '%Y-%m-%d')
elif type(date) in (type(DateTime.today()), datetime.datetime):
return date.strftime('%Y-%m-%d')
示例15: check_date
# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strptime [as 别名]
def check_date(option, opt, value):
"""check a file value
return the filepath
"""
try:
return DateTime.strptime(value, "%Y/%m/%d")
except DateTime.Error:
raise OptionValueError("expected format of %s is yyyy/mm/dd" % opt)