From 5e6ed88a3dc828e8d0e6236f5765bf2d31d42631 Mon Sep 17 00:00:00 2001 From: Michael Beutler Date: Fri, 1 Mar 2024 13:40:31 +0100 Subject: [PATCH] =?UTF-8?q?Added=20date=20extractor=20from=20filename.=20?= =?UTF-8?q?=F0=9F=93=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6acd7ca..9a370ef 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@iperka/scan-categorizer", "description": "Categorize your scanned documents and organize them in folders.", - "version": "2.0.2", + "version": "2.0.3", "main": "index.js", "license": "MIT", "author": { diff --git a/src/index.ts b/src/index.ts index fae98dd..e9db7b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,7 +198,22 @@ namespace ScanCategorizer { category: Query.Category, onlyShortcut?: boolean, ) => { - const date: Date = new Date(file.getDateCreated().getTime()); + let date: Date = new Date(file.getDateCreated().getTime()); + if ( + file.getName().match(/[1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]/g) + .length === 1 + ) { + const d = file + .getName() + .match(/[1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]/g)[0]; + const dateArray = d.split('-'); + (date = new Date( + parseInt(dateArray[0]), + parseInt(dateArray[1]) - 1, + parseInt(dateArray[2]), + )), + Logger.log('Date found in file name: ' + date); + } // Check if custom name is defined. const name =