-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
add note about microsecond precision in Calendar.strftime #14137
Merged
josevalim
merged 3 commits into
elixir-lang:main
from
simonmcconnell:sm-strftime-format-note
Jan 4, 2025
+18
−1
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -496,38 +496,55 @@ defmodule Calendar do | |
|
||
The accepted formats for `string_format` are: | ||
|
||
Format | Description | Examples (in ISO) | ||
:----- | :-----------------------------------------------------------------------| :------------------------ | ||
a | Abbreviated name of day | Mon | ||
A | Full name of day | Monday | ||
b | Abbreviated month name | Jan | ||
B | Full month name | January | ||
c | Preferred date+time representation | 2018-10-17 12:34:56 | ||
d | Day of the month | 01, 31 | ||
f | Microseconds *(does not support width and padding modifiers)* | 000000, 999999, 0123 | ||
H | Hour using a 24-hour clock | 00, 23 | ||
I | Hour using a 12-hour clock | 01, 12 | ||
j | Day of the year | 001, 366 | ||
m | Month | 01, 12 | ||
M | Minute | 00, 59 | ||
p | "AM" or "PM" (noon is "PM", midnight as "AM") | AM, PM | ||
P | "am" or "pm" (noon is "pm", midnight as "am") | am, pm | ||
q | Quarter | 1, 2, 3, 4 | ||
s | Number of seconds since the Epoch, 1970-01-01 00:00:00+0000 (UTC) | 1565888877 | ||
S | Second | 00, 59, 60 | ||
u | Day of the week | 1 (Monday), 7 (Sunday) | ||
x | Preferred date (without time) representation | 2018-10-17 | ||
X | Preferred time (without date) representation | 12:34:56 | ||
y | Year as 2-digits | 01, 01, 86, 18 | ||
Y | Year | -0001, 0001, 1986 | ||
z | +hhmm/-hhmm time zone offset from UTC (empty string if naive) | +0300, -0530 | ||
Z | Time zone abbreviation (empty string if naive) | CET, BRST | ||
% | Literal "%" character | % | ||
Format | Description | Examples (in ISO) | ||
:----- | :----------------------------------------------------------------------- | :------------------------ | ||
a | Abbreviated name of day | Mon | ||
A | Full name of day | Monday | ||
b | Abbreviated month name | Jan | ||
B | Full month name | January | ||
c | Preferred date+time representation | 2018-10-17 12:34:56 | ||
d | Day of the month | 01, 31 | ||
f | Microseconds (uses its precision for width and padding) | 000000, 999999, 0123 | ||
H | Hour using a 24-hour clock | 00, 23 | ||
I | Hour using a 12-hour clock | 01, 12 | ||
j | Day of the year | 001, 366 | ||
m | Month | 01, 12 | ||
M | Minute | 00, 59 | ||
p | "AM" or "PM" (noon is "PM", midnight as "AM") | AM, PM | ||
P | "am" or "pm" (noon is "pm", midnight as "am") | am, pm | ||
q | Quarter | 1, 2, 3, 4 | ||
s | Number of seconds since the Epoch, 1970-01-01 00:00:00+0000 (UTC) | 1565888877 | ||
S | Second | 00, 59, 60 | ||
u | Day of the week | 1 (Monday), 7 (Sunday) | ||
x | Preferred date (without time) representation | 2018-10-17 | ||
X | Preferred time (without date) representation | 12:34:56 | ||
y | Year as 2-digits | 01, 01, 86, 18 | ||
Y | Year | -0001, 0001, 1986 | ||
z | +hhmm/-hhmm time zone offset from UTC (empty string if naive) | +0300, -0530 | ||
Z | Time zone abbreviation (empty string if naive) | CET, BRST | ||
% | Literal "%" character | % | ||
|
||
Any other character will be interpreted as an invalid format and raise an error. | ||
|
||
### `%f` Microseconds | ||
|
||
`%f` does not support width and padding modifiers. It will be formatted by truncating | ||
the microseconds to the precision of the `microseconds` field of the struct, with a | ||
minimum precision of 1. | ||
|
||
## Examples | ||
|
||
Microsecond formatting: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this to the end or middle of examples, we should not start with it. :) |
||
|
||
iex> Calendar.strftime(~U[2019-08-26 13:52:06Z], "%y-%m-%d %H:%M:%S.%f") | ||
"19-08-26 13:52:06.0" | ||
|
||
iex> Calendar.strftime(~U[2019-08-26 13:52:06.048Z], "%y-%m-%d %H:%M:%S.%f") | ||
"19-08-26 13:52:06.048" | ||
|
||
iex> Calendar.strftime(~U[2019-08-26 13:52:06.048531Z], "%y-%m-%d %H:%M:%S.%f") | ||
"19-08-26 13:52:06.048531" | ||
|
||
Without user options: | ||
|
||
iex> Calendar.strftime(~U[2019-08-26 13:52:06.0Z], "%y-%m-%d %I:%M:%S %p") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please make sure we only change a single row in the table? :) Thank you!