-
Notifications
You must be signed in to change notification settings - Fork 546
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
Format to string #1121
Format to string #1121
Conversation
c8b2b3f
to
8bfcf98
Compare
Just noticed that we should definitely turn formatting with |
Hmm, this is not a complete solution, see #902 (comment). Still I think
I'll rework this PR a bit. |
5b0f2de
to
2d599f1
Compare
@jtmoon79 You may be interested in this CI failure https://github.com/chronotope/chrono/actions/runs/5169010209/jobs/9310999690?pr=1121 |
Ah nice, the bash error mode The In this case, I suggest re-running the failed CI job. |
2d599f1
to
22b2b78
Compare
Wrote up my thoughts in #1127. |
This PR is meant as an alternative to #902 and #614, for the problem in described in #575.
The problem is that if the format string is invalid, or contains a field that the type can not provide (such as time fields on a
NaiveDate
), the display implementation returns an error.Some formattings macro's can correctly forward this error, such as
write!
andwriteln!
. Others, such asprintln!
,format!
andto_string
panic instead.StrftimeItems::new
return aResult
. It will need some more work to detect a string with fields the type can not provide.fmt::Result<String>
.Compared to #902 I believe this solution is better because:
String
, instead of making it slightly harder to get aDelayedFormat
.There are 5 new methods, all just a couple of lines of code:
DelayedFormat::try_to_string
NaiveDate::format_to_string
NaiveTime::format_to_string
NaiveDateTime::format_to_string
DateTime::format_to_string
Most of the effort in this PR is updating the surrounding documentation and examples, to make users more aware of the potential panic and the solutions.