Skip to content

Commit

Permalink
Merge branch '0.4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jul 7, 2023
2 parents 088b693 + 56c6967 commit ac7d7dd
Show file tree
Hide file tree
Showing 37 changed files with 4,165 additions and 3,110 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --check -- --color=always
- run: cargo fmt --check --manifest-path fuzz/Cargo.toml
- run: cargo clippy --color=always -- -D warnings
- run: |
cargo clippy --color=always --target x86_64-pc-windows-msvc \
cargo clippy --all-features --all-targets --color=always \
-- -D warnings
- run: |
cargo clippy --manifest-path fuzz/Cargo.toml --color=always \
-- -D warnings
env:
RUSTFLAGS: "-Dwarnings"
toml:
runs-on: ubuntu-latest
container:
image: tamasfe/taplo:0.8.0
steps:
- run: taplo lint
- run: taplo fmt --check --diff

cargo-deny:
runs-on: ubuntu-latest
steps:
Expand Down
26 changes: 8 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ jobs:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --lib --all-features --color=always -- --color=always
- run: cargo test --doc --all-features --color=always -- --color=always
- run: cargo test --all-features --color=always -- --color=always

# later this may be able to be included with the below
# kept separate for now as the following don't compile on 1.56.1
Expand Down Expand Up @@ -94,8 +93,7 @@ jobs:
# run using `bash` on all platforms for consistent
# line-continuation marks
shell: bash
- run: cargo test --lib --no-default-features
- run: cargo test --doc --no-default-features
- run: cargo test --no-default-features

no_std:
strategy:
Expand All @@ -118,7 +116,6 @@ jobs:
os: [ubuntu-latest]
target:
[
wasm32-unknown-unknown,
wasm32-wasi,
wasm32-unknown-emscripten,
aarch64-apple-ios,
Expand All @@ -131,19 +128,11 @@ jobs:
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-node@v3
with:
node-version: "12"
- run: |
set -euxo pipefail
export RUST_BACKTRACE=1
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf \
| bash --noprofile --norc
wasm-pack --version
shell: bash
- run: cargo build --target ${{ matrix.target }} --color=always

features_check_wasm:
test_wasm:
strategy:
matrix:
os: [ubuntu-latest]
Expand All @@ -155,10 +144,11 @@ jobs:
targets: wasm32-unknown-unknown
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
- run: |
cargo hack check --feature-powerset --optional-deps serde,rkyv \
--skip default --skip __internal_bench --skip __doctest \
--skip iana-time-zone --skip pure-rust-locales
- uses: actions/setup-node@v3
- uses: jetli/[email protected]
# The `TZ` and `NOW` variables are used to compare the results inside the WASM environment
# with the host system.
- run: TZ="$(date +%z)" NOW="$(date +%s)" wasm-pack test --node -- --features wasmbind

cross-targets:
strategy:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ __doctest = []

[dependencies]
serde = { version = "1.0.99", default-features = false, optional = true }
pure-rust-locales = { version = "0.5.2", optional = true }
pure-rust-locales = { version = "0.6", optional = true }
criterion = { version = "0.4.0", optional = true }
rkyv = {version = "0.7", optional = true}
rkyv = { version = "0.7", optional = true }
arbitrary = { version = "1.0.0", features = ["derive"], optional = true }

[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API
js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.48.0", features = ["Win32_System_Time", "Win32_System_SystemInformation", "Win32_Foundation"], optional = true }
Expand Down
64 changes: 64 additions & 0 deletions benches/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};

use chrono::format::StrftimeItems;
use chrono::prelude::*;
#[cfg(feature = "unstable-locales")]
use chrono::Locale;
use chrono::{DateTime, FixedOffset, Local, Utc, __BenchYearFlags};

fn bench_datetime_parse_from_rfc2822(c: &mut Criterion) {
Expand Down Expand Up @@ -122,6 +125,57 @@ fn bench_num_days_from_ce(c: &mut Criterion) {
}
}

fn bench_parse_strftime(c: &mut Criterion) {
c.bench_function("bench_parse_strftime", |b| {
b.iter(|| {
let str = black_box("%a, %d %b %Y %H:%M:%S GMT");
let items = StrftimeItems::new(str);
black_box(items.collect::<Vec<_>>());
})
});
}

#[cfg(feature = "unstable-locales")]
fn bench_parse_strftime_localized(c: &mut Criterion) {
c.bench_function("bench_parse_strftime_localized", |b| {
b.iter(|| {
let str = black_box("%a, %d %b %Y %H:%M:%S GMT");
let items = StrftimeItems::new_with_locale(str, Locale::nl_NL);
black_box(items.collect::<Vec<_>>());
})
});
}

fn bench_format(c: &mut Criterion) {
let dt = Local::now();
c.bench_function("bench_format", |b| b.iter(|| format!("{}", dt.format("%Y-%m-%d %H-%M-%S"))));
}

fn bench_format_with_items(c: &mut Criterion) {
let dt = Local::now();
let items: Vec<_> = StrftimeItems::new("%Y-%m-%d %H-%M-%S").collect();
c.bench_function("bench_format_with_items", |b| {
b.iter(|| format!("{}", dt.format_with_items(items.iter())))
});
}

fn bench_format_manual(c: &mut Criterion) {
let dt = Local::now();
c.bench_function("bench_format_manual", |b| {
b.iter(|| {
format!(
"{}-{:02}-{:02} {:02}:{:02}:{:02}",
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second()
)
})
});
}

criterion_group!(
benches,
bench_datetime_parse_from_rfc2822,
Expand All @@ -132,6 +186,16 @@ criterion_group!(
bench_year_flags_from_year,
bench_num_days_from_ce,
bench_get_local_time,
bench_parse_strftime,
bench_format,
bench_format_with_items,
bench_format_manual,
);

#[cfg(feature = "unstable-locales")]
criterion_group!(unstable_locales, bench_parse_strftime_localized,);

#[cfg(not(feature = "unstable-locales"))]
criterion_main!(benches);
#[cfg(feature = "unstable-locales")]
criterion_main!(benches, unstable_locales);
6 changes: 3 additions & 3 deletions ci/core-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
name = "core-test"
version = "0.1.0"
authors = [
"Kang Seonghoon <[email protected]>",
"Brandon W Maister <[email protected]>",
"Kang Seonghoon <[email protected]>",
"Brandon W Maister <[email protected]>",
]
edition = "2018"

[dependencies]
chrono = { path = "../..", default-features = false, features = ["serde"] }

[features]
alloc = ["chrono/alloc"]
alloc = ["chrono/alloc"]
4 changes: 2 additions & 2 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ copyleft = "deny"

[advisories]
ignore = [
"RUSTSEC-2021-0145", # atty (dev-deps only, dependency of criterion)
"RUSTSEC-2022-0004", # rustc_serialize, cannot remove due to compatibility
"RUSTSEC-2021-0145", # atty (dev-deps only, dependency of criterion)
"RUSTSEC-2022-0004", # rustc_serialize, cannot remove due to compatibility
]
unmaintained = "deny"
unsound = "deny"
Expand Down
12 changes: 5 additions & 7 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! ISO 8601 calendar date with time zone.
#![allow(deprecated)]

#[cfg(any(feature = "alloc", feature = "std", test))]
#[cfg(any(feature = "alloc", feature = "std"))]
use core::borrow::Borrow;
use core::cmp::Ordering;
use core::ops::{Add, AddAssign, Sub, SubAssign};
Expand All @@ -15,7 +15,7 @@ use rkyv::{Archive, Deserialize, Serialize};

#[cfg(feature = "unstable-locales")]
use crate::format::Locale;
#[cfg(any(feature = "alloc", feature = "std", test))]
#[cfg(any(feature = "alloc", feature = "std"))]
use crate::format::{DelayedFormat, Item, StrftimeItems};
use crate::naive::{IsoWeek, NaiveDate, NaiveTime};
use crate::offset::{TimeZone, Utc};
Expand Down Expand Up @@ -74,8 +74,6 @@ pub const MAX_DATE: Date<Utc> = Date::<Utc>::MAX_UTC;
impl<Tz: TimeZone> Date<Tz> {
/// Makes a new `Date` with given *UTC* date and offset.
/// The local date should be constructed via the `TimeZone` trait.
//
// note: this constructor is purposely not named to `new` to discourage the direct usage.
#[inline]
#[must_use]
pub fn from_utc(date: NaiveDate, offset: Tz::Offset) -> Date<Tz> {
Expand All @@ -85,7 +83,7 @@ impl<Tz: TimeZone> Date<Tz> {
/// Makes a new `DateTime` from the current date and given `NaiveTime`.
/// The offset in the current date is preserved.
///
/// Panics on invalid datetime.
/// Returns `None` on invalid datetime.
#[inline]
#[must_use]
pub fn and_time(&self, time: NaiveTime) -> Option<DateTime<Tz>> {
Expand Down Expand Up @@ -335,7 +333,7 @@ where
Tz::Offset: fmt::Display,
{
/// Formats the date with the specified formatting items.
#[cfg(any(feature = "alloc", feature = "std", test))]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
#[inline]
#[must_use]
Expand All @@ -350,7 +348,7 @@ where
/// Formats the date with the specified format string.
/// See the [`crate::format::strftime`] module
/// on the supported escape sequences.
#[cfg(any(feature = "alloc", feature = "std", test))]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
#[inline]
#[must_use]
Expand Down
Loading

0 comments on commit ac7d7dd

Please sign in to comment.