diff --git a/packages/plugin-core/manifest.json b/packages/plugin-core/manifest.json index f8093496a8..a2e3afc513 100644 --- a/packages/plugin-core/manifest.json +++ b/packages/plugin-core/manifest.json @@ -183,6 +183,69 @@ }, "uiHints": ["Filter"] }, + { + "name": "assetDateFilter", + "title": "Filter by date", + "description": "Filter assets by date taken", + "types": ["AssetV1"], + "schema": { + "type": "object", + "properties": { + "startDate": { + "type": "object", + "title": "Start date", + "description": "Earliest date of assets to include", + "properties": { + "month": { + "type": "number", + "title": "Month", + "description": "Month of the year to match" + }, + "day": { + "type": "number", + "title": "Day", + "description": "Day of the year to match" + }, + "year": { + "type": "number", + "title": "Year", + "description": "Year to match" + } + } + }, + "endDate": { + "type": "object", + "title": "End date", + "description": "Latest date of assets to include", + "properties": { + "month": { + "type": "number", + "title": "Month", + "description": "Month of the year to match" + }, + "day": { + "type": "number", + "title": "Day", + "description": "Day of the year to match" + }, + "year": { + "type": "number", + "title": "Year", + "description": "Year to match" + } + } + }, + "recurring": { + "type": "boolean", + "default": false, + "title": "Match recurring dates", + "description": "Allow any assets with matching months/days regardless of the year" + } + }, + "required": ["recurring", "startDate", "endDate"] + }, + "uiHints": ["Filter"] + }, { "name": "filterFileType", "title": "Filter by file type", diff --git a/packages/plugin-core/src/index.d.ts b/packages/plugin-core/src/index.d.ts index 2ce414e84f..bc72437a3b 100644 --- a/packages/plugin-core/src/index.d.ts +++ b/packages/plugin-core/src/index.d.ts @@ -14,6 +14,7 @@ declare module 'main' { export function assetFileFilter(): I32; export function assetMissingTimeZoneFilter(): I32; export function assetLocationFilter(): I32; + export function assetDateFilter(): I32; // updates export function assetFavorite(): I32; diff --git a/packages/plugin-core/src/index.ts b/packages/plugin-core/src/index.ts index e67434bb54..29092a321d 100644 --- a/packages/plugin-core/src/index.ts +++ b/packages/plugin-core/src/index.ts @@ -95,6 +95,36 @@ export const assetLocationFilter = () => { }); }; +export const assetDateFilter = () => { + return wrapper< + WorkflowType.AssetV1, + { + startDate: { month: number; day: number; year: number }; + endDate: { month: number; day: number; year: number }; + recurring: boolean; + } + >(({ config, data }) => { + const assetDate = new Date(data.asset.localDateTime); + let startDate = new Date(config.startDate.year, config.startDate.month - 1, config.startDate.day); + let endDate = new Date(config.endDate.year, config.endDate.month - 1, config.endDate.day); + + if (config.recurring) { + startDate.setFullYear(assetDate.getFullYear()); + endDate.setFullYear(assetDate.getFullYear()); + + if (endDate < startDate) { + if (assetDate > endDate) { + endDate.setFullYear(endDate.getFullYear() + 1); + } else { + startDate.setFullYear(startDate.getFullYear() - 1); + } + } + } + + return { workflow: { continue: assetDate >= startDate && assetDate <= endDate } }; + }); +}; + export const assetFavorite = () => { return wrapper(({ config, data }) => { const target = config.inverse ? false : true;