-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
48 deletions.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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]"); | ||
|
||
/// Formatting | ||
impl 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")) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -22,6 +22,8 @@ pub enum Sign { | |
Minus, | ||
} | ||
|
||
/// | ||
pub mod format; | ||
mod init; | ||
mod write; | ||
|
||
|
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
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
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