Skip to content

Commit 15dc2b9

Browse files
committed
Merge branch 'main' into bigbang
2 parents 4002733 + 544fd9a commit 15dc2b9

File tree

14 files changed

+126
-133
lines changed

14 files changed

+126
-133
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- { target: i686-unknown-linux-musl , os: ubuntu-20.04, use-cross: true }
5151
- { target: x86_64-apple-darwin , os: macos-12 }
5252
- { target: aarch64-apple-darwin , os: macos-12 }
53-
- { target: x86_64-pc-windows-gnu , os: windows-2019 }
53+
# - { target: x86_64-pc-windows-gnu , os: windows-2019 }
5454
- { target: x86_64-pc-windows-msvc , os: windows-2019 }
5555
- { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true }
5656
- { target: x86_64-unknown-linux-musl , os: ubuntu-20.04, use-cross: true }

Cargo.lock

Lines changed: 32 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jaq-core/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "jaq-core"
3-
version = "1.5.0"
3+
version = "1.5.1"
44
authors = ["Michael Färber <michael.faerber@gedenkt.at>"]
55
edition = "2021"
66
license = "MIT"
@@ -16,11 +16,12 @@ std = []
1616
format = ["aho-corasick", "base64", "urlencoding"]
1717
math = ["libm"]
1818
parse_json = ["hifijson"]
19+
time = ["chrono"]
1920

2021
[dependencies]
2122
jaq-interpret = { version = "1.5.0", path = "../jaq-interpret" }
2223
hifijson = { version = "0.2.0", optional = true }
23-
time = { version = "0.3.20", optional = true, features = ["formatting", "parsing"] }
24+
chrono = { version = "0.4.38", default-features = false, features = ["alloc"], optional = true }
2425
regex = { version = "1.9", optional = true }
2526
log = { version = "0.4.17", optional = true }
2627
libm = { version = "0.2.7", optional = true }

jaq-core/src/time.rs

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,36 @@
11
use crate::{ValR2, ValT};
22
use alloc::string::{String, ToString};
3+
use chrono::DateTime;
34
use jaq_interpret::Error;
45

5-
/// Parse an ISO-8601 timestamp string to a number holding the equivalent UNIX timestamp
6+
/// Parse an ISO 8601 timestamp string to a number holding the equivalent UNIX timestamp
67
/// (seconds elapsed since 1970/01/01).
8+
///
9+
/// Actually, this parses RFC 3339; see
10+
/// <https://ijmacd.github.io/rfc3339-iso8601/> for differences.
11+
/// jq also only parses a very restricted subset of ISO 8601.
712
pub fn from_iso8601<V: ValT>(s: &str) -> ValR2<V> {
8-
use time::format_description::well_known::Iso8601;
9-
use time::OffsetDateTime;
10-
let datetime = OffsetDateTime::parse(s, &Iso8601::DEFAULT)
13+
let dt = DateTime::parse_from_rfc3339(s)
1114
.map_err(|e| Error::str(format_args!("cannot parse {s} as ISO-8601 timestamp: {e}")))?;
12-
let epoch_s = datetime.unix_timestamp();
1315
if s.contains('.') {
14-
let seconds = epoch_s as f64 + (f64::from(datetime.nanosecond()) * 1e-9_f64);
15-
Ok(seconds.into())
16+
Ok((dt.timestamp_micros() as f64 * 1e-6_f64).into())
1617
} else {
17-
isize::try_from(epoch_s)
18+
let seconds = dt.timestamp();
19+
isize::try_from(seconds)
1820
.map(V::from)
19-
.or_else(|_| V::from_num(&epoch_s.to_string()))
21+
.or_else(|_| V::from_num(&seconds.to_string()))
2022
}
2123
}
2224

23-
/// Format a number as an ISO-8601 timestamp string.
25+
/// Format a number as an ISO 8601 timestamp string.
2426
pub fn to_iso8601<V: ValT>(v: &V) -> Result<String, Error<V>> {
25-
use time::format_description::well_known::iso8601;
26-
use time::OffsetDateTime;
27-
const SECONDS_CONFIG: iso8601::EncodedConfig = iso8601::Config::DEFAULT
28-
.set_time_precision(iso8601::TimePrecision::Second {
29-
decimal_digits: None,
30-
})
31-
.encode();
32-
33-
let fail1 = |e| Error::str(format_args!("cannot format {v} as ISO-8601 timestamp: {e}"));
34-
let fail2 = |e| Error::str(format_args!("cannot format {v} as ISO-8601 timestamp: {e}"));
35-
27+
let fail = || Error::str(format_args!("cannot format {v} as ISO-8601 timestamp"));
3628
if let Some(i) = v.as_isize() {
37-
let iso8601_fmt_s = iso8601::Iso8601::<SECONDS_CONFIG>;
38-
OffsetDateTime::from_unix_timestamp(i as i64)
39-
.map_err(fail1)?
40-
.format(&iso8601_fmt_s)
41-
.map_err(fail2)
29+
let dt = DateTime::from_timestamp(i as i64, 0).ok_or_else(fail)?;
30+
Ok(dt.format("%Y-%m-%dT%H:%M:%SZ").to_string())
4231
} else {
4332
let f = v.as_f64()?;
44-
let f_ns = (f * 1_000_000_000_f64).round() as i128;
45-
OffsetDateTime::from_unix_timestamp_nanos(f_ns)
46-
.map_err(fail1)?
47-
.format(&iso8601::Iso8601::DEFAULT)
48-
.map_err(fail2)
33+
let dt = DateTime::from_timestamp_micros((f * 1e6_f64) as i64).ok_or_else(fail)?;
34+
Ok(dt.format("%Y-%m-%dT%H:%M:%S%.fZ").to_string())
4935
}
5036
}

jaq-core/tests/tests.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,22 @@ fn ascii() {
3737
give(json!("aAaAäの"), "ascii_downcase", json!("aaaaäの"));
3838
}
3939

40-
#[test]
41-
fn dateiso8601() {
42-
give(
43-
json!("1970-01-02T00:00:00Z"),
44-
"fromdateiso8601",
45-
json!(86400),
46-
);
47-
give(
48-
json!("1970-01-02T00:00:00.123456789Z"),
49-
"fromdateiso8601",
50-
json!(86400.123456789),
51-
);
52-
give(json!(86400), "todateiso8601", json!("1970-01-02T00:00:00Z"));
53-
give(
54-
json!(86400.123456789),
55-
"todateiso8601",
56-
json!("1970-01-02T00:00:00.123456789Z"),
57-
);
58-
}
40+
yields!(
41+
fromdate,
42+
r#""1970-01-02T00:00:00Z" | fromdateiso8601"#,
43+
86400
44+
);
45+
yields!(
46+
fromdate_micros,
47+
r#""1970-01-02T00:00:00.123456Z" | fromdateiso8601"#,
48+
86400.123456
49+
);
50+
yields!(todate, r#"86400 | todateiso8601"#, "1970-01-02T00:00:00Z");
51+
yields!(
52+
todate_micros,
53+
r#"86400.123456 | todateiso8601"#,
54+
"1970-01-02T00:00:00.123456Z"
55+
);
5956

6057
#[test]
6158
fn explode_implode() {

jaq-parse/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "jaq-parse"
3-
version = "1.0.2"
3+
version = "1.0.3"
44
authors = ["Michael Färber <michael.faerber@gedenkt.at>"]
55
edition = "2021"
66
license = "MIT"
@@ -14,3 +14,6 @@ rust-version = "1.64"
1414
[dependencies]
1515
chumsky = { version = "0.9.0", default-features = false }
1616
jaq-syn = { version = "1.0.0", path = "../jaq-syn" }
17+
18+
[badges.maintenance]
19+
status = "deprecated"

jaq-parse/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//! JSON query language parser.
2+
//!
3+
//! **Note**:
4+
//! This crate is not maintained anymore.
5+
//! It has been superseded by the `jaq-syn` crate.
26
#![no_std]
37
#![forbid(unsafe_code)]
48
#![warn(missing_docs)]

jaq-play/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jaq-interpret = { version = "1.2.0", path = "../jaq-interpret" }
2121
jaq-core = { version = "1.2.0", path = "../jaq-core" }
2222
jaq-std = { version = "1.2.0", path = "../jaq-std" }
2323
aho-corasick = "1.1.2"
24-
codesnake = { version = "0.1" }
24+
codesnake = { version = "0.2" }
2525
hifijson = "0.2"
2626
log = "0.4.17"
2727
unicode-width = "0.1.13"

jaq-play/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ pub fn run(filter: &str, input: &str, settings: &JsValue, scope: &Scope) {
179179
.unwrap();
180180
}
181181
Err(Error::Jaq(e)) => {
182-
scope.post_message(&format!("⚠️ Error: {e}").into()).unwrap();
182+
scope
183+
.post_message(&format!("⚠️ Error: {e}").into())
184+
.unwrap();
183185
}
184186
}
185187

@@ -354,7 +356,9 @@ impl Report {
354356
};
355357
let labels = self.labels.into_iter().map(|(range, text, color)| {
356358
let text = text.into_iter().map(color_maybe).collect::<Vec<_>>();
357-
Label::new(range, text.join("")).with_style(move |s| color.apply(s).to_string())
359+
Label::new(range)
360+
.with_text(text.join(""))
361+
.with_style(move |s| color.apply(s).to_string())
358362
});
359363
Block::new(idx, labels).unwrap().map_code(|c| {
360364
let c = c.replace('\t', " ");

jaq-std/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "jaq-std"
3-
version = "1.5.1"
3+
version = "1.6.0"
44
authors = ["Michael Färber <michael.faerber@gedenkt.at>"]
55
edition = "2021"
66
license = "MIT"
@@ -11,7 +11,7 @@ keywords = ["json", "query", "jq"]
1111
rust-version = "1.64"
1212

1313
[dependencies]
14-
jaq-syn = { version = "1.0.0", path = "../jaq-syn" }
14+
jaq-syn = { version = "1.6.0", path = "../jaq-syn" }
1515

1616
[dev-dependencies]
1717
jaq-interpret = { version = "1.2.0", path = "../jaq-interpret" }

0 commit comments

Comments
 (0)