Skip to content

Commit 10b69f7

Browse files
committed
update check_time_args
1 parent 8189e88 commit 10b69f7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Lib/_pydatetime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,8 @@ def _check_time_fields(hour, minute, second, microsecond, nanosecond, fold):
594594
raise ValueError(f"second must be in 0..59, not {second}")
595595
if not 0 <= microsecond <= 999999:
596596
raise ValueError(f"microsecond must be in 0..999999, not {microsecond}")
597-
if not 0 <= nanosecond <= 999999999:
598-
raise ValueError(f"nanosecond must be in 0..999999999, not {nanosecond}")
597+
if not 0 <= nanosecond <= 999:
598+
raise ValueError(f"nanosecond must be in 0..999, not {nanosecond}")
599599
if fold not in (0, 1):
600600
raise ValueError(f"fold must be either 0 or 1, not {fold}")
601601
return hour, minute, second, microsecond, nanosecond, fold

Modules/_datetimemodule.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ check_date_args(int year, int month, int day)
679679
* aren't, raise ValueError and return -1.
680680
*/
681681
static int
682-
check_time_args(int h, int m, int s, int us, int fold)
682+
check_time_args(int h, int m, int s, int us, int ns, int fold)
683683
{
684684
if (h < 0 || h > 23) {
685685
PyErr_Format(PyExc_ValueError, "hour must be in 0..23, not %i", h);
@@ -698,6 +698,11 @@ check_time_args(int h, int m, int s, int us, int fold)
698698
"microsecond must be in 0..999999, not %i", us);
699699
return -1;
700700
}
701+
if (ns < 0 || ns > 999) {
702+
PyErr_Format(PyExc_ValueError,
703+
"nanosecond must be in 0..999, not %i", ns);
704+
return -1;
705+
}
701706
if (fold != 0 && fold != 1) {
702707
PyErr_Format(PyExc_ValueError,
703708
"fold must be either 0 or 1, not %i", fold);

0 commit comments

Comments
 (0)