Sebastian Thielthanks clipppyb139d704 years agoHistory
27 lines · 974 B · Rust
RawDownload
use crate::Time;use time::format_description::FormatItem;use time::formatting::Formattable;use time::macros::format_description; /// E.g. `2018-12-24`pub const SHORT: &[FormatItem<'_>] = format_description!("[year]-[month]-[day]"); /// Formattingimpl Time {    /// Format this instance according to the given `format`.    ///    /// Use the [`format_description`] macro to create and validate formats at compile time, courtesy of the [`time`] crate.    pub fn format(&self, format: &(impl Formattable + ?Sized)) -> String {        self.to_time()            .format(&format)            .expect("well-known format into memory never fails")    }} impl Time {    fn to_time(self) -> time::OffsetDateTime {        time::OffsetDateTime::from_unix_timestamp(self.seconds_since_unix_epoch as i64)            .expect("always valid unix time")            .replace_offset(time::UtcOffset::from_whole_seconds(self.offset_in_seconds).expect("valid offset"))    }}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t