Hello -just getting started with Tinderbox and trying my hand at making a blog with it.
I’d like to create a string attribute that is the date of the note but with ordinals on the number, i.e. the final date looking like: Friday, 7th January, 2021.
I have a container with an OnAdd attribute $Date|=today;$NiceDate=date($Date).format("W, d MM, y"); which gets me everything except the th etc.
I have a feeling it may be a little complex for such a tiny detail but perhaps someone has solved it before or there’s a nice way. I did try searching but didn’t come across the same problem.
Assuming $Date is a date attribute, there’s no need to say date($Date). $Date is fine. (You need to coerce the value if it’s a string, or if Tinderbox doesn’t know what it is.)
As you say, the easy approach gets you MOST of the way there!
What we need is function that takes a number and returns an ordinal string: “1st” or “3rd” or “25th”. That should not be too hard to write. Let’s suppose we’ve already done that. We’ll call the function ordinal().
Now, you’re going to say something like $NiceDate=$Date.format("W, ")+ordinal($Date.day)+$Date.format(" MM, y");. I haven’t tested this so there may be typos, but you’re going to want something like that.
I think this might be sort of fun to do — a good Czerny exercise! If you (or someone) does this, do share the result.
This only works in English. A better way to do this would be to build a localized solution into date.formatter — perhaps the format code “od” for "ordinal date. I’ll look into that if there’s interest.