relative datetime improvements (fixes #15167)

This commit is contained in:
Benjamin Dauvergne 2017-02-27 15:09:35 +01:00
parent ab947ce0a0
commit c513691ba8
2 changed files with 18 additions and 3 deletions

View File

@ -32,6 +32,11 @@ class RelativeDate(date):
'truncate': 'year',
'timedelta': {'years': -1},
},
{
'pattern': u' *l\'année +prochaine *',
'truncate': 'year',
'timedelta': {'years': 1},
},
{
'pattern': ' *les +(?P<years>[1-9][0-9]*)+ +dernières +années*',
'truncate': 'year',
@ -79,6 +84,16 @@ class RelativeDate(date):
'truncate': 'quarter',
'timedelta': {'months': '-3*quarters'},
},
{
'pattern': ' *le +prochain +trimestre *',
'truncate': 'quarter',
'timedelta': {'months': 3},
},
{
'pattern': ' *les +(?P<quarters>[1-9][0-9]*) +prochains +trimestres *',
'truncate': 'quarter',
'timedelta': {'months': '3*quarters'},
},
{
'pattern': ' *maintenant *',
},
@ -104,7 +119,7 @@ class RelativeDate(date):
d = d + relativedelta(weekday=MO(-1))
if template['truncate'] == 'quarter':
d = d.replace(day=1)
d = d + relativedelta(months=-((d.month - 1) % 3))
d = d + relativedelta(months=3 - ((d.month - 1) % 3))
if 'timedelta' in template:
timedelta = template['timedelta']
kwargs = {}

View File

@ -57,7 +57,7 @@ DATE_RANGES = [
'value': 'this_year',
'label': _('this year'),
'start': u"cette année",
'end': u"maintenant",
'end': u"l\'année prochaine",
},
{
'value': 'last_year',
@ -69,7 +69,7 @@ DATE_RANGES = [
'value': 'this_quarter',
'label': _('this quarter'),
'start': u'ce trimestre',
'end': "maintenant",
'end': "le prochain trimestre",
},
{
'value': 'last_quarter',