Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
f4c0eec7
Kaydet (Commit)
f4c0eec7
authored
Ock 14, 2017
tarafından
Jinank Jain
Kaydeden (comit)
Claude Paroz
Ock 14, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27699 -- Added negative timedelta support to parse_duration()
üst
8ade277a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
dateparse.py
django/utils/dateparse.py
+5
-3
test_dateparse.py
tests/utils_tests/test_dateparse.py
+4
-0
No files found.
django/utils/dateparse.py
Dosyayı görüntüle @
f4c0eec7
...
...
@@ -30,9 +30,9 @@ datetime_re = re.compile(
standard_duration_re
=
re
.
compile
(
r'^'
r'(?:(?P<days>-?\d+) (days?, )?)?'
r'((?:(?P<hours>\d+):)(?=\d+:\d+))?'
r'(?:(?P<minutes>\d+):)?'
r'(?P<seconds>\d+)'
r'((?:(?P<hours>
-?
\d+):)(?=\d+:\d+))?'
r'(?:(?P<minutes>
-?
\d+):)?'
r'(?P<seconds>
-?
\d+)'
r'(?:\.(?P<microseconds>\d{1,6})\d{0,6})?'
r'$'
)
...
...
@@ -125,5 +125,7 @@ def parse_duration(value):
sign
=
-
1
if
kw
.
pop
(
'sign'
,
'+'
)
==
'-'
else
1
if
kw
.
get
(
'microseconds'
):
kw
[
'microseconds'
]
=
kw
[
'microseconds'
]
.
ljust
(
6
,
'0'
)
if
kw
.
get
(
'seconds'
)
and
kw
.
get
(
'microseconds'
)
and
kw
[
'seconds'
]
.
startswith
(
'-'
):
kw
[
'microseconds'
]
=
'-'
+
kw
[
'microseconds'
]
kw
=
{
k
:
float
(
v
)
for
k
,
v
in
six
.
iteritems
(
kw
)
if
v
is
not
None
}
return
sign
*
datetime
.
timedelta
(
**
kw
)
tests/utils_tests/test_dateparse.py
Dosyayı görüntüle @
f4c0eec7
...
...
@@ -108,6 +108,10 @@ class DurationParseTests(unittest.TestCase):
def
test_negative
(
self
):
self
.
assertEqual
(
parse_duration
(
'-4 15:30'
),
timedelta
(
days
=-
4
,
minutes
=
15
,
seconds
=
30
))
self
.
assertEqual
(
parse_duration
(
'-172800'
),
timedelta
(
days
=-
2
))
self
.
assertEqual
(
parse_duration
(
'-15:30'
),
timedelta
(
minutes
=-
15
,
seconds
=
30
))
self
.
assertEqual
(
parse_duration
(
'-1:15:30'
),
timedelta
(
hours
=-
1
,
minutes
=
15
,
seconds
=
30
))
self
.
assertEqual
(
parse_duration
(
'-30.1'
),
timedelta
(
seconds
=-
30
,
milliseconds
=-
100
))
def
test_iso_8601
(
self
):
self
.
assertIsNone
(
parse_duration
(
'P4Y'
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment