Skip to content

gh-59648: Nanosecond support for datetime #92078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 85 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
bcc712e
Nanosecond support for datetime
SmartManoj Apr 30, 2022
db8a9a5
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 30, 2022
b559573
typo
SmartManoj Apr 30, 2022
e0e0ee9
removed Decimal
SmartManoj May 6, 2022
c0af7e9
updated probe1
SmartManoj May 6, 2022
1678928
updated utcnow
SmartManoj May 6, 2022
7f6b8b8
Merge branch 'main' into patch-4
SmartManoj May 6, 2022
8492efa
Merge branch 'main' into patch-4
SmartManoj May 20, 2022
37e77d8
nit
SmartManoj Jan 28, 2025
1b500e6
don't divide
SmartManoj Jan 28, 2025
049a7dd
Merge branch 'main' into pr/92078
SmartManoj Jan 28, 2025
3de498e
add nanosecond
SmartManoj Jan 28, 2025
b0c9552
update docstring
SmartManoj Jan 28, 2025
69bfcd8
truncate decimal
SmartManoj Jan 28, 2025
ef62206
rename to nanosecond
SmartManoj Jan 29, 2025
78d4188
parse empty string
SmartManoj Jan 29, 2025
b56c892
Merge branch 'main' into patch-4
SmartManoj Apr 17, 2025
e7305a4
fix kwarg
SmartManoj Apr 17, 2025
9d2f818
update logic
SmartManoj Apr 17, 2025
0986e7b
lint
SmartManoj Apr 17, 2025
e437eaf
Merge branch 'main' into pr/92078
SmartManoj Apr 17, 2025
be25162
Merge branch 'main' into patch-4
SmartManoj Apr 23, 2025
38c00d6
cleanup
SmartManoj Apr 24, 2025
e23588b
revert changes in __reduce__
SmartManoj Apr 24, 2025
bf71681
lint
SmartManoj Apr 24, 2025
dac7876
update time class
SmartManoj Apr 24, 2025
2b78414
update whatsnew
SmartManoj Apr 24, 2025
efb694f
Change name to English
SmartManoj Apr 24, 2025
e4ae66d
Remove Emoji
SmartManoj Apr 24, 2025
f5c118d
Merge branch 'main' into pr/92078
SmartManoj Apr 24, 2025
0b7a81b
update news
SmartManoj Apr 24, 2025
8189e88
update time_isoformat
SmartManoj Apr 24, 2025
10b69f7
update check_time_args
SmartManoj Apr 24, 2025
b0ebfc5
add nanosecond arg
SmartManoj Apr 24, 2025
adb92a6
Merge branch 'main' into pr/92078
SmartManoj Apr 25, 2025
54127a2
update timedelta
SmartManoj Apr 25, 2025
633ff23
add complimentary changes
SmartManoj Apr 25, 2025
6687799
Merge branch 'main' into pr/92078
SmartManoj Apr 25, 2025
4ca6185
add ns
SmartManoj Apr 25, 2025
0c4ff5a
Merge branch 'main' into pr/92078
SmartManoj Apr 25, 2025
f100451
lint
SmartManoj Apr 25, 2025
4f5f428
add macro
SmartManoj Apr 25, 2025
6a43121
Merge branch 'main' into pr/92078
SmartManoj Apr 25, 2025
9c23406
update doc
SmartManoj Apr 25, 2025
b125d71
declare delta_ns
SmartManoj Apr 25, 2025
911ddb0
fix constructors
SmartManoj Apr 25, 2025
c775e96
Merge branch 'main' into pr/92078
SmartManoj Apr 25, 2025
3590c7c
fix signature
SmartManoj Apr 26, 2025
c323ed5
Merge branch 'main' into pr/92078
SmartManoj Apr 26, 2025
d577bc3
fix clinic input
SmartManoj Apr 26, 2025
29c8112
fix get_datetime_fromdateandtime
SmartManoj Apr 26, 2025
13dcc7b
fix macro
SmartManoj Apr 26, 2025
26c8800
fix get_time_fromtime
SmartManoj Apr 26, 2025
b30edbc
force regenerate clinic output
SmartManoj Apr 26, 2025
aed1afa
add append_keyword_nanosecond
SmartManoj Apr 27, 2025
75553a2
fix tests
SmartManoj Apr 26, 2025
dad595d
Merge branch 'main' into pr/92078
SmartManoj Apr 27, 2025
6f4db2b
Merge branch 'main' into pr/92078
SmartManoj Apr 28, 2025
ebaf468
remove test_backdoor_resistance
SmartManoj Apr 28, 2025
00e3b45
minor fixes
SmartManoj Apr 28, 2025
f9d468c
update tests
SmartManoj Apr 28, 2025
4959a6a
Merge branch 'main' into pr/92078
SmartManoj Apr 28, 2025
eabd9a5
fix test
SmartManoj Apr 28, 2025
7d8183c
Merge branch 'main' into pr/92078
SmartManoj Apr 28, 2025
70320ca
bug fix
SmartManoj Apr 29, 2025
10ac2d6
temp
SmartManoj Apr 29, 2025
bda6c29
Merge branch 'main' into pr/92078
SmartManoj Apr 29, 2025
0bcf405
bug fix
SmartManoj Apr 30, 2025
17f2943
update test
SmartManoj Apr 30, 2025
2173886
temp
SmartManoj Apr 30, 2025
387baf9
Merge branch 'main' into pr/92078
SmartManoj Apr 30, 2025
56bc655
regen
SmartManoj May 1, 2025
92c53b2
temp
SmartManoj May 1, 2025
629fa5b
Merge branch 'main' into pr/92078
SmartManoj May 1, 2025
9b73fd6
add missing arg
SmartManoj May 1, 2025
4fefead
use const
SmartManoj May 1, 2025
28647b0
update value
SmartManoj May 1, 2025
bdb8385
temp
SmartManoj May 1, 2025
861e403
Update datetimetester.py
SmartManoj May 1, 2025
7fddf11
Update datetime.h
SmartManoj May 1, 2025
0b0b214
fix arg
SmartManoj May 1, 2025
c2ed07c
temp
SmartManoj May 1, 2025
bae2e30
Merge branch 'main' into pr/92078
SmartManoj May 1, 2025
98297a1
lint
SmartManoj May 1, 2025
8d80782
temp
SmartManoj May 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 100 additions & 35 deletions Doc/library/datetime.rst

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@ datetime
* Add :meth:`datetime.time.strptime` and :meth:`datetime.date.strptime`.
(Contributed by Wannes Boeykens in :gh:`41431`.)

* Add nanosecond precision support for :class:`datetime.datetime` and
:class:`datetime.time` objects.
(Contributed by Manojkumar Palanisamy in :gh:`59648`.)

decimal
-------

Expand Down
46 changes: 28 additions & 18 deletions Include/datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ extern "C" {
* 4 hour 1 byte, 0-23
* 5 minute 1 byte, 0-59
* 6 second 1 byte, 0-59
* 7 usecond 3 bytes, 0-999999
* 10
* 7 microsecond 3 bytes, 0-999999
* 10 nsecond 2 bytes, 0-999
* 12
*/

/* # of bytes for year, month, and day. */
#define _PyDateTime_DATE_DATASIZE 4

/* # of bytes for hour, minute, second, and usecond. */
#define _PyDateTime_TIME_DATASIZE 6
/* # of bytes for hour, minute, second, microsecond and nanosecond */
#define _PyDateTime_TIME_DATASIZE 8

/* # of bytes for year, month, day, hour, minute, second, and usecond. */
#define _PyDateTime_DATETIME_DATASIZE 10
/* # of bytes for year, month, day, hour, minute, second, microsecond and nanosecond */
#define _PyDateTime_DATETIME_DATASIZE 12


typedef struct
Expand All @@ -38,6 +39,7 @@ typedef struct
int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
int seconds; /* 0 <= seconds < 24*3600 is invariant */
int microseconds; /* 0 <= microseconds < 1000000 is invariant */
int nanoseconds; /* 0 <= nanoseconds < 1000 is invariant */
} PyDateTime_Delta;

typedef struct
Expand Down Expand Up @@ -131,6 +133,9 @@ typedef struct
((((PyDateTime_DateTime*)(o))->data[7] << 16) | \
(((PyDateTime_DateTime*)(o))->data[8] << 8) | \
((PyDateTime_DateTime*)(o))->data[9])
#define PyDateTime_DATE_GET_NANOSECOND(o) \
((((PyDateTime_DateTime*)(o))->data[10] << 8) | \
((PyDateTime_DateTime*)(o))->data[11])
#define PyDateTime_DATE_GET_FOLD(o) (((PyDateTime_DateTime*)(o))->fold)
#define PyDateTime_DATE_GET_TZINFO(o) (_PyDateTime_HAS_TZINFO((o)) ? \
((PyDateTime_DateTime *)(o))->tzinfo : Py_None)
Expand All @@ -143,6 +148,9 @@ typedef struct
((((PyDateTime_Time*)(o))->data[3] << 16) | \
(((PyDateTime_Time*)(o))->data[4] << 8) | \
((PyDateTime_Time*)(o))->data[5])
#define PyDateTime_TIME_GET_NANOSECOND(o) \
((((PyDateTime_Time*)(o))->data[6] << 8) | \
((PyDateTime_Time*)(o))->data[7])
#define PyDateTime_TIME_GET_FOLD(o) (((PyDateTime_Time*)(o))->fold)
#define PyDateTime_TIME_GET_TZINFO(o) (_PyDateTime_HAS_TZINFO(o) ? \
((PyDateTime_Time *)(o))->tzinfo : Py_None)
Expand All @@ -152,6 +160,8 @@ typedef struct
#define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)(o))->seconds)
#define PyDateTime_DELTA_GET_MICROSECONDS(o) \
(((PyDateTime_Delta*)(o))->microseconds)
#define PyDateTime_DELTA_GET_NANOSECONDS(o) \
(((PyDateTime_Delta*)(o))->nanoseconds)


/* Define structure for C API. */
Expand All @@ -171,7 +181,7 @@ typedef struct {
PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int,
PyObject*, PyTypeObject*);
PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*);
PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*);
PyObject *(*Delta_FromDelta)(int, int, int, int, int, PyTypeObject*);
PyObject *(*TimeZone_FromTimeZone)(PyObject *offset, PyObject *name);

/* constructors for the DB API */
Expand All @@ -180,8 +190,8 @@ typedef struct {

/* PEP 495 constructors */
PyObject *(*DateTime_FromDateAndTimeAndFold)(int, int, int, int, int, int, int,
PyObject*, int, PyTypeObject*);
PyObject *(*Time_FromTimeAndFold)(int, int, int, int, PyObject*, int, PyTypeObject*);
PyObject*, int, int, PyTypeObject*);
PyObject *(*Time_FromTimeAndFold)(int, int, int, int, PyObject*, int, int, PyTypeObject*);

} PyDateTime_CAPI;

Expand Down Expand Up @@ -227,20 +237,20 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL;
PyDateTimeAPI->DateTime_FromDateAndTime((year), (month), (day), (hour), \
(min), (sec), (usec), Py_None, PyDateTimeAPI->DateTimeType)

#define PyDateTime_FromDateAndTimeAndFold(year, month, day, hour, min, sec, usec, fold) \
#define PyDateTime_FromDateAndTimeAndFold(year, month, day, hour, min, sec, usec, fold, nanosecond) \
PyDateTimeAPI->DateTime_FromDateAndTimeAndFold((year), (month), (day), (hour), \
(min), (sec), (usec), Py_None, (fold), PyDateTimeAPI->DateTimeType)
(min), (sec), (usec), Py_None, (fold), (nanosecond), PyDateTimeAPI->DateTimeType)

#define PyTime_FromTime(hour, minute, second, usecond) \
PyDateTimeAPI->Time_FromTime((hour), (minute), (second), (usecond), \
#define PyTime_FromTime(hour, minute, second, microsecond) \
PyDateTimeAPI->Time_FromTime((hour), (minute), (second), (microsecond), \
Py_None, PyDateTimeAPI->TimeType)

#define PyTime_FromTimeAndFold(hour, minute, second, usecond, fold) \
PyDateTimeAPI->Time_FromTimeAndFold((hour), (minute), (second), (usecond), \
Py_None, (fold), PyDateTimeAPI->TimeType)
#define PyTime_FromTimeAndFold(hour, minute, second, microsecond, fold, nanosecond) \
PyDateTimeAPI->Time_FromTimeAndFold((hour), (minute), (second), (microsecond), \
Py_None, (fold), (nanosecond), PyDateTimeAPI->TimeType)

#define PyDelta_FromDSU(days, seconds, useconds) \
PyDateTimeAPI->Delta_FromDelta((days), (seconds), (useconds), 1, \
#define PyDelta_FromDSU(days, seconds, microseconds, nanoseconds) \
PyDateTimeAPI->Delta_FromDelta((days), (seconds), (microseconds), (nanoseconds), 1, \
PyDateTimeAPI->DeltaType)

#define PyTimeZone_FromOffset(offset) \
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(name_from)
STRUCT_FOR_ID(namespace_separator)
STRUCT_FOR_ID(namespaces)
STRUCT_FOR_ID(nanosecond)
STRUCT_FOR_ID(narg)
STRUCT_FOR_ID(ndigits)
STRUCT_FOR_ID(nested)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading