BurntSushi / jiff

A date-time library for Rust that encourages you to jump into the pit of success.
The Unlicense
1.77k stars 35 forks source link

fmt: support formatting `Timestamp` with a specific offset #122

Closed BurntSushi closed 2 months ago

BurntSushi commented 2 months ago

This PR does a couple things.

First, it adds a new jiff::fmt::DateTimePrinter::print_timestamp_with_offset routine for formatting a jiff::Timestamp as an RFC 3339 string with a specific offset. In particular, this draws a contrast between the existing print_timestamp method which will always use Zulu time. (Zulu is UTC, but where the offset is unknown.)

Secondly, we add new helper methods on the datetime and span printers to format datetimes and spans directly into a string. This is just for convenience, since otherwise creating a String and passing it in as a buffer can be a bit annoying. Also, since it's fixed to a String, these methods are infallible and can never fail, which further simplifies their use.