pub struct StrPTimeFmt { /* private fields */ }Expand description
A pre-validated, reusable date/time format string.
- Format is validated once at construction (
newreturnsResult). - Format bytes are copied into an owned fixed-size buffer.
- Only ASCII formats are accepted.
§See also
Implementations§
Source§impl StrPTimeFmt
impl StrPTimeFmt
pub const MAX_FORMAT_LEN: usize = 256
Sourcepub fn new(fmt: &str) -> Result<Self, DtErr>
pub fn new(fmt: &str) -> Result<Self, DtErr>
Creates a new validated format.
- Validates syntax and supported directives.
- Requires the format to be valid ASCII and ≤ 256 bytes.
- Returns a
DtErron any failure.
§Examples
use deep_time::{Dt, StrPTimeFmt};
let fmt = Dt::parse_fmt("%F %T").unwrap();
// parse a datetime
let dt = fmt.to_dt("2025-05-23 14:30:00", false, false, false).unwrap();
// change a datetimes format
let s = fmt.to_str("2000-01-01 12:00:00", "%d %m %Y %H:%M:%S", false, false, false).unwrap();Sourcepub fn to_dt(
&self,
s: &str,
inp_can_end_before_fmt: bool,
fmt_can_end_before_inp: bool,
allow_partial_date: bool,
) -> Result<Dt, DtErr>
pub fn to_dt( &self, s: &str, inp_can_end_before_fmt: bool, fmt_can_end_before_inp: bool, allow_partial_date: bool, ) -> Result<Dt, DtErr>
Parses a date/time string using this pre-validated format.
The four boolean flags control lenient parsing behavior — see
Dt::from_str for full documentation.
§Parameters
s: The input string to parse.inp_can_end_before_fmt: Allow input to end before format is fully consumed.fmt_can_end_before_inp: Allow format to end before input is fully consumed.allow_partial_date: Default missing month/day to1instead of erroring.
§Errors
Returns DtErr for parse failures, incomplete data, trailing characters, etc.
§Example
use deep_time::{Dt, StrPTimeFmt};
let fmt = Dt::parse_fmt("%F %T").unwrap();
let dt = fmt.to_dt("2025-05-23 14:30:00", false, false, false).unwrap();Sourcepub fn to_str(
&self,
s: &str,
output_fmt: &str,
inp_can_end_before_fmt: bool,
fmt_can_end_before_inp: bool,
allow_partial_date: bool,
) -> Result<String, DtErr>
pub fn to_str( &self, s: &str, output_fmt: &str, inp_can_end_before_fmt: bool, fmt_can_end_before_inp: bool, allow_partial_date: bool, ) -> Result<String, DtErr>
Formats a Dt into a string using this pre-validated format and a given
output format.
Effectively parses a [str] with the contained format, then outputs a
String to a new given format.
Requires the alloc feature.
§Parameters
s: datetime input [str].output_fmt: The new format to output the datetime as.- The remaining three flags are passed through to the internal
to_dtcall.
§Example
use deep_time::{Dt, StrPTimeFmt};
let fmt = Dt::parse_fmt("%Y-%m-%dT%H:%M:%S").unwrap();
let s = fmt.to_str("2000-01-01T12:00:00", "%d %m %Y %H:%M:%S", false, false, false).unwrap();Trait Implementations§
Source§impl Clone for StrPTimeFmt
impl Clone for StrPTimeFmt
Source§fn clone(&self) -> StrPTimeFmt
fn clone(&self) -> StrPTimeFmt
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StrPTimeFmt
impl Debug for StrPTimeFmt
impl Copy for StrPTimeFmt
Auto Trait Implementations§
impl Freeze for StrPTimeFmt
impl RefUnwindSafe for StrPTimeFmt
impl Send for StrPTimeFmt
impl Sync for StrPTimeFmt
impl Unpin for StrPTimeFmt
impl UnsafeUnpin for StrPTimeFmt
impl UnwindSafe for StrPTimeFmt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more