Date/Time Customizer

Amplenote plugins

name

Date/Time Customizer

icon

schedule

description

This plugin provide a customizable timestamp, you can change the format by proving your preferred options to the plugin.
Uses Intl.DateTimeFormat with a fairly rudimentary implementation.

The default format is 17/04/2024
The useFallbacks option will default everything to my preferred format: Wed, 17 April 2024 at 23:53

To configure a custom format to your liking:

weekdayyearmonthdayhourminutesecond: These options allow you to customize the representation of each date and time component. The possible values include "numeric", "2-digit", "long", "short", and "narrow".

hour12: true or false for to enable 12 hour vs 24 hour clock

setting

useFallbacks

setting

weekday

setting

month

setting

year

setting

hour12

setting

hour

setting

minute

setting

day

setting

second

{
insertText:
{
"dateTime": async function(app) {
return this._time(app)
},
},
_getParts(app)
{
var options = {
hour12: app.settings["hour12"] === "true",
}
 
if (app.settings.year)
{
options["year"] = app.settings.year;
}
if (app.settings.month)
{
options["month"] = app.settings.month;
}
if (app.settings.day)
{
options["day"] = app.settings.day;
}
if (app.settings.weekday)
{
options["weekday"] = app.settings.weekday;
}
if (app.settings.hour)
{
options["hour"] = app.settings.hour;
}
if (app.settings.minute)
{
options["minute"] = app.settings.minute;
}
if (app.settings.second)
{
options["second"] = app.settings.second;
}
 
if(app.settings.useFallbacks === "true") {
options["year"] = app.settings.year || "numeric";
options["month"] = app.settings.month || "long";
options["weekday"] = app.settings.weekday || "short";
options["day"] = app.settings.day || "numeric";
options["hour"] = app.settings.hour || "numeric";
options["minute"] = app.settings.minute || "numeric";
 
}
 
var f = new Intl.DateTimeFormat("en-GB", options);
var parts = f.formatToParts();
 
return parts;
},
_time(app)
{
var parts = this._getParts(app);
 
return parts.map((o) => o.value).join("");
}
}


linkExample

Default
17/04/2024


Default with "useFallbacks=true"
Wed, 17 April 2024 at 23:53