Skip to content

Commit 801d22c

Browse files
authored
Update deps (#8)
1 parent 6c27b30 commit 801d22c

File tree

10 files changed

+70
-66
lines changed

10 files changed

+70
-66
lines changed

.github/workflows/ci.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
lints:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616
- name: Format
1717
run: |
1818
cargo fmt -- --check
@@ -34,16 +34,15 @@ jobs:
3434
- { name: macOS, os: macos-latest, triple: x86_64-apple-darwin }
3535
- { name: Windows, os: windows-2022, triple: x86_64-pc-windows-msvc }
3636
version:
37-
- 1.59.0 # MSRV
37+
- 1.73.0 # MSRV
3838
- stable
3939
- nightly
4040
steps:
41-
- uses: actions/checkout@v2
41+
- uses: actions/checkout@v4
4242
- name: Install ${{ matrix.version }}
43-
uses: actions-rs/toolchain@v1
43+
uses: actions-rust-lang/setup-rust-toolchain@v1
4444
with:
4545
toolchain: ${{ matrix.version }}-${{ matrix.target.triple }}
46-
profile: minimal
4746
override: true
4847
- name: Run tests
4948
run: |
@@ -53,7 +52,7 @@ jobs:
5352
needs: test
5453
runs-on: ubuntu-latest
5554
steps:
56-
- uses: actions/checkout@v2
55+
- uses: actions/checkout@v4
5756
- name: Audit
5857
run: |
5958
cargo update

.github/workflows/tag_publish.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ jobs:
99
name: publish ${{ matrix.target }}
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions-rs/toolchain@v1
12+
- uses: actions/checkout@v4
13+
- uses: actions-rust-lang/setup-rust-toolchain@v1
1414
with:
1515
toolchain: stable
1616
override: true
17-
- uses: katyo/publish-crates@v1
17+
- uses: katyo/publish-crates@v2
1818
with:
1919
path: './formula'
2020
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/update_readme.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ jobs:
88
generate_readme:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
1212
- name: Install Cargo readme
1313
run: cargo install cargo-readme
1414
- name: Run Cargo readme
1515
run: cd formula && cargo readme --no-title --no-license > ../README.md
1616
- name: Commit the changes
17-
uses: stefanzweifel/git-auto-commit-action@v4
17+
uses: stefanzweifel/git-auto-commit-action@v5
1818
with:
1919
commit_message: Update README.md
2020
file_pattern: README.md

Cargo.toml

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
[workspace]
22
members = ["formula", "formula-wasm"]
3-
4-
[profile.dev]
5-
debug = 0
6-
7-
[profile.release]
8-
lto = true
9-
opt-level = 'z'
10-
codegen-units = 1
11-
panic = 'abort'
12-
strip = true
3+
resolver = "2"
134

145
[patch.crates-io]
156
formula = { path = "formula" }

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ check:
1111
@cargo update --dry-run
1212
@cargo outdated -wR
1313
@cargo +nightly udeps --all-targets
14-
@cargo readme --no-title --no-license > README.md
14+
@cd formula && cargo readme --no-title --no-license > ../README.md
1515

16-
check_nightly: check
16+
check_nightly:
1717
@cargo +nightly clippy --fix --allow-dirty --allow-staged
1818

1919
check_strictly:
20-
@cargo +nightly clippy --fix --allow-dirty --allow-staged --all-features --all-targets -- -W clippy::all -W clippy::pedantic -W clippy::cargo -A clippy::missing_errors_doc -A clippy::extra_unused_lifetimes -A clippy::cast_sign_loss -A clippy::cast_possible_truncation -A clippy::missing-panics-doc -A clippy::module_name_repetitions -A clippy::cast_precision_loss -A clippy::cast_possible_wrap -A clippy::used_underscore_binding -A clippy::multiple_crate_versions -A clippy::option_option -A clippy::let_underscore_drop
20+
@cargo +nightly clippy --fix --allow-dirty --allow-staged --all-features --all-targets -- -W clippy::all -W clippy::pedantic -W clippy::cargo -A clippy::missing_errors_doc -A clippy::extra_unused_lifetimes -A clippy::cast_sign_loss -A clippy::cast_possible_truncation -A clippy::missing-panics-doc -A clippy::module_name_repetitions -A clippy::cast_precision_loss -A clippy::cast_possible_wrap -A clippy::used_underscore_binding -A clippy::multiple_crate_versions -A clippy::option_option -A let_underscore_drop
2121

2222
check_very_strictly:
2323
@cargo +nightly clippy --fix --allow-dirty --allow-staged --all-features --all-targets -- -W clippy::all -W clippy::pedantic -W clippy::cargo -A clippy::cast_sign_loss -A clippy::cast_possible_truncation -A clippy::cast_precision_loss
@@ -32,4 +32,4 @@ wasm_pack_and_publish:
3232
cargo build --release; \
3333
wasm-pack build --release; \
3434
wasm-pack pack; \
35-
wasm-pack publish
35+
wasm-pack publish

formula-wasm/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ readme = "README.md"
1010
documentation = "https://docs.rs/formula"
1111
repository = "https://github.com/omid/formula"
1212
edition = "2021"
13-
rust-version = "1.59"
13+
rust-version = "1.73"
1414

1515
[lib]
1616
crate-type = ["cdylib"]
1717

1818
[dependencies]
19-
wasm-bindgen = "0.2.83"
20-
formula = { version = "0.1.0" }
19+
wasm-bindgen = "0.2"
20+
formula = { version = "0.1" }

formula-wasm/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ fn array_to_string(arr: Expr) -> String {
2929
}
3030
format!("[{}]", strings.join(","))
3131
}
32-
Expr::String(v) => format!("\"{}\"", v),
33-
Expr::Date(v) => format!("\"{}\"", v),
34-
Expr::Datetime(v) => format!("\"{}\"", v),
35-
Expr::Time(v) => format!("\"{}\"", v),
32+
Expr::String(v) => format!("\"{v}\""),
33+
Expr::Date(v) => format!("\"{v}\""),
34+
Expr::Datetime(v) => format!("\"{v}\""),
35+
Expr::Time(v) => format!("\"{v}\""),
3636
Expr::Number(v) => v.to_string(),
3737
Expr::Bool(v) => v.to_string(),
3838
Expr::Null => "null".to_string(),

formula/Cargo.toml

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ readme = "README.md"
1010
documentation = "https://docs.rs/formula"
1111
repository = "https://github.com/omid/formula"
1212
edition = "2021"
13-
rust-version = "1.59"
13+
rust-version = "1.73"
1414

1515
[dependencies]
16-
chrono = "0.4.22"
17-
pest = "2.4.0"
18-
pest_derive = "2.4.0"
19-
rand = "0.8.5"
20-
thiserror = "1.0.34"
21-
urlencoding = "2.1.2"
22-
#sxd-xpath = "0.4.2"
23-
#sxd-document = "0.3.2"
16+
chrono = "0.4"
17+
pest = "2.7"
18+
pest_derive = "2.7"
19+
rand = "0.8"
20+
thiserror = "1.0"
21+
urlencoding = "2.1"
22+
#sxd-xpath = "0.4"
23+
#sxd-document = "0.3"
2424

2525
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
26-
reqwest = { version = "0.11.11", features = ["blocking"] }
26+
reqwest = { version = "0.12", features = ["blocking"] }
2727

2828
[target.'cfg(target_arch = "wasm32")'.dependencies]
29-
getrandom = { version = "0.2.7", features = ["js"] }
29+
getrandom = { version = "0.2", features = ["js"] }

formula/src/parsers/date_and_time.rs

+34-20
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,21 @@ impl Formula<'_> {
132132
let date = Self::datestring_to_naivedate(&date, &rule_name)?;
133133
let date = Self::shift_months(date, num);
134134
let last_day = Self::last_day_of_month(date.year(), date.month());
135-
NaiveDate::from_ymd(date.year(), date.month(), last_day)
135+
NaiveDate::from_ymd_opt(date.year(), date.month(), last_day)
136136
}
137137
(Expr::Date(date), Expr::Number(num)) => {
138138
let date = Self::shift_months(date, num);
139139
let last_day = Self::last_day_of_month(date.year(), date.month());
140-
NaiveDate::from_ymd(date.year(), date.month(), last_day)
140+
NaiveDate::from_ymd_opt(date.year(), date.month(), last_day)
141141
}
142142
_ => return Err(Error::Parser(rule_name)),
143143
};
144144

145+
let date = match date {
146+
None => return Err(Error::Parser(rule_name)),
147+
Some(v) => v,
148+
};
149+
145150
Ok(Expr::Date(date))
146151
}
147152

@@ -180,7 +185,7 @@ impl Formula<'_> {
180185
_ => return Err(Error::Parser(rule_name)),
181186
};
182187

183-
Ok(Expr::Number(days as f64))
188+
Ok(Expr::Number(days))
184189
}
185190

186191
pub(crate) fn parse_day(pair: Pair<Rule>) -> Result<Expr> {
@@ -227,7 +232,11 @@ impl Formula<'_> {
227232
let second = Self::get_formula(&mut args, &rule_name)?;
228233
let time = match (hour, minute, second) {
229234
(Expr::Number(hour), Expr::Number(minute), Expr::Number(second)) => {
230-
Expr::Time(NaiveTime::from_hms(hour as u32, minute as u32, second as u32))
235+
let time = match NaiveTime::from_hms_opt(hour as u32, minute as u32, second as u32) {
236+
None => return Err(Error::Parser(rule_name)),
237+
Some(v) => v,
238+
};
239+
Expr::Time(time)
231240
}
232241
_ => return Err(Error::Parser(rule_name)),
233242
};
@@ -242,7 +251,11 @@ impl Formula<'_> {
242251
let day = Self::get_formula(&mut args, &rule_name)?;
243252
let date = match (year, month, day) {
244253
(Expr::Number(year), Expr::Number(month), Expr::Number(day)) => {
245-
Expr::Date(NaiveDate::from_ymd(year as i32, month as u32, day as u32))
254+
let date = match NaiveDate::from_ymd_opt(year as i32, month as u32, day as u32) {
255+
None => return Err(Error::Parser(rule_name)),
256+
Some(v) => v,
257+
};
258+
Expr::Date(date)
246259
}
247260
_ => return Err(Error::Parser(rule_name)),
248261
};
@@ -256,7 +269,7 @@ impl Formula<'_> {
256269
.collect::<std::result::Result<Vec<_>, _>>()
257270
.map_err(|_| Error::Parser(rule_name.to_owned()))?;
258271
#[allow(clippy::cast_possible_wrap)]
259-
Ok(NaiveDate::from_ymd(mdy[2] as i32, mdy[0], mdy[1]))
272+
NaiveDate::from_ymd_opt(mdy[2] as i32, mdy[0], mdy[1]).ok_or_else(|| Error::Parser(rule_name.to_owned()))
260273
}
261274

262275
fn timestring_to_naivetime(timestring: &str, rule_name: &str) -> Result<NaiveTime> {
@@ -267,14 +280,15 @@ impl Formula<'_> {
267280
.map(str::parse)
268281
.collect::<std::result::Result<Vec<_>, _>>()
269282
.map_err(|_| Error::Parser(rule_name.to_owned()))?;
270-
Ok(NaiveTime::from_hms(hms[0], hms[1], hms[2]))
283+
NaiveTime::from_hms_opt(hms[0], hms[1], hms[2]).ok_or_else(|| Error::Parser(rule_name.to_owned()))
271284
}
272285

273286
fn last_day_of_month(year: i32, month: u32) -> u32 {
274287
NaiveDate::from_ymd_opt(year, month + 1, 1)
275-
.unwrap_or_else(|| NaiveDate::from_ymd(year + 1, 1, 1))
276-
.pred()
277-
.day()
288+
.ok_or_else(|| NaiveDate::from_ymd_opt(year + 1, 1, 1))
289+
.map(|v| v.pred_opt().map(|v| v.day()))
290+
.expect("A valid date")
291+
.expect("A valid date")
278292
}
279293

280294
fn shift_months(date: NaiveDate, months: f64) -> NaiveDate {
@@ -287,7 +301,7 @@ impl Formula<'_> {
287301
let last_day = Self::last_day_of_month(year, month);
288302
let day = if day > last_day { last_day } else { day };
289303

290-
NaiveDate::from_ymd(year, month, day)
304+
NaiveDate::from_ymd_opt(year, month, day).expect("A valid date")
291305
}
292306
}
293307

@@ -301,11 +315,11 @@ mod tests {
301315
fn test_parse_date_and_time_types() {
302316
let formula = Formula::new("=DATE(2020,2,3)").unwrap();
303317
let value = formula.parse().unwrap();
304-
assert_eq!(value, Expr::Date(NaiveDate::from_ymd(2020, 2, 3)));
318+
assert_eq!(value, Expr::Date(NaiveDate::from_ymd_opt(2020, 2, 3).unwrap()));
305319

306320
let formula = Formula::new("=DATE(YEAR('1/30/2020'),MONTH('1/30/2020'),DAY('1/30/2020'))".trim()).unwrap();
307321
let value = formula.parse().unwrap();
308-
assert_eq!(value, Expr::Date(NaiveDate::from_ymd(2020, 1, 30)));
322+
assert_eq!(value, Expr::Date(NaiveDate::from_ymd_opt(2020, 1, 30).unwrap()));
309323

310324
let formula = Formula::new("=YEAR('1/30/2020')").unwrap();
311325
let value = formula.parse().unwrap();
@@ -321,7 +335,7 @@ mod tests {
321335

322336
let formula = Formula::new("=DATEVALUE('1/30/2020')").unwrap();
323337
let value = formula.parse().unwrap();
324-
assert_eq!(value, Expr::Date(NaiveDate::from_ymd(2020, 1, 30)));
338+
assert_eq!(value, Expr::Date(NaiveDate::from_ymd_opt(2020, 1, 30).unwrap()));
325339

326340
let formula = Formula::new("=DAYS('3/30/2020', '1/30/2020')").unwrap();
327341
let value = formula.parse().unwrap();
@@ -337,19 +351,19 @@ mod tests {
337351

338352
let formula = Formula::new("=EDATE('1/30/2020', 5)").unwrap();
339353
let value = formula.parse().unwrap();
340-
assert_eq!(value, Expr::Date(NaiveDate::from_ymd(2020, 6, 30)));
354+
assert_eq!(value, Expr::Date(NaiveDate::from_ymd_opt(2020, 6, 30).unwrap()));
341355

342356
let formula = Formula::new("=EDATE(DATE(2020,8,25),27)").unwrap();
343357
let value = formula.parse().unwrap();
344-
assert_eq!(value, Expr::Date(NaiveDate::from_ymd(2022, 11, 25)));
358+
assert_eq!(value, Expr::Date(NaiveDate::from_ymd_opt(2022, 11, 25).unwrap()));
345359

346360
let formula = Formula::new("=EOMONTH('1/20/2020', 5)").unwrap();
347361
let value = formula.parse().unwrap();
348-
assert_eq!(value, Expr::Date(NaiveDate::from_ymd(2020, 6, 30)));
362+
assert_eq!(value, Expr::Date(NaiveDate::from_ymd_opt(2020, 6, 30).unwrap()));
349363

350364
let formula = Formula::new("=EOMONTH(DATE(2020,8,31),27)").unwrap();
351365
let value = formula.parse().unwrap();
352-
assert_eq!(value, Expr::Date(NaiveDate::from_ymd(2022, 11, 30)));
366+
assert_eq!(value, Expr::Date(NaiveDate::from_ymd_opt(2022, 11, 30).unwrap()));
353367

354368
let formula = Formula::new("=HOUR('02:30:00')").unwrap();
355369
let value = formula.parse().unwrap();
@@ -369,11 +383,11 @@ mod tests {
369383

370384
let formula = Formula::new("=TIME(2,30,0)").unwrap();
371385
let value = formula.parse().unwrap();
372-
assert_eq!(value, Expr::Time(NaiveTime::from_hms(2, 30, 0)));
386+
assert_eq!(value, Expr::Time(NaiveTime::from_hms_opt(2, 30, 0).unwrap()));
373387

374388
let formula = Formula::new("=TIMEVALUE('02:30:00')").unwrap();
375389
let value = formula.parse().unwrap();
376-
assert_eq!(value, Expr::Time(NaiveTime::from_hms(2, 30, 0)));
390+
assert_eq!(value, Expr::Time(NaiveTime::from_hms_opt(2, 30, 0).unwrap()));
377391

378392
let formula = Formula::new("=WEEKDAY(DATE(2020,1,1))").unwrap();
379393
let value = formula.parse().unwrap();

formula/src/parsers/text.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl Formula<'_> {
312312
};
313313

314314
let decimals = decimals as usize;
315-
let mut text = format!("{:.*}", decimals, number);
315+
let mut text = format!("{number:.decimals$}");
316316

317317
if !no_commas {
318318
// separate text with commas
@@ -342,7 +342,7 @@ impl Formula<'_> {
342342

343343
match num_and_decimal.get(1) {
344344
Some(decimals) => {
345-
text = format!("{}.{}", t, decimals);
345+
text = format!("{t}.{decimals}");
346346
}
347347
None => {
348348
text = t;
@@ -432,7 +432,7 @@ impl Formula<'_> {
432432
}
433433
let start_text = text.chars().take((start as usize) - 1).collect::<String>();
434434
let end_text = text.chars().skip((start + len) as usize - 1).collect::<String>();
435-
format!("{}{}{}", start_text, new_text, end_text)
435+
format!("{start_text}{new_text}{end_text}")
436436
}
437437
_ => return Err(Error::Parser(rule_name)),
438438
};

0 commit comments

Comments
 (0)