Skip to content

GH-15 feat!: Add flags --overwrite and --threshold. - #22

Merged
OrangeTux merged 8 commits into
masterfrom
gh-15-update-data
May 10, 2026
Merged

GH-15 feat!: Add flags --overwrite and --threshold. #22
OrangeTux merged 8 commits into
masterfrom
gh-15-update-data

Conversation

@OrangeTux

@OrangeTux OrangeTux commented May 9, 2026

Copy link
Copy Markdown
Owner

If --overwrite is set, retrodate will always
set an asset's originalDateTime value, even if it
already had a value for originalDateTime.

If --threshold is set, one can configure the minimum
interval between the old and the new originalDateTime.
E.g. a value of "1d" means that the asset is updated
only, if the old and the new originalDateTime are
more than 1 day apart.

This commit renames the option --apply with --if-unset,
making this commit backwards incompatible.

OrangeTux added 3 commits May 8, 2026 13:33
If `--overwrite` is set, `retrodate` will always
set an asset's originalDateTime value, even if it
already had a value for originalDateTime.

If `--threshold` is set, one can configure the minimum
interval between the old and the new originalDateTime.
E.g. a value of "1d" means that the asset is updated
only, if the old and the new originalDateTime are
more than 1 day apart.

This commit renames the option  `--apply` with `--if-unset`,
making this commit backwards incompatible.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates retrodate’s execution modes to better control when asset EXIF timestamps are mutated, adding support for “only set if missing”, “overwrite”, and an overwrite threshold based on jiff::Span.

Changes:

  • Replaces the previous “apply” behavior with explicit modes (--if-unset, --overwrite) and introduces a --threshold option.
  • Updates App/Builder to use a Mode enum and adds overwrite-threshold logic when deciding whether to update timestamps.
  • Adjusts tests and CLI wiring to use the new overwrite behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
tests/lib.rs Updates test setup to use the new builder overwrite mode.
src/main.rs Wires new CLI flags into the builder and parses the overwrite threshold.
src/lib.rs Introduces Mode enum, updates asset mutation logic, and updates CLI args.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main.rs
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
@OrangeTux
OrangeTux marked this pull request as ready for review May 10, 2026 19:20
@OrangeTux
OrangeTux requested a review from Copilot May 10, 2026 19:28
@OrangeTux OrangeTux changed the title Gh 15 update data GH-15 feat!: Add flags --overwrite and --threshold. May 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 11 comments.

Comment thread src/lib.rs
pub apply: bool,
pub overwrite: bool,

/// maximum allowed time difference when deciding to update an asset's creation date.
Comment thread src/lib.rs
#[argh(switch)]
pub if_unset: bool,

/// set the creation date of an asset, even if that asset has a creation date already. It sets --if-unset.
Comment thread src/lib.rs
Comment on lines +183 to +189
(Mode::IfUnset | Mode::Overwrite(_), None) => {
let _ = set_assets_date_time(&asset.id, &datetime, &self.client)?;
debug(format!(
"Date of {} set to {}.",
asset.original_file_name, datetime
));
}
Comment thread README.md
Comment on lines +35 to 51
Run the same command with the flag `--if-unset` added to apply the changes:

```bash
./retrodate --api-key "${API_KEY}" --host "${IMMICH_API}" --apply
Date of IMG_20180301_131212.jpg set to 2018-03-01T13:12:12.
Date of 20190720_130508.jpg set to 2019-07-20T13:05:08.
Date of Screenshot_20201225-162340_Nike Run Club.jpg set to 2020-12-25T16:23:40.
Date of Screenshot_20201202-183706_Spotify.jpg set to 2020-12-02T18:37:06.
./retrodate --api-key "${API_KEY}" --host "${IMMICH_API}" --if-unset
Date of Screenshot_20230927_191315.jpg set to 2023-09-27T19:13:15.
Date of Screenshot_20231001.jpg set to 2023-10-01T00:00:00.
Skipping of Screenshot_2023-11-02T041328.jpg, the asset has datetime set to 1970-01-01T00:00:00. Call `retrodate` with --overwrite to replace the existing datetime.
```

Alternatively, use `--overwrite` to modify assets that already have a creation date.

```bash
./retrodate --api-key "${API_KEY}" --host "${IMMICH_API}" --overwrite
Date of Screenshot_20230927_191315.jpg set to 2023-09-27T19:13:15.
Date of Screenshot_20231001.jpg set to 2023-10-01T00:00:00.
Date of Screenshot_2023-11-02T041328.jpg set from 1970-01-01T00:00:00 to 2023-11-02T04:13:28.
```
Comment thread README.md
Comment thread README.md Outdated
Comment thread tests/env/immich.rs
Comment on lines +42 to 43
// println!("Received {} {}", request.method(), request.url());

Comment thread tests/lib.rs
Comment on lines +46 to +50
// Asset contains valid date and time. But it already a value for dateTimeOriginal.
Asset {
id: String::from("6"),
original_file_name: String::from("Screenshot_2023-09-27T191315.jpg"),
exif_info: Some(ExifInfo {
Comment thread tests/lib.rs
Comment on lines +54 to +58
// Asset contains valid date and time. But it already a value for dateTimeOriginal.
Asset {
id: String::from("7"),
original_file_name: String::from("Screenshot_2023-09-27T191315.jpg"),
exif_info: Some(ExifInfo {
Comment thread src/main.rs
Comment on lines +29 to +41
let threshold = args
.threshold
.map(|value| value.parse::<Span>())
.transpose()
.wrap_err_with(|| {
"failed to parse the value of --threshold, use a value like '1d' or '24h'".to_string()
})?;

let builder = match (args.overwrite, threshold) {
(false, _) => builder,
(true, None) => builder.overwrite(Span::new()),
(true, Some(interval)) => builder.overwrite(interval),
};
OrangeTux and others added 2 commits May 10, 2026 21:35
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@OrangeTux
OrangeTux merged commit 0c85da1 into master May 10, 2026
7 checks passed
@OrangeTux
OrangeTux deleted the gh-15-update-data branch May 10, 2026 19:44
@OrangeTux
OrangeTux restored the gh-15-update-data branch May 11, 2026 07:00
Copilot AI mentioned this pull request May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants