Skip to content

Commit

Permalink
Rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jun 30, 2023
1 parent 89c10b2 commit fd0f41b
Showing 1 changed file with 120 additions and 122 deletions.
242 changes: 120 additions & 122 deletions src/format/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,136 +350,134 @@ fn format_inner(
Item::Fixed(ref spec) => {
use self::Fixed::*;

let ret =
match *spec {
ShortMonthName => date.map(|d| {
result.push_str(locale.short_months[d.month0() as usize]);
Ok(())
}),
LongMonthName => date.map(|d| {
result.push_str(locale.long_months[d.month0() as usize]);
Ok(())
}),
ShortWeekdayName => date.map(|d| {
result.push_str(
locale.short_weekdays[d.weekday().num_days_from_sunday() as usize],
);
Ok(())
}),
LongWeekdayName => date.map(|d| {
result.push_str(
locale.long_weekdays[d.weekday().num_days_from_sunday() as usize],
);
Ok(())
}),
LowerAmPm => time.map(|t| {
let ampm = if t.hour12().0 { locale.am_pm[1] } else { locale.am_pm[0] };
for char in ampm.chars() {
result.extend(char.to_lowercase())
}
Ok(())
}),
UpperAmPm => time.map(|t| {
result.push_str(if t.hour12().0 {
locale.am_pm[1]
} else {
locale.am_pm[0]
});
let ret = match *spec {
ShortMonthName => date.map(|d| {
result.push_str(locale.short_months[d.month0() as usize]);
Ok(())
}),
LongMonthName => date.map(|d| {
result.push_str(locale.long_months[d.month0() as usize]);
Ok(())
}),
ShortWeekdayName => date.map(|d| {
result.push_str(
locale.short_weekdays[d.weekday().num_days_from_sunday() as usize],
);
Ok(())
}),
LongWeekdayName => date.map(|d| {
result.push_str(
locale.long_weekdays[d.weekday().num_days_from_sunday() as usize],
);
Ok(())
}),
LowerAmPm => time.map(|t| {
let ampm = if t.hour12().0 { locale.am_pm[1] } else { locale.am_pm[0] };
for char in ampm.chars() {
result.extend(char.to_lowercase())
}
Ok(())
}),
UpperAmPm => time.map(|t| {
result.push_str(if t.hour12().0 { locale.am_pm[1] } else { locale.am_pm[0] });
Ok(())
}),
Nanosecond => time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
if nano == 0 {
Ok(())
}),
Nanosecond => time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
if nano == 0 {
Ok(())
} else if nano % 1_000_000 == 0 {
write!(result, ".{:03}", nano / 1_000_000)
} else if nano % 1_000 == 0 {
write!(result, ".{:06}", nano / 1_000)
} else {
write!(result, ".{:09}", nano)
}
}),
Nanosecond3 => time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
} else if nano % 1_000_000 == 0 {
write!(result, ".{:03}", nano / 1_000_000)
}),
Nanosecond6 => time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
} else if nano % 1_000 == 0 {
write!(result, ".{:06}", nano / 1_000)
}),
Nanosecond9 => time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
} else {
write!(result, ".{:09}", nano)
}),
Internal(InternalFixed { val: InternalInternal::Nanosecond3NoDot }) => time
.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
write!(result, "{:03}", nano / 1_000_000)
}),
Internal(InternalFixed { val: InternalInternal::Nanosecond6NoDot }) => time
.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
write!(result, "{:06}", nano / 1_000)
}),
Internal(InternalFixed { val: InternalInternal::Nanosecond9NoDot }) => time
.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
write!(result, "{:09}", nano)
}),
TimezoneName => off.map(|(name, _)| {
result.push_str(name);
Ok(())
}),
TimezoneOffset | TimezoneOffsetZ => off.map(|&(_, off)| {
let allow_zulu = *spec == TimezoneOffsetZ;
OffsetFormat::new(
OffsetPrecision::Minutes,
Colons::Maybe,
allow_zulu,
Pad::Zero
)
}
}),
Nanosecond3 => time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
write!(result, ".{:03}", nano / 1_000_000)
}),
Nanosecond6 => time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
write!(result, ".{:06}", nano / 1_000)
}),
Nanosecond9 => time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
write!(result, ".{:09}", nano)
}),
Internal(InternalFixed { val: InternalInternal::Nanosecond3NoDot }) => {
time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
write!(result, "{:03}", nano / 1_000_000)
})
}
Internal(InternalFixed { val: InternalInternal::Nanosecond6NoDot }) => {
time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
write!(result, "{:06}", nano / 1_000)
})
}
Internal(InternalFixed { val: InternalInternal::Nanosecond9NoDot }) => {
time.map(|t| {
let nano = t.nanosecond() % 1_000_000_000;
write!(result, "{:09}", nano)
})
}
TimezoneName => off.map(|(name, _)| {
result.push_str(name);
Ok(())
}),
TimezoneOffset | TimezoneOffsetZ => off.map(|&(_, off)| {
let allow_zulu = *spec == TimezoneOffsetZ;
OffsetFormat::new(
OffsetPrecision::Minutes,
Colons::Maybe,
allow_zulu,
Pad::Zero,
)
.format(result, off)
}),
TimezoneOffsetColon | TimezoneOffsetColonZ => off.map(|&(_, off)| {
let allow_zulu = *spec == TimezoneOffsetColonZ;
OffsetFormat::new(
OffsetPrecision::Minutes,
Colons::Colon,
allow_zulu,
Pad::Zero,
)
.format(result, off)
}),
TimezoneOffsetDoubleColon => off.map(|&(_, off)| {
OffsetFormat::new(OffsetPrecision::Seconds, Colons::Colon, false, Pad::Zero)
.format(result, off)
}),
TimezoneOffsetColon | TimezoneOffsetColonZ => off.map(|&(_, off)| {
let allow_zulu = *spec == TimezoneOffsetColonZ;
OffsetFormat::new(
OffsetPrecision::Minutes,
Colons::Colon,
allow_zulu,
Pad::Zero,
)
}),
TimezoneOffsetTripleColon => off.map(|&(_, off)| {
OffsetFormat::new(OffsetPrecision::Hours, Colons::None, false, Pad::Zero)
.format(result, off)
}),
TimezoneOffsetDoubleColon => off.map(|&(_, off)| {
OffsetFormat::new(OffsetPrecision::Seconds, Colons::Colon, false, Pad::Zero)
.format(result, off)
}),
TimezoneOffsetTripleColon => off.map(|&(_, off)| {
OffsetFormat::new(OffsetPrecision::Hours, Colons::None, false, Pad::Zero)
.format(result, off)
}),
Internal(InternalFixed { val: InternalInternal::TimezoneOffsetPermissive }) => {
return Err(fmt::Error);
}
RFC2822 =>
// same as `%a, %d %b %Y %H:%M:%S %z`
{
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
Some(write_rfc2822_inner(result, d, t, off, locale))
} else {
None
}
}),
Internal(InternalFixed { val: InternalInternal::TimezoneOffsetPermissive }) => {
return Err(fmt::Error);
}
RFC2822 =>
// same as `%a, %d %b %Y %H:%M:%S %z`
{
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
Some(write_rfc2822_inner(result, d, t, off, locale))
} else {
None
}
RFC3339 =>
// same as `%Y-%m-%dT%H:%M:%S%.f%:z`
{
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
Some(write_rfc3339(result, crate::NaiveDateTime::new(*d, *t), off))
} else {
None
}
}
RFC3339 =>
// same as `%Y-%m-%dT%H:%M:%S%.f%:z`
{
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
Some(write_rfc3339(result, crate::NaiveDateTime::new(*d, *t), off))
} else {
None
}
};
}
};

match ret {
Some(ret) => ret?,
Expand Down

0 comments on commit fd0f41b

Please sign in to comment.