Skip to content

Allow construct CustomFormat outside the crate #1638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions gix-date/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ pub enum Sign {
/// Various ways to describe a time format.
#[derive(Debug, Clone, Copy)]
pub enum Format {
/// A custom format limited to what's in the
/// [`format`](mod@crate::time::format) submodule.
/// A custom format limited to what's in the [`format`](mod@format) submodule.
Custom(CustomFormat),
/// The seconds since 1970, also known as unix epoch, like `1660874655`.
Unix,
Expand All @@ -33,6 +32,13 @@ pub enum Format {
#[derive(Clone, Copy, Debug)]
pub struct CustomFormat(pub(crate) &'static str);

impl CustomFormat {
/// Create a new custom `format` suitable for use with the [`jiff`] crate.
pub const fn new(format: &'static str) -> Self {
Self(format)
}
}

impl From<CustomFormat> for Format {
fn from(custom_format: CustomFormat) -> Format {
Format::Custom(custom_format)
Expand Down
Loading