summaryrefslogtreecommitdiffstats
path: root/Doc/library/datetime.rst
Commit message (Collapse)AuthorAgeFilesLines
* GH-103857: Deprecate utcnow and utcfromtimestamp (#103858)Paul Ganssle2023-04-271-0/+8
| | | | | Using `datetime.datetime.utcnow()` and `datetime.datetime.utcfromtimestamp()` will now raise a `DeprecationWarning`. We also have removed our internal uses of these functions and documented the change.
* gh-99032: datetime docs: Encoding is no longer relevant (#93365)William Andrea2023-04-241-4/+1
| | | | | | | This removes a section of the `strftime` and `strptime` documentation that refers to a bygone era when `strftime` would return an encoded byte string. --------- Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
* gh-94300: Update datetime.strptime documentation (#95318)Howie Zhao2023-04-241-1/+1
| | | | | | | The new wording better reflects the cases where `datetime.strptime` differs from` time.strptime`. --------- Co-authored-by: Paul Ganssle <git@m.ganssle.io>
* gh-100574: add examples/links to the `strptime`/`strftime` docs (#100575)Ezio Melotti2023-04-081-21/+26
|
* GH-101898: Fix missing term references for hashable definition (#101899)Furkan Onder2023-02-141-1/+1
| | | Fix missing term references for hashable definition
* datetime.rst: fix combine() signature (#101490)John Belmonte2023-02-011-1/+1
| | | | | The default `tzinfo` param of the `combine()` signature pseudocode was erroneously `self.tzinfo`. `self` has no meaning in the context of a classmethod, and the datetime class itself has no `tzinfo` attribute. The correct default pseudocode is `time.tzinfo`, reflecting that the default is the `tzinfo` attribute of the `time` parameter.
* datetime.rst: improve combine() docs (#101338)John Belmonte2023-01-261-4/+3
| | | | | The explanation on handling of datetime as the date arg was confusingly mixed with an unrelated item, and lacked proper arg name formatting.
* gh-101041: Fix a misspelled name of `utctimetuple` in a doc warning (GH-101042)Oleg Iarygin2023-01-151-1/+1
|
* gh-99728: correct typo in `datetime` format codes documentation (#99750)Brad Wolfe2022-12-101-1/+1
|
* gh-99087: Add missing newline for prompts in docs (GH-98993)Stanley2022-12-091-0/+1
| | | Add newline for prompts so copying to REPL does not cause errors.
* Docs: Fix backtick errors found by sphinx-lint (#97998)Hugo van Kemenade2022-10-071-2/+2
| | | Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
* gh-69142: add %:z strftime format code (gh-95983)TW2022-08-281-2/+14
| | | | | | | | | | | | | | | | datetime.isoformat generates the tzoffset with colons, but there was no format code to make strftime output the same format. for simplicity and consistency the %:z formatting behaves mostly as %z, with the exception of adding colons. this includes the dynamic behaviour of adding seconds and microseconds only when needed (when not 0). this fixes the still open "generate" part of this issue: https://github.com/python/cpython/issues/69142 Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* Improve documentation for adding datetime and timedelta (gh-95403)BenjaminHelyer2022-07-291-2/+2
|
* Fix documentation to include possible Exception (#94818)Guy Yagev2022-07-181-2/+2
|
* gh-93851: Fix all broken links in Doc/ (GH-93853)Oleg Iarygin2022-06-211-1/+1
|
* Restore default role check in `make check`. (#92290)Ezio Melotti2022-05-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | * Restore default role check in `make check`. * Options first, then files. * Update `make.bat` too. * Add a comment explaining the extra options. * No reason to ignore the README.rst. * Enable default-role check in sphinx-lint. Co-authored-by: Julien Palard <julien@palard.fr> * Update sphinx-lint default-role check. * Fix use of the default role in the docs. * Update make.bat to check for the default role too. * Fix comment in make.bat. Co-authored-by: Julien Palard <julien@palard.fr>
* gh-80010: Expand fromisoformat to include most of ISO-8601 (#92177)Paul Ganssle2022-05-061-35/+48
| | | This expands `fromisoformat` to cover most of the common uses of ISO 8601. We may expand the scope more in the future.
* gh-91928: Add `datetime.UTC` alias for `datetime.timezone.utc` (GH-91973)Kabir Kwatra2022-05-031-0/+6
| | | | | | | | | ### fixes #91928 `UTC` is now module attribute aliased to `datetime.timezone.utc`. You can now do the following: ```python from datetime import UTC ```
* Update documentation in datetime module strftime-and-strptime-behavior fix ↵Evan2022-01-191-5/+5
| | | | | | | typo in '%W' format code description (GH-30232) A small change to the documentation of datetime module , in the format codes section of stftime and strptime. Changed the description of format code '%W' from 'as a decimal number' to 'a zero padded decimal number' so it's in line with the example having leading zeros. Similar to the format code '%U' above. Automerge-Triggered-By: GH:pganssle
* bpo-33381: [doc] strftime's %f option may pad zeros on the left or the right ↵Vishal Pandey2021-11-301-2/+2
| | | | (GH-29801)
* Add zoneinfo to the datetime documentation (GH-29038)Paul Ganssle2021-10-191-4/+6
| | | | | | We should have done this way back when 3.9 was released, but it fell off the radar. Co-authored-by: Paul Ganssle <git@m.ganssle.io>
* bpo-9811: [doc] strftime handling of unsupported format specifiers is ↵Irit Katriel2021-09-101-1/+2
| | | | platform dependent (GH-28264)
* [doc] Fix missing commas in signatures (#23693)Andre Delfino2020-12-221-2/+2
| | | | | * Fix star in signatures * Fix comma in signatures
* Reword aware/naive introduction sentence (GH-20175)Mathieu Dupuy2020-05-211-1/+2
| | | | | This is more informative and avoids the question of whether the period should go inside or outside the quotation marks. See also GH-20007.
* Doc: move a dot outside double quotes (GH-20007)Mathieu Dupuy2020-05-171-1/+1
|
* bpo-24416: Return named tuple from date.isocalendar() (GH-20113)Paul Ganssle2020-05-161-8/+12
| | | | | | | | | | | | | | | | | | | | | | | {date, datetime}.isocalendar() now return a private custom named tuple object IsoCalendarDate rather than a simple tuple. In order to leave IsocalendarDate as a private class and to improve what backwards compatibility is offered for pickling the result of a datetime.isocalendar() call, add a __reduce__ method to the named tuples that reduces them to plain tuples. (This is the part of this PR most likely to cause problems — if it causes major issues, switching to a strucseq or equivalent would be prudent). The pure python implementation of IsoCalendarDate uses positional-only arguments, since it is private and only constructed by position anyway; the equivalent change in the argument clinic on the C side would require us to move the forward declaration of the type above the clinic import for whatever reason, so it seems preferable to hold off on that for now. bpo-24416: https://bugs.python.org/issue24416 Original PR by Dong-hee Na with only minor alterations by Paul Ganssle. Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
* [typo] fix dupe in datetime.fromisoformat docs (GH-17295)Michael Morehouse2019-12-231-2/+0
| | | | | | | | | Fixes a nearly word for word duplication of a sentence that appears earlier in the caution section of datetime.datetime.fromisoformat in Doc/Library/datetime.rst. No issue created as it's a trivial change. Automerge-Triggered-By: @pganssle
* Add missing markup (GH-17680)cocoatomo2019-12-221-1/+1
| | | "HH", "MM" and "ffffff" are enclosed with double back quotes, but "SS" is left being bare
* Fix typos (GH-17423)Ofek Lev2019-12-011-2/+2
|
* bpo-22377: Fixes documentation for %Z in datetime (GH-16507)Karl Dubost2019-11-261-4/+13
| | | | | | | | | | This fixes the issue discussed in https://bugs.python.org/issue22377 and fixes it according to the comments made by Paul Ganssle @pganssle * It clarifies which values are acceptable in the table * It extends the note with a clearer information on the valid values https://bugs.python.org/issue22377
* bpo-37488 : Document a warning for datetime.utcnow() and utcfromtimestamp() ↵Joannah Nanjekye2019-09-111-16/+34
| | | | | | | | | (GH-15773) https://bugs.python.org/issue37488 Automerge-Triggered-By: @pganssle
* Overhaul datetime documentation (GH-13410)Brad2019-09-111-476/+729
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a restructuring of the datetime documentation to hopefully make them more user-friendly and approachable to new users without losing any of the detail. Changes include: - Creating dedicated subsections for some concepts such as: - "Constants" - "Naive vs Aware" - "Determining if an Object is Aware" - Give 'naive vs aware' its own subsection - Give 'constants' their own subsection - Overhauling the strftime-strptime section by: - Breaking it into logical, linkable, and digestable parts - Adding a high-level comparison table - Moving the technical detail to bottom: readers come to this section primarily to remind themselves to things: - How do I write the format code for X? - strptime/strftime: which one is which again? - Touching up fromisoformat + isoformat sections by: - Revising fromisoformat + isoformat for date, time, and datetime - Adding basic examples - Enforcing consistency about putting formats (i.e. ``HH:MM``) in double backticks. This was previously done in some places but not all - Putting long 'supported formats', on their own line to improve readability - Moving the 'seealso' section to the top and add a link to dateutil Rationale: This doesn't really belong nested under the 'constants' section. Let readers know right away that datetime is one of several related tools. - Moving common features of several types into one place: Previously, each type went out of its way to note separately that it was hashable and picklable. These can be brought into one single place that is more prominent. - Reducing some verbose explanations to improve readability - Breaking up long paragraphs into digestable chunks - Displaying longer "equivalent to" examples, as short code blocks - Using the dot notation for datetime/time classes: Use :class:`.time` and :class:`.datetime` rather than :class:`time` and :class:`datetime`; otherwise, the generated links will route to the respective modules, not classes. - Rewording the tzinfo class description The top paragraph should get straight to the point of telling the reader what subclasses of tzinfo _do_. Previously, that was hidden in a later paragraph. - Adding a note on .today() versus .now() - Rearranging and expanding example blocks, including: - Moved long, multiline inline examples to standalone examples - Simplified the example block for timedelta arithmetic: - Broke the example into two logical sections: 1. normalization/parameter 'merging' 2. timedelta arithmetic - Reduced the complexity of the some of the examples. Show reasonable, real-world uses cases that are easy to follow along with and progres in difficult slightly. - Broke up the example sections for date and datetime sections by putting the easy examples first, progressing to more esoteric situations and breaking it up into logical sections based on what the methods are doing at a high level. - Simplified the KabulTz example: - Put the class definition itself into a non-REPL block since there is no interactive output involved there - Briefly explained what's happening before launching into the code - Broke the example section into visually separate chunks - Various whitespace, formatting, style and grammar fixes including: - Consistently using backctics for 'date_string' formats - Consistently using one space after periods. - Consistently using bold for vocab terms - Consistently using italics when referring to params: See https://devguide.python.org/documenting/#id4 - Using '::' to lead into code blocks Per https://devguide.python.org/documenting/#source-code, this will let the reader use the 'expand/collapse' top-right button for REPL blocks to hide or show the prompt. - Using consistent captialization schemes - Removing use of the default role - Put 'example' blocks in Markdown subsections This is a combination of 66 commits. See bpo-36960: https://bugs.python.org/issue36960
* bpo-37979: Add alternative to fromisoformat in documentation (GH-15596)Paul Ganssle2019-08-291-1/+3
| | | | | | | | | | | | | | | | Adds a link to `dateutil.parser.isoparse` in the documentation. It would be nice to set up intersphinx for things like this, but I think we can leave that for a separate PR. CC: @pitrou [bpo-37979](https://bugs.python.org/issue37979) https://bugs.python.org/issue37979 Automerge-Triggered-By: @pitrou
* Clarify argument types in datetime docs. (GH-15459)Jürgen Gmach2019-08-241-3/+3
| | | | | | | | | | | | "Arguments may be integers... " could be misunderstand as they also could be strings. New wording makes it clear that arguments have to be integers. modified: Doc/library/datetime.rst Automerge-Triggered-By: @pganssle
* bpo-34903: Document that some strptime formats only require 1 digit (GH-14149)Mike Gleen2019-06-181-15/+20
| | | | | | | For datetime.datetime.strptime(), the leading zero for some two-digit formats is optional. This adds a footnote to the strftime/strptime documentation to reflect this fact, and adds some tests to ensure that it is true. bpo-34903
* bpo-30699: Improve example on datetime tzinfo instances (GH-4290)Mario Corchero2019-06-041-51/+60
| | | | | | | | | | | | | | | | | | | * Improve example on tzinfo instances Move from GMTX to TZX when naming the classes, as GMT1 might be rather confusing as seen in the reported issue. In addition, move to UTC over GMT and improve the tzname implementation. * Simplify datetime with tzinfo example Move the example in the documentation to just use timezone.utc and a user defined Kabul timezone rather than having two user defined timezones with DST. Kabul timezone is still interesting as it changes its offset but not based on DST. This is more accurate as the previous example was missing information about the fold attribute. Additionally, implementing the fold attribute was rather complex and probably not relevant enough for the section "datetime with tzinfo".
* bpo-19376: Added doc mentioning `datetime.strptime()` without a year fails ↵Abhishek Kumar Singh2019-05-181-0/+4
| | | | for Feb 29. (GH-10243)
* bpo-36004: Add date.fromisocalendar (GH-11888)Paul Ganssle2019-04-291-0/+17
| | | | This commit implements the first version of date.fromisocalendar, the inverse function for date.isocalendar.
* bpo-36138: Clarify docs about converting datetime.timedelta to scalars. ↵Yasser A2019-03-161-3/+5
| | | | | | (GH-12137) Be explicit that timedelta division converts an overall duration to the interval units given by the denominator.
* bpo-34512: Document platform-specific strftime() behavior for non-ASCII ↵Alexey Izbyshev2019-01-121-0/+6
| | | | format strings (GH-8948)
* bpo-35110: Fix unintentional spaces around hyphens and dashes. (GH-10231)Serhiy Storchaka2018-10-311-3/+4
|
* bpo-27741: Better wording for datetime.strptime() (GH-9994)Gus Goulart2018-10-291-1/+3
|
* bpo-35054: Add yet more index entries for symbols. (GH-10121)Serhiy Storchaka2018-10-281-1/+1
|
* bpo-35054: Add more index entries for symbols. (GH-10064)Serhiy Storchaka2018-10-261-0/+3
|
* bpo-34158: Documentation UTC offset update (GH-8377)Christophe Nanteuil2018-10-051-20/+21
| | | | | | | | | | | | | | | | | | | | | * Documentation of UTC offset update Since changes in the UTC offset that allows sub-minute offsets, the documentation needs update: - "%z" format code documentation update Karthikeyan Singaravelan commented on bugs.python.org: Added as part of 018d353c1c8c87767d2335cd884017c2ce12e045 and a fix regarding duplicate words for that part was added at bac2d5ba30339298db7d4caa9c8cd31d807cf081. Relevant format string at https://github.com/python/cpython/pull/2896/files#diff-25e2d173c84057d069b7890450714eddR214. Relevant test case with 6-digit string for microsecond : https://github.com/python/cpython/pull/2896/files#diff-acc40bec51c7de832de3361db3edae52R309. Table at https://docs.python.org/3.7/library/datetime.html#strftime-and-strptime-behavior could also be updated with microseconds being optional in the second column %z | UTC offset in the form ±HHMM[SS] (empty string if the object is naive). | (empty), +0000, -0400, +1030 - isoformat documentation update According to me, needs confirmation: Relevant format string at https://github.com/python/cpython/pull/4699/files#diff-25e2d173c84057d069b7890450714eddR176 Relevant test case at https://github.com/python/cpython/pull/4699/files#diff-25e2d173c84057d069b7890450714edd * From Martin Panter: some style improvment; From @pganssle: using f for fractional part of seconds in all file.
* bpo-34365: Update date object documentation (GH-8814)Danish Prakash2018-09-111-4/+3
| | | | | | | | Python 3.x does not fall back to comparing object addresses when comparing two `dt` objects. <!-- issue-number: [bpo-34365](https://www.bugs.python.org/issue34365) --> https://bugs.python.org/issue34365 <!-- /issue-number -->
* bpo-30516: Fix documentation issue with -timedelta in datetime (GH-7348)Farhaan Bukhsh2018-07-041-5/+6
| | | | | This commit fixes the -timedelta overfllow issue not documented properly. Signed-off-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
* bpo-33812: Corrected astimezone for naive datetimes. (GH-7578)Alexander Belopolsky2018-06-101-2/+1
| | | | | | | | | | | | | | | | | | | | A datetime object d is aware if d.tzinfo is not None and d.tzinfo.utcoffset(d) does not return None. If d.tzinfo is None, or if d.tzinfo is not None but d.tzinfo.utcoffset(d) returns None, d is naive. This commit ensures that instances with non-None d.tzinfo, but d.tzinfo.utcoffset(d) returning None are treated as naive. In addition, C acceleration code will raise TypeError if d.tzinfo.utcoffset(d) returns an object with the type other than timedelta. * Updated the documentation. Assume that the term "naive" is defined elsewhere and remove the not entirely correct clarification. Thanks, Tim.
* Fix duplicating words words. (GH-6296)Serhiy Storchaka2018-03-281-2/+2
| | | Most of them have been added in 3.7.
* bpo-15873: Implement [date][time].fromisoformat (#4699)Paul Ganssle2017-12-211-1/+47
| | | Closes bpo-15873.