当前位置: 首页>>代码示例>>Python>>正文


Python DateTime.strftime方法代码示例

本文整理汇总了Python中mx.DateTime.strftime方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.strftime方法的具体用法?Python DateTime.strftime怎么用?Python DateTime.strftime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mx.DateTime的用法示例。


在下文中一共展示了DateTime.strftime方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _calc_dates

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strftime [as 别名]
def _calc_dates(self, cr, uid, data, context):
    res = {}
    period_length = data["form"]["period_length"]
    if period_length <= 0:
        raise wizard.except_wizard(_("UserError"), _("You must enter a period length that cannot be 0 or below !"))
    start = datetime.date.fromtimestamp(time.mktime(time.strptime(data["form"]["date1"], "%Y-%m-%d")))
    start = DateTime(int(start.year), int(start.month), int(start.day))
    if data["form"]["direction_selection"] == "past":
        for i in range(5)[::-1]:
            stop = start - RelativeDateTime(days=period_length)
            res[str(i)] = {
                "name": str((5 - (i + 1)) * period_length) + "-" + str((5 - i) * period_length),
                "stop": start.strftime("%Y-%m-%d"),
                "start": stop.strftime("%Y-%m-%d"),
            }
            start = stop - RelativeDateTime(days=1)
    else:
        for i in range(5):
            stop = start + RelativeDateTime(days=period_length)
            res[str(5 - (i + 1))] = {
                "name": str((i) * period_length) + "-" + str((i + 1) * period_length),
                "start": start.strftime("%Y-%m-%d"),
                "stop": stop.strftime("%Y-%m-%d"),
            }
            start = stop + RelativeDateTime(days=1)
    return res
开发者ID:MarkNorgate,项目名称:addons-EAD,代码行数:28,代码来源:wizard_aged_trial_balance.py

示例2: _get_prod_stock_before

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strftime [as 别名]
    def _get_prod_stock_before(self, cr, uid, ids, name, arg, context={}):
        res = {}
        prod_obj = self.pool.get('product.product')

        loc_ids = 11
        for line in self.browse(cr, uid, ids, context=context):
            # print 'fechaxxx: ',line.name
            startf = datetime.datetime.fromtimestamp(time.mktime(
                time.strptime(line.name, "%Y-%m-%d:%H:%M:%S")))
            # print 'ffff: ',startf
            start = DateTime(int(startf.year), 1, 1)
            # end =
            # DateTime(int(startf.year),int(startf.month),int(startf.day))
            end = startf - datetime.timedelta(seconds=1)
            d1 = start.strftime('%Y-%m-%d %H:%M:%S')
            d2 = end.strftime('%Y-%m-%d %H:%M:%S')
            # print 'd1xxxxxxx: ',d1
            # print 'd2yyyyyyy: ',d2
            c = context.copy()
            c.update({'location': loc_ids, 'from_date': d1, 'to_date': d2})
            res.setdefault(line.id, 0.0)
            if line.product_id and line.product_id.id:
                prd = prod_obj.browse(cr, uid, line.product_id.id, context=c)
                res[line.id] = prd.qty_available
        return res
开发者ID:meswapnilwagh,项目名称:odoo-adr,代码行数:27,代码来源:report_profit_picking.py

示例3: _get_prod_stock

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strftime [as 别名]
    def _get_prod_stock(self, cr, uid, ids, name, arg, context={}):
        res = {}
        prod_obj = self.pool.get('product.product')

        loc_ids = 1
        for line in self.browse(cr, uid, ids, context=context):
            startf = datetime.date.fromtimestamp(time.mktime(time.strptime(line.name,"%Y-%m-%d")))
            start = DateTime(int(startf.year),1,1)
            end = DateTime(int(startf.year),int(startf.month),int(startf.day))
            d1 = start.strftime('%Y-%m-%d %H:%M:%S')
            d2 = end.strftime('%Y-%m-%d %H:%M:%S')
            c = context.copy()
            c.update({'location': loc_ids,'from_date':d1,'to_date':d2})
            res.setdefault(line.id, 0.0)
            if line.product_id and line.product_id.id:
                prd = prod_obj.browse(cr, uid, line.product_id.id,context=c)
                res[line.id] = prd.qty_available
        return res
开发者ID:nhomar,项目名称:vauxoo_bzr2git,代码行数:20,代码来源:report_profit_invoice.py

示例4: _data_save

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strftime [as 别名]
def _data_save(self, cr, uid, data, context):
    form = data['form']
    if not form['u_check']  and not form['p_check'] and not form['c_check']:
        raise wizard.except_wizard(_('User Error'), _('You have to check one box !'))    
    res = {}
    period_length = data['form']['period_length']
    if period_length<=0:
        raise wizard.except_wizard(_('UserError'), _('You must enter a period length that cannot be 0 or below !'))
    start = datetime.date.fromtimestamp(time.mktime(time.strptime(data['form']['date_start'],"%Y-%m-%d")))
    start = DateTime(int(start.year),int(start.month),int(start.day))

    for i in range(4)[::-1]:
        stop = start - RelativeDateTime(days=period_length)
        res[str(i)] = {
            'name' : str((4-(i+1))*period_length) + '-' + str((4-i)*period_length),
            
            'stop': start.strftime('%Y-%m-%d'),
            'start' : stop.strftime('%Y-%m-%d'),
            }
        start = stop - RelativeDateTime(days=1)

    return res
开发者ID:nhomar,项目名称:vauxoo_bzr2git,代码行数:24,代码来源:wizard_trial_cost.py

示例5: action_print

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strftime [as 别名]
    def action_print(self, cr, uid, ids, data, context=None):
        if context is None:
            context = {}

        data = {}
        data['ids'] = context.get('active_ids', [])
        data['model'] = context.get('active_model', 'ir.ui.menu')
        data['form'] = self.read(cr, uid, ids[0])
        form = data['form']
        if not form['u_check'] and not form['p_check'] and not form['c_check']:
            raise osv.except_osv(_('User Error'), _(
                'You must check one box !'))
        res = {}
        period_length = data['form']['period_length']
        if period_length <= 0:
            raise osv.except_osv(_('UserError'), _(
                'You must enter a period length that cannot be 0 or below !'))
        start = datetime.date.fromtimestamp(time.mktime(
            time.strptime(data['form']['date_start'], "%Y-%m-%d")))
        start = DateTime(int(start.year), int(start.month), int(start.day))

        for i in range(4)[::-1]:
            stop = start - RelativeDateTime(days=period_length)
            res[str(i)] = {
                'name': str((4 - (i + 1)) * period_length) +
                '-' + str((4 - i) * period_length),

                'stop': start.strftime('%Y-%m-%d'),
                'start': stop.strftime('%Y-%m-%d'),
            }
            start = stop - RelativeDateTime(days=1)

        data['form'].update(res)
        return {'type': 'ir.actions.report.xml',
                'report_name': 'profit.trial.cost',
                'datas': data}
开发者ID:meswapnilwagh,项目名称:odoo-adr,代码行数:38,代码来源:wiz_trial_cost.py

示例6: test_string_format

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strftime [as 别名]
def test_string_format():
    # Negative years
    t = DateTime(-1,1,1,12,34,56.78)
    assert str(t) == '-0001-01-01 12:34:56.78'

    # Rounding
    t = DateTime(2007,1,1,12,34,56.78)
    assert str(t) == '2007-01-01 12:34:56.78'
    t = DateTime(2011,1,1,12,34,3.42)
    # Note: 3.42 is stored as 3.4199999999999999
    assert str(t) == '2011-01-01 12:34:03.42', str(t)
    assert repr(t).find( '2011-01-01 12:34:03.42') > 0
    assert t.date == '2011-01-01'
    assert t.time == '12:34:03.42'
    t = DateTime(2011,1,1,12,34,3.425)
    # Note: 3.425 is stored as 3.4249999999999998
    assert str(t) == '2011-01-01 12:34:03.43', str(t)
    assert repr(t).find( '2011-01-01 12:34:03.43') > 0
    assert t.date == '2011-01-01'
    assert t.time == '12:34:03.43'
    t = DateTime(2011,1,1,12,34,56.1147)
    # Note: 56.1147 is stored as 56.114699999999999
    assert str(t) == '2011-01-01 12:34:56.11', str(t)
    assert repr(t).find( '2011-01-01 12:34:56.11') > 0
    assert t.date == '2011-01-01'
    assert t.time == '12:34:56.11'
    t = DateTime(2011,1,1,12,34,56.124449)
    # Note: 56.124449 is stored as 56.124448999999998
    assert str(t) == '2011-01-01 12:34:56.12', str(t)

    # Rounding at the end of a minute
    t = DateTimeFromAbsDateTime(733407, 86399)
    assert str(t) == '2008-12-31 23:59:59.00'
    t = DateTimeFromAbsDateTime(733407, 86399.9)
    assert str(t) == '2008-12-31 23:59:59.90'
    t = DateTimeFromAbsDateTime(733407, 86399.99)
    assert str(t) == '2008-12-31 23:59:59.99'
    assert repr(t).find('2008-12-31 23:59:59.99') > 0
    t = DateTimeFromAbsDateTime(733407, 86399.995)
    assert str(t) == '2008-12-31 23:59:59.99'
    assert repr(t).find('2008-12-31 23:59:59.99') > 0
    t = DateTimeFromAbsDateTime(733407, 86399.999)
    assert str(t) == '2008-12-31 23:59:59.99'
    assert repr(t).find('2008-12-31 23:59:59.99') > 0

    print 'String format ok.'

    # .strftime()
    t = DateTime(2015,6,30,23,59,59)
    assert t.strftime('%y-%m-%d') == '15-06-30'
    assert t.strftime('%Y-%m-%d') == '2015-06-30'
    assert t.strftime('%H:%M:%S') == '23:59:59'
    assert t.strftime('%Y-%m-%d %H:%M:%S') == '2015-06-30 23:59:59'

    # .strftime() and unsupported format codes
    try:
        assert t.strftime('%f') == '%f'
    except ValueError:
        # On Windows, a ValueError is raised
        print "Note: dt.strftime('%f') raises a ValueError on Windows"

    # .strftime() and % at the end of the format string
    try:
        assert t.strftime('%') == '%'
    except ValueError:
        # On Windows, a ValueError is raised
        print "Note: dt.strftime('%') raises a ValueError on Windows"

    # .strftime() with leap seconds
    t = DateTime(2015,6,30,23,59,60)
    try:
        assert t.strftime('%Y-%m-%d %H:%M:%S') == '2015-06-30 23:59:60'
    except ValueError:
        # On Windows, a ValueError is raised
        print "Note: dt.strftime('%c') raises a ValueError on Windows for leap seconds"
开发者ID:rfleschenberg,项目名称:egenix-mx-base-python-2x3,代码行数:77,代码来源:test_test.py

示例7: _data_save

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strftime [as 别名]
def _data_save(self, cr, uid, data, context):
    form = data['form']
    pool = pooler.get_pool(cr.dbname)
    prod_obj = pool.get('product.product')
    line_inv_obj = pool.get('report.profit.invoice')
    inv_ids = []
    res = {}
    
    
    cost_obj = pool.get('costo.inicial')
    inv_obj = pool.get('account.invoice')
    if form['state']=='bydate':
        inv_ids = inv_obj.search(cr,uid,[('date_invoice','>=',form['date_start']), ('date_invoice','<=',form['date_end'])])

    if form['state']=='byinvoice':
        inv_ids.append(form['invoice_id'])

    if form['state']=='some':
        if form['invoice_ids'] and form['invoice_ids'][0]:
            inv_ids.extend(form['invoice_ids'][0][2])

    if form['state']=='none':
        inv_ids = inv_obj.search(cr,uid,[])


    if inv_ids:
        inv_obj.button_reset_cost(cr, uid, inv_ids, context)

    il_ids = line_inv_obj.search(cr,uid,[])

    if il_ids:
        cr.execute('SELECT DISTINCT product_id FROM report_profit_invoice WHERE id in ('+','.join(map(str,il_ids))+')')
        prd_ids = filter(None, map(lambda x:x[0], cr.fetchall()))
        for p_id in prd_ids:
            res[p_id] = []

        for line in line_inv_obj.browse(cr, uid, il_ids):
            dct = {}
            lst_tmp = []
            elem = False
            cost_ids = cost_obj.search(cr,uid,[('default_code','=',line.product_id.default_code)])
            if cost_ids:
                if len(cost_ids)==1:
                    elem=cost_ids[0]
                else:
                    raise wizard.except_wizard('Error','Codigo duplicado en csv importado')

            dct={
                'fecha': line.name,
                'costo': line.acc_cost,
                'cant': line.quantity,
                'tipo': line.invoice_id.type,
                'fact': line.invoice_id.id,
                'comp': line.move_id.id,
                'prod': line.product_id.id,
                'linea': line.line_id.id,
                'exist': line.stock,                
                'elem': elem
            }

            lst_tmp = res[line.product_id.id]
            lst_tmp.append(dct)
            res[line.product_id.id] = lst_tmp
               


    for pd_id in res.keys():
        dct = {}
        lst_tmp = []
        startf = datetime.date.fromtimestamp(time.mktime(time.strptime(time.strftime('%Y-%m-%d'),"%Y-%m-%d")))
        start = DateTime(int(startf.year),1,1)
        d1 = start.strftime('%Y-%m-%d')
        if res[pd_id] and res[pd_id][0]['elem']:
            c_ini = cost_obj.browse(cr, uid, res[pd_id][0]['elem'])
            dct={
                'fecha': d1,
                'costo': float(c_ini.standard_price.replace(',','')) or 0.0,
                'cant': float(c_ini.product_qty.replace(',','')) or 0.0,
                'tipo': u'cos_ini'
            }
            lst_tmp = res[pd_id]
            lst_tmp.append(dct)
            res[pd_id] = lst_tmp


    print 'ressssss: ',res            
    return {}
开发者ID:nhomar,项目名称:vauxoo_bzr2git,代码行数:89,代码来源:wizard_update_cost.py

示例8: int

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import strftime [as 别名]
assert int(d1 + d2) == 0
assert int(d2 + d1) == 0
assert int(d1 - d2) == 86400 * 2, d1 - d2
assert int(d2 - d1) == -86400 * 2, d2 - d1

try:
    d2 * d1
except TypeError:
    pass
else:
    raise TypeError('DateTimeDelta*DateTimeDelta should not work')

# .strftime()
d = DateTimeDelta(30,1,2,3)
assert d.strftime('%d %H:%M:%S') == '30 01:02:03'

# .strftime() and days out of typical month range
d = DateTimeDelta(32,1,2,3)
try:
    assert d.strftime('%d %H:%M:%S') == '32 01:02:03'
except ValueError:
    # On Windows, a ValueError is raised
    print "Note: dtd.strftime('%S') raises a ValueError on Windows with day > 31"

# .strftime() and unsupported format codes
d = DateTimeDelta(30,1,2,3)
try:
    assert d.strftime('%f') == '%f'
except ValueError:
    # On Windows, a ValueError is raised
开发者ID:Themanwithoutaplan,项目名称:egenix-mx-base-python-2x3,代码行数:32,代码来源:test.py


注:本文中的mx.DateTime.strftime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。