-
Notifications
You must be signed in to change notification settings - Fork 533
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
Flexible offset formatting [1/3] #1082
Conversation
10e49a9
to
df6a2d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
df6a2d0
to
492c83c
Compare
src/format/mod.rs
Outdated
} else { | ||
locale.am_pm[0] | ||
}); | ||
let ret = match *spec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in a separate commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it easier for you to see what is changed, and what is caused by rustfmt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is old code that was previously not formatted? What changed that rustfmt is now formatting it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some experiments at the time, but couldn't pin it down. In #1126 (comment) I run into the same issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to file a rustfmt issue?
e687926
to
d27793b
Compare
f84e948
to
fd0f41b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, please fix up these final nits (unless you disagree) and feel free to merge.
src/format/formatting.rs
Outdated
@@ -23,6 +23,8 @@ use crate::{Datelike, Timelike, Weekday}; | |||
#[cfg(feature = "unstable-locales")] | |||
use super::locales; | |||
#[cfg(any(feature = "alloc", feature = "std"))] | |||
use super::{Colons, OffsetFormat, OffsetPrecision}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can merge these imports, right?
src/format/formatting.rs
Outdated
off.map(|&(_, off)| write_local_minus_utc(result, off, true, Colons::None)) | ||
} | ||
TimezoneOffset | TimezoneOffsetZ => off.map(|&(_, off)| { | ||
let allow_zulu = *spec == TimezoneOffsetZ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer inlining this value in the OffsetFormat::new()
call.
src/format/formatting.rs
Outdated
.format(result, off) | ||
}), | ||
TimezoneOffsetColon | TimezoneOffsetColonZ => off.map(|&(_, off)| { | ||
let allow_zulu = *spec == TimezoneOffsetColonZ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
src/format/mod.rs
Outdated
|
||
impl OffsetFormat { | ||
/// Create a new `OffsetFormat`. | ||
pub const fn new( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the new()
calls will still be spread over the same number of lines in practice, I feel like this method isn't really buying us anything, whereas having the field names in the initializer would make the code a little easier to understand (particularly for the allow_zulu
field).
src/format/mod.rs
Outdated
pub struct OffsetFormat { | ||
/// See `OffsetPrecision`. | ||
pub precision: OffsetPrecision, | ||
/// Seperator between hours, minutes and seconds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more instance of sepe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for being thorough, I thought I had them all.
fd0f41b
to
2cce338
Compare
2cce338
to
edf413d
Compare
There are a lot of issues with our current code to parse time zone offsets. For example
%z
,%:z
,%::z
and%:::z
are all treated identical in the parser. In some casesZ
is accepted, and there is a hack to acceptUTC
. There is no way to parse seconds.Formatting is in a better state, but it would be nice if it could be more flexible. For example to be able to print seconds optionally, support padding, or print
Z
.This is part 1 of a series of PRs to improve offset formatting and parsing. (1) adds a flexible formatter, (2) adds a flexible parser and fixes current parsing bugs, and (3) exposes the functionality in the format string.
With this PR it is now possible to specify the format of an offset:
Z
used for+00:00
?