Here’s some of the internal code for the convertdate[]
filter:
if (format=="timestamp") {
results.push(new Date(title.replace(re,"$1")).getTime().toString());
} else {
if (title.match(/^-?\d+$/)) {
results.push($tw.utils.formatDateString(new Date(Number(title)),format));
} else {
results.push($tw.utils.formatDateString(new Date(title.replace(re,"$1")),format));
}
}
As you can see, the code uses new Date(...)
to turn the input to a JS date object. This standard JS method only accepts ISO8601-compliant text or epoch date signed integers as input, and thus does not handle the TWCore’s 17-digit “system date” format (or any abbreviated forms thereof).
Also, take note that, if the input is an integer value (as detected by the regexp pattern “/^-?\d+$/
”), then it is assumed to be an epoch date value and is passed directly to new Date()
to turn it into a JS date object.
In order to achieve the results you want, you would first need to format the input to an ISO8601-compliant form by using the TWCore’s existing format:date[...]
filter, like this:
*{{{ [{!!created}format:date[YYYY 0MM 0DD 0hh:0mm:0ss.0XXX]convertdate[timestamp]] }}}
*{{{ [{!!created}format:date[YYYY 0MM 0DD 0hh:0mm:0ss.0XXX]convertdate[]] }}}
*{{{ [[202207180910]format:date[YYYY 0MM 0DD 0hh:0mm:0ss.0XXX]convertdate[timestamp]] }}}
*{{{ [[202207180910]format:date[YYYY 0MM 0DD 0hh:0mm:0ss.0XXX]convertdate[]] }}}
*{{{ [[20220718]format:date[YYYY 0MM 0DD 0hh:0mm:0ss.0XXX]convertdate[timestamp]] }}}
*{{{ [[20220718]format:date[YYYY 0MM 0DD 0hh:0mm:0ss.0XXX]convertdate[]] }}}
Perhaps I can add a filter suffix (e.g., “convertdate:system[…]”) to indicate that the numeric input is a TWCore “system date” (or an abbreviated form of system date) rather than an epoch date signed integer value. This suffix would then automatically apply the format:date[...]
handling internally, so that the filter syntax could be simplified to something like this:
*{{{ [{!!created}convertdate:system[timestamp]] }}}
*{{{ [{!!created}convertdate:system[]] }}}
*{{{ [[202207180910]convertdate:system[timestamp]] }}}
*{{{ [[202207180910]convertdate:system[]] }}}
*{{{ [[20220718]convertdate:system[timestamp]] }}}
*{{{ [[20220718]convertdate:system[]] }}}
Let me experiment a bit to see what I can come up with…
-e