-
-
Notifications
You must be signed in to change notification settings - Fork 281
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
Permit skipping [optional]
values when formatting
#708
Comments
Can you share some code? I'm not certain what you're referring to. |
#[test]
fn test_format() {
let format =
time::macros::format_description!(version = 2, "[year]-[month]-[optional [[day]]]");
// let mut format = format_description!(version = 2, "[year]-[month]-[optional format:false [[day]]]");
// format.format_optional(false)
let date = time::Date::from_calendar_date(2024, time::Month::April, 1).unwrap();
let str = date.format(format).unwrap(); // --> format to "2024-04-"
// assert_eq!(str,"2024-04-");
println!("{:?}", str)
} |
Why is this needed? Generally you should be providing as much information as possible when formatting, only inferring when parsing if absolutely necessary. The description in documentation matches this:
|
Format it into a simpler form when supporting more formats pub const FORMAT: &[time::format_description::BorrowedFormatItem] = time::macros::format_description!(
version = 2,
"[year]-[month]-[day][first [ ] [T]][hour]:[minute]:[second][optional [[first [[end]] [.[subsecond digits:1+]]]]][optional [[first [[end]] [[offset_hour]:[offset_minute][optional [:[offset_second]]]]]]]"
);
Just like this, if I want to format the time zone without formatting milliseconds, I can't do it |
Unfortunately the |
optional
for formatting[optional]
values when formatting
How to format
optional
as emptyThe text was updated successfully, but these errors were encountered: