Skip to content

Commit d6bf093

Browse files
committed
RFC #66: Add string formatting.
1 parent 5b05fe8 commit d6bf093

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

text/0066-simulation-time.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ The following operators are defined:
8080
- Operators on `Period`s are performed on the underlying femtosecond values.
8181
- Operators involving `numbers.Real` operands have the result rounded back to the closest integer femtosecond representation.
8282
- Operators given unsupported operand combinations will return `NotImplemented`.
83+
- `.__str__() -> str`
84+
- Equivalent to `.__format__("")`
85+
- `.__format__(format_spec: str) -> str`
86+
- The format specifier format is `[width][.precision][ ][unit]`.
87+
- An invalid format specifier raises `ValueError`.
88+
- If `width` is specified, the string is left-padded with space to at least the requested width.
89+
- If `precision` is specified, the requested number of decimal digits will be emitted.
90+
Otherwise, duration units will emit as many digits required for an exact result, while frequency units will defer to default `float` formatting.
91+
- If a space is present in the format specifier, the formatted string will have a space between the number and the unit.
92+
- `unit` can be specified as any of the argument names accepted by the constructor.
93+
If a unit is not specified, the largest duration unit that has a nonzero integer part is used.
94+
Formatting frequency units have the same restrictions and exception behavior as accessing frequency properties.
8395

8496
`SimulatorContext` have an `.elapsed_time() -> Period` method added that returns the elapsed time since start of simulation.
8597

0 commit comments

Comments
 (0)