Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- run: cargo test --doc --all-features --color=always -- --color=always

# later this may be able to be included with the below
# kept seperate for now as the following don't compile on 1.38.0
# kept seperate for now as the following don't compile on 1.47.0
# * rkyv
# * criterion
rust_msrv:
Expand All @@ -49,7 +49,7 @@ jobs:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.38.0
toolchain: 1.47.0
- uses: Swatinem/rust-cache@v1
# run --lib and --doc to avoid the long running integration tests which are run elsewhere
- run: cargo test --lib --features unstable-locales,wasmbind,clock,serde,winapi --color=always -- --color=always
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales", "alloc"]
__internal_bench = ["criterion"]
__doctest = []
const-validation = []

[dependencies]
num-integer = { version = "0.1.36", default-features = false }
serde = { version = "1.0.99", default-features = false, optional = true }
pure-rust-locales = { version = "0.5.2", optional = true }
criterion = { version = "0.4.0", optional = true }
Expand Down
12 changes: 6 additions & 6 deletions benches/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ fn bench_datetime_to_rfc3339(c: &mut Criterion) {
fn bench_year_flags_from_year(c: &mut Criterion) {
c.bench_function("bench_year_flags_from_year", |b| {
b.iter(|| {
for year in -999i32..1000 {
__BenchYearFlags::from_year(year);
for year in -999i16..1000 {
__BenchYearFlags::calculate_from_year(year);
}
})
});
Expand All @@ -67,15 +67,15 @@ fn bench_year_flags_from_year(c: &mut Criterion) {
/// # Panics
///
/// Panics if `div` is not positive.
fn in_between(start: i32, end: i32, div: i32) -> i32 {
fn in_between(start: i16, end: i16, div: i16) -> i32 {
assert!(div > 0, "in_between: nonpositive div = {}", div);
let start = (start.div_euclid(div), start.rem_euclid(div));
let end = (end.div_euclid(div), end.rem_euclid(div));
// The lowest multiple of `div` greater than or equal to `start`, divided.
let start = start.0 + (start.1 != 0) as i32;
let start = start.0 + (start.1 != 0) as i16;
// The lowest multiple of `div` greater than or equal to `end`, divided.
let end = end.0 + (end.1 != 0) as i32;
end - start
let end = end.0 + (end.1 != 0) as i16;
i32::from(end - start)
}

/// Alternative implementation to `Datelike::num_days_from_ce`
Expand Down
4 changes: 2 additions & 2 deletions ci/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ meaningful in the github actions feature matrix UI.

runv cargo --version

if [[ ${RUST_VERSION:-} != 1.38.0 ]]; then
if [[ ${RUST_VERSION:-} != 1.47.0 ]]; then
if [[ ${WASM:-} == yes_wasm ]]; then
test_wasm
elif [[ ${WASM:-} == wasm_simple ]]; then
Expand All @@ -51,7 +51,7 @@ meaningful in the github actions feature matrix UI.
else
test_regular UTC0
fi
elif [[ ${RUST_VERSION:-} == 1.38.0 ]]; then
elif [[ ${RUST_VERSION:-} == 1.47.0 ]]; then
test_132
else
echo "ERROR: didn't run any tests"
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.38"
msrv = "1.47"
35 changes: 20 additions & 15 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,74 +387,79 @@ where

impl<Tz: TimeZone> Datelike for Date<Tz> {
#[inline]
fn year(&self) -> i32 {
fn num_days_from_ce(&self) -> i32 {
self.date.num_days_from_ce()
}

#[inline]
fn year(&self) -> i16 {
self.naive_local().year()
}
#[inline]
fn month(&self) -> u32 {
fn month(&self) -> u8 {
self.naive_local().month()
}
#[inline]
fn month0(&self) -> u32 {
fn month0(&self) -> u8 {
self.naive_local().month0()
}
#[inline]
fn day(&self) -> u32 {
fn day(&self) -> u8 {
self.naive_local().day()
}
#[inline]
fn day0(&self) -> u32 {
fn day0(&self) -> u8 {
self.naive_local().day0()
}
#[inline]
fn ordinal(&self) -> u32 {
fn ordinal(&self) -> u16 {
self.naive_local().ordinal()
}
#[inline]
fn ordinal0(&self) -> u32 {
fn ordinal0(&self) -> u16 {
self.naive_local().ordinal0()
}
#[inline]
fn weekday(&self) -> Weekday {
self.naive_local().weekday()
}
#[inline]
fn iso_week(&self) -> IsoWeek {
fn iso_week(&self) -> Option<IsoWeek> {
self.naive_local().iso_week()
}

#[inline]
fn with_year(&self, year: i32) -> Option<Date<Tz>> {
fn with_year(&self, year: i16) -> Option<Date<Tz>> {
map_local(self, |date| date.with_year(year))
}

#[inline]
fn with_month(&self, month: u32) -> Option<Date<Tz>> {
fn with_month(&self, month: u8) -> Option<Date<Tz>> {
map_local(self, |date| date.with_month(month))
}

#[inline]
fn with_month0(&self, month0: u32) -> Option<Date<Tz>> {
fn with_month0(&self, month0: u8) -> Option<Date<Tz>> {
map_local(self, |date| date.with_month0(month0))
}

#[inline]
fn with_day(&self, day: u32) -> Option<Date<Tz>> {
fn with_day(&self, day: u8) -> Option<Date<Tz>> {
map_local(self, |date| date.with_day(day))
}

#[inline]
fn with_day0(&self, day0: u32) -> Option<Date<Tz>> {
fn with_day0(&self, day0: u8) -> Option<Date<Tz>> {
map_local(self, |date| date.with_day0(day0))
}

#[inline]
fn with_ordinal(&self, ordinal: u32) -> Option<Date<Tz>> {
fn with_ordinal(&self, ordinal: u16) -> Option<Date<Tz>> {
map_local(self, |date| date.with_ordinal(ordinal))
}

#[inline]
fn with_ordinal0(&self, ordinal0: u32) -> Option<Date<Tz>> {
fn with_ordinal0(&self, ordinal0: u16) -> Option<Date<Tz>> {
map_local(self, |date| date.with_ordinal0(ordinal0))
}
}
Expand Down
34 changes: 19 additions & 15 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,74 +810,78 @@ where

impl<Tz: TimeZone> Datelike for DateTime<Tz> {
#[inline]
fn year(&self) -> i32 {
fn num_days_from_ce(&self) -> i32 {
self.naive_local().date().num_days_from_ce()
}
#[inline]
fn year(&self) -> i16 {
self.naive_local().year()
}
#[inline]
fn month(&self) -> u32 {
fn month(&self) -> u8 {
self.naive_local().month()
}
#[inline]
fn month0(&self) -> u32 {
fn month0(&self) -> u8 {
self.naive_local().month0()
}
#[inline]
fn day(&self) -> u32 {
fn day(&self) -> u8 {
self.naive_local().day()
}
#[inline]
fn day0(&self) -> u32 {
fn day0(&self) -> u8 {
self.naive_local().day0()
}
#[inline]
fn ordinal(&self) -> u32 {
fn ordinal(&self) -> u16 {
self.naive_local().ordinal()
}
#[inline]
fn ordinal0(&self) -> u32 {
fn ordinal0(&self) -> u16 {
self.naive_local().ordinal0()
}
#[inline]
fn weekday(&self) -> Weekday {
self.naive_local().weekday()
}
#[inline]
fn iso_week(&self) -> IsoWeek {
fn iso_week(&self) -> Option<IsoWeek> {
self.naive_local().iso_week()
}

#[inline]
fn with_year(&self, year: i32) -> Option<DateTime<Tz>> {
fn with_year(&self, year: i16) -> Option<DateTime<Tz>> {
map_local(self, |datetime| datetime.with_year(year))
}

#[inline]
fn with_month(&self, month: u32) -> Option<DateTime<Tz>> {
fn with_month(&self, month: u8) -> Option<DateTime<Tz>> {
map_local(self, |datetime| datetime.with_month(month))
}

#[inline]
fn with_month0(&self, month0: u32) -> Option<DateTime<Tz>> {
fn with_month0(&self, month0: u8) -> Option<DateTime<Tz>> {
map_local(self, |datetime| datetime.with_month0(month0))
}

#[inline]
fn with_day(&self, day: u32) -> Option<DateTime<Tz>> {
fn with_day(&self, day: u8) -> Option<DateTime<Tz>> {
map_local(self, |datetime| datetime.with_day(day))
}

#[inline]
fn with_day0(&self, day0: u32) -> Option<DateTime<Tz>> {
fn with_day0(&self, day0: u8) -> Option<DateTime<Tz>> {
map_local(self, |datetime| datetime.with_day0(day0))
}

#[inline]
fn with_ordinal(&self, ordinal: u32) -> Option<DateTime<Tz>> {
fn with_ordinal(&self, ordinal: u16) -> Option<DateTime<Tz>> {
map_local(self, |datetime| datetime.with_ordinal(ordinal))
}

#[inline]
fn with_ordinal0(&self, ordinal0: u32) -> Option<DateTime<Tz>> {
fn with_ordinal0(&self, ordinal0: u16) -> Option<DateTime<Tz>> {
map_local(self, |datetime| datetime.with_ordinal0(ordinal0))
}
}
Expand Down
55 changes: 35 additions & 20 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ impl ParseError {

/// The category of parse error
#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash)]
#[allow(clippy::manual_non_exhaustive)]
pub enum ParseErrorKind {
/// Given field is out of permitted range.
OutOfRange,
Expand Down Expand Up @@ -488,8 +489,8 @@ fn format_inner<'a>(
)
};

use crate::naive::internals::{const_div_floor_i64, const_mod_floor_i64};
use core::fmt::Write;
use num_integer::{div_floor, mod_floor};

match *item {
Item::Literal(s) | Item::Space(s) => result.push_str(s),
Expand All @@ -508,16 +509,34 @@ fn format_inner<'a>(

let (width, v) = match *spec {
Year => (4, date.map(|d| i64::from(d.year()))),
YearDiv100 => (2, date.map(|d| div_floor(i64::from(d.year()), 100))),
YearMod100 => (2, date.map(|d| mod_floor(i64::from(d.year()), 100))),
IsoYear => (4, date.map(|d| i64::from(d.iso_week().year()))),
IsoYearDiv100 => (2, date.map(|d| div_floor(i64::from(d.iso_week().year()), 100))),
IsoYearMod100 => (2, date.map(|d| mod_floor(i64::from(d.iso_week().year()), 100))),
YearDiv100 => (2, date.map(|d| const_div_floor_i64(i64::from(d.year()), 100))),
YearMod100 => (2, date.map(|d| const_mod_floor_i64(i64::from(d.year()), 100))),
IsoYear => (
4,
date.map(|d| d.iso_week().map(|w| i64::from(w.year()))).ok_or(fmt::Error)?,
),
IsoYearDiv100 => (
2,
date.map(|d| {
d.iso_week().map(|w| const_div_floor_i64(i64::from(w.year()), 100))
})
.ok_or(fmt::Error)?,
),
IsoYearMod100 => (
2,
date.map(|d| {
d.iso_week().map(|w| const_mod_floor_i64(i64::from(w.year()), 100))
})
.ok_or(fmt::Error)?,
),
Month => (2, date.map(|d| i64::from(d.month()))),
Day => (2, date.map(|d| i64::from(d.day()))),
WeekFromSun => (2, date.map(|d| i64::from(week_from_sun(d)))),
WeekFromMon => (2, date.map(|d| i64::from(week_from_mon(d)))),
IsoWeek => (2, date.map(|d| i64::from(d.iso_week().week()))),
IsoWeek => (
2,
date.map(|d| d.iso_week().map(|w| i64::from(w.week()))).ok_or(fmt::Error)?,
),
NumDaysFromSun => (1, date.map(|d| i64::from(d.weekday().num_days_from_sunday()))),
WeekdayFromMon => (1, date.map(|d| i64::from(d.weekday().number_from_monday()))),
Ordinal => (3, date.map(|d| i64::from(d.ordinal()))),
Expand Down Expand Up @@ -583,19 +602,15 @@ fn format_inner<'a>(
Colons::Single => {
write!(result, "{}{:02}:{:02}", sign, off / 3600, off / 60 % 60)
}
Colons::Double => {
write!(
result,
"{}{:02}:{:02}:{:02}",
sign,
off / 3600,
off / 60 % 60,
off % 60
)
}
Colons::Triple => {
write!(result, "{}{:02}", sign, off / 3600)
}
Colons::Double => write!(
result,
"{}{:02}:{:02}:{:02}",
sign,
off / 3600,
off / 60 % 60,
off % 60
),
Colons::Triple => write!(result, "{}{:02}", sign, off / 3600),
}
} else {
result.push('Z');
Expand Down
8 changes: 4 additions & 4 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,10 @@ fn test_parse() {
check!("+42", [num!(Year)]; year: 42);
check!("-0042", [num!(Year)]; year: -42);
check!("+0042", [num!(Year)]; year: 42);
check!("-42195", [num!(Year)]; year: -42195);
check!("+42195", [num!(Year)]; year: 42195);
check!(" -42195", [num!(Year)]; year: -42195);
check!(" +42195", [num!(Year)]; year: 42195);
check!("-32765", [num!(Year)]; year: -32765);
check!("+32765", [num!(Year)]; year: 32765);
check!(" -32765", [num!(Year)]; year: -32765);
check!(" +32765", [num!(Year)]; year: 32765);
check!(" - 42", [num!(Year)]; INVALID);
check!(" + 42", [num!(Year)]; INVALID);
check!("-", [num!(Year)]; TOO_SHORT);
Expand Down
Loading