GH-15 feat!: Add flags --overwrite and --threshold. - #22
Merged
Conversation
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.
There was a problem hiding this comment.
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--thresholdoption. - Updates
App/Builderto use aModeenum 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.
OrangeTux
marked this pull request as ready for review
May 10, 2026 19:20
| pub apply: bool, | ||
| pub overwrite: bool, | ||
|
|
||
| /// maximum allowed time difference when deciding to update an asset's creation date. |
| #[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 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 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 on lines
+42
to
43
| // println!("Received {} {}", request.method(), request.url()); | ||
|
|
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 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 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), | ||
| }; |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If
--overwriteis set,retrodatewill alwaysset an asset's originalDateTime value, even if it
already had a value for originalDateTime.
If
--thresholdis set, one can configure the minimuminterval 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
--applywith--if-unset,making this commit backwards incompatible.