Date Tag From Title

link

name

Date Tag From Title

Icon

🗓️

Setting

Parent tag

Setting

Revert to today upon failure

instructions

linkSettings

linkParent Tag

Decide if you want your date tags nested underneath a parent tag or at the top-level of your tags.

If you prefer to keep your date tags at the top level of your tag structure then leave the "Parent tag" setting blank.

If you prefer to keep your date tags underneath a parent tag, set the default "Parent tag" value with the tag path:

Be sure to end with a /.

In this example, the parent tag(s) are: -/dates/

This will keep all date tags nested under those tags, like this:

linkRevert to today upon failure

As the title suggests, this setting will use the current date if no other dates are found in the title.

Default value is no.

If left blank or invalid values are entered it will default to no.

You can also type in no.

Accepts yes, y, 1, and true

linkUsage

Put the date in your note's title

Many formats are correctly parsed.

Examples (can vary from one browser to another):

2023-12-22

December 22nd, 2023

Dec 22nd, 2023

Dec 22 2023

2023DEC22

2023-DEC-15

12-05-2023 (Interprets as: December 05, 2023)

Go to the menu and select "Date Tag From Title"

Enjoy having your note automatically tagged with a date tag!

Description

Tags current note with date from note title.

Tag will be formatted as yyyy/mm/dd.

Correctly parses Amplenote's Month NNst, YYYY format.

If it fails to parse a date from the note title, it can revert to the current date, if you have set it to do so in the options.


{
async noteOption(app, noteUUID) {
const note = await app.notes.find(noteUUID);
const title = note.name;
var revert_to_today_upon_failure;
var d;
var y;
var m;
var day;
 
const parts = title.trim().split(" ");
/*----====----====----====----====
First attempt: Look for Amplenote date format from string start position.
----====----====----====----====*/
if(parts.length > 2){
if(title.match(/(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d{1,2})(st|nd|rd|th),\s(\d{4})/i)){
var match = title.match(/(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d{1,2})(st|nd|rd|th),\s(\d{4})/i);
console.log(match);
match = match[0].replace("1st","1").replace("1th","1").replace("2th","2").replace("3th","3").replace("2nd","2").replace("3rd","3").replace("4th","4").replace("5th","5").replace("6th","6").replace("7th","7").replace("8th","8").replace("9th","9").replace("0th","0");
d = new Date(match);
}else if(title.match(/(Jan|January|Feb|February|Mar|March|Apr|April|May|Jun|June|Jul|July|Aug|August|Sept|September|Oct|October|Nov|November|Dec|December)\s(\d{1,2}),\s(\d{4})/i)){
var match = title.match(/(Jan|January|Feb|February|Mar|March|Apr|April|May|Jun|June|Jul|July|Aug|August|Sept|September|Oct|October|Nov|November|Dec|December)\s(\d{1,2}),\s(\d{4})/i);
d = new Date(match[0]);
}
}
 
 
/*----====----====----====----====
If fails, next attempt: Look through entire title for dates.
----====----====----====----====*/
if(isNaN(d)){
for(var i = 0; i < parts.length; i++){
d = new Date(parts[i]);
/* if successful then break out of the loop */
if(!isNaN(d)){break;}
}
}
 
/*----====----====----====----====
If still fails, revert to today if user accepted that option
----====----====----====----====*/
try{
revert_to_today_upon_failure = app.settings['Revert to today upon failure'];
if(revert_to_today_upon_failure == 'y' || revert_to_today_upon_failure == 'true' || revert_to_today_upon_failure == '1'){
revert_to_today_upon_failure = 'yes';
}
}catch(e){
revert_to_today_upon_failure = 'no';
}
if(isNaN(d) && revert_to_today_upon_failure == 'yes'){
d = new Date();
}
 
/*----====----====----====----====
Final output
----====----====----====----====*/
if(!isNaN(d)){
/* account for user's time zone */
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
y = d.getFullYear();
m = ('0' + (d.getMonth() + 1)).slice(-2);
day = ('0' + d.getDate()).slice(-2);
var parent_tag = await (app.settings["Parent tag"]) || "";
var final_tag = parent_tag + y + "/" + m + "/" + day;
const added = await note.addTag(final_tag);
}
}
}