How to use the tryton.common.datetime_strftime function in tryton

To help you get started, we’ve selected a few tryton examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tryton / tryton / tryton / gui / window / view_tree / view_tree.py View on Github external
else:
                            val[field] = ''
                    res_ids.append(val)
                    if obj_id not in self.to_reload:
                        self.to_reload.append(obj_id)
        res_ids.sort(lambda x, y: cmp(ids.index(x['id']), ids.index(y['id'])))
        for field in self.fields:
            field_type = self.fields_type[field]['type']
            if field in self.fields_attrs \
                    and 'widget' in self.fields_attrs[field]:
                field_type = self.fields_attrs[field]['widget']
            if field_type in ('date',):
                display_format = date_format()
                for obj in res_ids:
                    if obj[field]:
                        obj[field] = common.datetime_strftime(obj[field],
                                display_format)
            elif field_type in ('datetime',):
                display_format = date_format() + ' ' + HM_FORMAT
                for obj in res_ids:
                    if obj[field]:
                        if 'timezone' in rpc.CONTEXT:
                            try:
                                import pytz
                                lzone = pytz.timezone(rpc.CONTEXT['timezone'])
                                szone = pytz.timezone(rpc.TIMEZONE)
                                sdt = szone.localize(obj[field], is_dst=True)
                                ldt = sdt.astimezone(lzone)
                                obj[field] = ldt
                            except Exception:
                                pass
                        obj[field] = common.datetime_strftime(obj[field],
github tryton / tryton / tryton / gui / window / view_form / widget_search / calendar.py View on Github external
def conv(value):
            if not value:
                return ''
            try:
                return datetime_strftime(value, self.format)
            except ValueError:
                return ''
github tryton / tryton / tryton / common / tdp.py View on Github external
suggestions = tuple(x[1]
                        for x in parent_field['selection'])
                else:
                    suggestions = (_('Y'), _('Yes'), _('True'), '1', _('N'),
                        _('No'), _('False'), '0')
                for suggestion in self.suggest_ltr(words, suggestions):
                    if suggestion != orig:
                        extra.append(suggestion)
            elif parent_field['type'] in ('date', 'datetime'):
                format_ = date_format()
                if parent_field['type'] == 'datetime':
                    format_ += ' ' + HM_FORMAT
                entry = DateEntry(format_)
                entry.set_text(entry.initial_value)
                gtk.Entry.insert_text(entry, orig, 0)
                default = datetime_strftime(datetime.datetime.combine(
                        datetime.date.today(), datetime.time.min), format_)
                value = entry.compute_date(entry.get_text(), default) or ''
                if value:
                    if value.endswith(' 00:00:00'):
                        value = value[:-9]
                    if len(value) > len(orig):
                        extra.append(quote(value))

        if not extra:
            values = tuple(self.suggest(words, self.parser.sugg_fields))

        if not values and not extra:
            values = (quote(' '.join(reversed(words))),)
        elif (not self.parent) or self.pos == 'right':
            values = extra or tuple(v + ':' for v in values)
github tryton / tryton / tryton / common / tdp.py View on Github external
def test_date_domain():
    today = datetime.date.today()
    today_str = datetime_strftime(today, date_format())
    parser = test_parser()
    assert parser.parse('Date:').domain() == []
    assert parser.parse('Date: ' + today_str[0]).domain() == [
        ('date', '=', False)]
    assert parser.parse('Date: >' + today_str[0]).domain() == [
        ('date', '>', False)]
    assert parser.parse('Date: 12/04/2002').domain() == [
        ('date', '=', datetime.date(2002, 12, 4))]
    assert parser.parse('Date: 12/4/2002').domain() == [
        ('date', '=', datetime.date(2002, 12, 4))]
    assert parser.parse('Date: 12/4/2002; 1/1/1970').domain() == [
        ('date', 'in', [datetime.date(2002, 12, 4),
                datetime.date(1970, 1, 1)])]
github tryton / tryton / tryton / gui / window / view_form / widget_search / calendar.py View on Github external
def _date_get(self, value):
        try:
            date = datetime.date(*time.strptime(value, self.format)[:3])
        except ValueError:
            return False
        if self.attrs.get('type', 'date') == 'datetime':
            return datetime_strftime(datetime.datetime.combine(date,
                datetime.time.min), DHM_FORMAT)
        return datetime_strftime(date, DT_FORMAT)
github tryton / tryton / tryton / gui / window / view_tree / view_tree.py View on Github external
display_format)
            elif field_type in ('datetime',):
                display_format = date_format() + ' ' + HM_FORMAT
                for obj in res_ids:
                    if obj[field]:
                        if 'timezone' in rpc.CONTEXT:
                            try:
                                import pytz
                                lzone = pytz.timezone(rpc.CONTEXT['timezone'])
                                szone = pytz.timezone(rpc.TIMEZONE)
                                sdt = szone.localize(obj[field], is_dst=True)
                                ldt = sdt.astimezone(lzone)
                                obj[field] = ldt
                            except Exception:
                                pass
                        obj[field] = common.datetime_strftime(obj[field],
                                display_format)
            elif field_type in ('many2one', 'one2one'):
                for obj in res_ids:
                    if obj[field]:
                        obj[field] = obj[field + '.rec_name']
            elif field_type in ('selection'):
                selection = self.fields_type[field]['selection']
                if 'relation' in self.fields_type[field]:
                    try:
                        result = rpc.execute('model',
                                self.fields_type[field]['relation'],
                                'search_read',
                                self.fields_type[field].get('domain', []),
                                0, None, None,
                                ['rec_name'], rpc.CONTEXT)
                        selection = [(x['id'], x['rec_name']) for x in result]
github tryton / tryton / tryton / gui / window / view_form / widget_search / calendar.py View on Github external
def _date_get(self, value):
        try:
            date = datetime.date(*time.strptime(value, self.format)[:3])
        except ValueError:
            return False
        if self.attrs.get('type', 'date') == 'datetime':
            return datetime_strftime(datetime.datetime.combine(date,
                datetime.time.min), DHM_FORMAT)
        return datetime_strftime(date, DT_FORMAT)