plugin-templates icon indicating copy to clipboard operation
plugin-templates copied to clipboard

Deprecate custom_datetime

Open nishantwrp opened this issue 1 year ago • 4 comments

  • Mark custom_datetime as deprecated in favour of {{ datetime format="[]YYYY[-]MM[-]DD[ ]HH[:]mm[:]ss" }}
  • (Optional - Non blocking for 3.0.0) Show a one-time deprecation notice if anyone uses custom_datetime.

nishantwrp avatar Sep 15 '24 11:09 nishantwrp

This plugin in v2.4.0 on Windows cannot handle the formatting that you proposed as favorable: {{ datetime format="[]YYYY[-]MM[-]DD[ ]HH[:]mm[:]ss" }}

It throws an error:

(In plugin: Templates)

There was an error parsing that template, please review it and try again.

TypeError: (lookupProperty(...) || (depth0 && lookupProperty(...) || container.hooks.helperMissing).call is not a function

Could it be that this functionality has not been developed yet and your issue is a weired kind of a feature request?

janklostermann avatar Oct 23 '24 12:10 janklostermann

I would desire a more general date formatting option as well, that does not only work for datetime through #custom_datetime but works for all variables of type date.

janklostermann avatar Oct 23 '24 12:10 janklostermann

Handlebar.js helper could be the way to go (as Handlebar.js is the underlying template engine). The most primitive solution would be something across these lines:

Handlebars.registerHelper('YYYY', function (date) {
  const d= new Date(date);
  const year = d.getFullYear();
	return year
})

with template definition like

---
 start: date
---

# Start of Note
{{YYYY start}}

with startconfigured as "1923-01-01" at note creation would produce:


Start of Note

1923


The easiest implementation would be a config field in the plugins config, where (power) users could define these Helpers in JavaScript through a text field. And yes, I am aware, that this could open up security concerns with unsafe code snippets, and also significant debugging problems. Maybe through a testing like on the Handlebar Playground before saving as new config, these issues could become less problematic.

janklostermann avatar Oct 23 '24 12:10 janklostermann

  • Mark custom_datetime as deprecated in favour of {{ datetime format="[]YYYY[-]MM[-]DD[ ]HH[:]mm[:]ss" }}
  • (Optional - Non blocking for 3.0.0) Show a one-time deprecation notice if anyone uses custom_datetime.

Sorry nishantwrp, only now I realize that this was a note by yourself as the maintainer/developer of that plugin. Thanks for all your work. I am looking forward for such generalization. Please go the full way for custom-defined date / time variables as well.

janklostermann avatar Oct 23 '24 12:10 janklostermann