Skip to content

Commit 763d0f1

Browse files
Add note about microsecond precision in Calendar.strftime (#14137)
1 parent cbc4c8b commit 763d0f1

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/elixir/lib/calendar.ex

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ defmodule Calendar do
504504
B | Full month name | January
505505
c | Preferred date+time representation | 2018-10-17 12:34:56
506506
d | Day of the month | 01, 31
507-
f | Microseconds *(does not support width and padding modifiers)* | 000000, 999999, 0123
507+
f | Microseconds (uses its precision for width and padding) | 000000, 999999, 0123
508508
H | Hour using a 24-hour clock | 00, 23
509509
I | Hour using a 12-hour clock | 01, 12
510510
j | Day of the year | 001, 366
@@ -526,6 +526,12 @@ defmodule Calendar do
526526
527527
Any other character will be interpreted as an invalid format and raise an error.
528528
529+
### `%f` Microseconds
530+
531+
`%f` does not support width and padding modifiers. It will be formatted by truncating
532+
the microseconds to the precision of the `microseconds` field of the struct, with a
533+
minimum precision of 1.
534+
529535
## Examples
530536
531537
Without user options:
@@ -569,6 +575,17 @@ defmodule Calendar do
569575
...>)
570576
"серпень"
571577
578+
Microsecond formatting:
579+
580+
iex> Calendar.strftime(~U[2019-08-26 13:52:06Z], "%y-%m-%d %H:%M:%S.%f")
581+
"19-08-26 13:52:06.0"
582+
583+
iex> Calendar.strftime(~U[2019-08-26 13:52:06.048Z], "%y-%m-%d %H:%M:%S.%f")
584+
"19-08-26 13:52:06.048"
585+
586+
iex> Calendar.strftime(~U[2019-08-26 13:52:06.048531Z], "%y-%m-%d %H:%M:%S.%f")
587+
"19-08-26 13:52:06.048531"
588+
572589
"""
573590
@doc since: "1.11.0"
574591
@spec strftime(map(), String.t(), keyword()) :: String.t()

0 commit comments

Comments
 (0)