Skip to content

Commit

Permalink
Rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jun 29, 2023
1 parent d921276 commit d27793b
Showing 1 changed file with 129 additions and 131 deletions.
260 changes: 129 additions & 131 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,144 +710,142 @@ 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 => {
let format = OffsetFormat {
precision: OffsetPrecision::Minutes,
colons: Colon::Maybe,
allow_zulu: *spec == TimezoneOffsetZ,
padding: Pad::Zero,
};
off.map(|&(_, off)| format.format(result, off))
}
TimezoneOffsetColon | TimezoneOffsetColonZ => {
let format = OffsetFormat {
precision: OffsetPrecision::Minutes,
colons: Colon::Colon,
allow_zulu: *spec == TimezoneOffsetColonZ,
padding: Pad::Zero,
};
off.map(|&(_, off)| format.format(result, off))
}
TimezoneOffsetDoubleColon => {
let format = OffsetFormat {
precision: OffsetPrecision::Seconds,
colons: Colon::Colon,
allow_zulu: false,
padding: Pad::Zero,
};
off.map(|&(_, off)| format.format(result, off))
}
TimezoneOffsetTripleColon => {
let format = OffsetFormat {
precision: OffsetPrecision::Hours,
colons: Colon::None,
allow_zulu: false,
padding: Pad::Zero,
};
off.map(|&(_, off)| format.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
}
}),
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 => {
let format = OffsetFormat {
precision: OffsetPrecision::Minutes,
colons: Colon::Maybe,
allow_zulu: *spec == TimezoneOffsetZ,
padding: Pad::Zero,
};
off.map(|&(_, off)| format.format(result, off))
}
TimezoneOffsetColon | TimezoneOffsetColonZ => {
let format = OffsetFormat {
precision: OffsetPrecision::Minutes,
colons: Colon::Colon,
allow_zulu: *spec == TimezoneOffsetColonZ,
padding: Pad::Zero,
};
off.map(|&(_, off)| format.format(result, off))
}
TimezoneOffsetDoubleColon => {
let format = OffsetFormat {
precision: OffsetPrecision::Seconds,
colons: Colon::Colon,
allow_zulu: false,
padding: Pad::Zero,
};
off.map(|&(_, off)| format.format(result, off))
}
TimezoneOffsetTripleColon => {
let format = OffsetFormat {
precision: OffsetPrecision::Hours,
colons: Colon::None,
allow_zulu: false,
padding: Pad::Zero,
};
off.map(|&(_, off)| format.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
}
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 d27793b

Please sign in to comment.