Automatic Ordinals?

Everything related to our flagship word processor.
Post Reply
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Automatic Ordinals?

Post by Vanceone »

So I frequently use a custom time string in my documents:
"Dated this 3rd day of March, 2021". It's tedious, of course, to type that in every time, and luckily Nisus has a custom date/time format in the Insert menu. Questions, though: can I save my custom automatic date/time command so it can be easily found and used? I.e. add it to the menu somehow? Second, how can I get ordinals, i.e the "rd" or "th" or "st" part of the custom day? Is it possible? More generally, can Nisus handle automatic ordinals for dates? I'd love to have text that automatically applied the correct ordinal somehow. I suspect with the macro language something might be done, but it seems a bit tricky: ordinals are a specialized use, and not every number should be transformed into an ordinal.

Thoughts?
credneb
Posts: 187
Joined: 2007-03-28 07:30:34

Re: Automatic Ordinals?

Post by credneb »

[quote]can Nisus handle automatic ordinals for dates?[/quote]

Don't know about in the custom date format, but under Preferences:QuickFix, checking Superscript ordinals will give you 3<rd> (where <> is superscript) when you type 3-r-d or 2-3-r-d, for example. (It will do the same for 1-3-r-d, but 1-3-t-h also works)

Cliff
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Automatic Ordinals?

Post by adryan »

G'day, Vanceone et al

This is a really interesting problem, but I'm afraid I only have time at present for some remarks and hints.

The Custom Date & Time command does not allow for conditional text which ordinal suffixes require.

I always use ISO 8601 formatting for dates and times; it has many advantages which I won't elaborate on here. Today would be 2021-03-25.

Even if you don't wish to display a date in that format, it is a great place to start because of the uniform parsing it affords. For example, here is a Macro I wrote years ago that operates on a selected ISO-formatted date to convert it to a date string with a named month and ordinal day number.

Date ISO → US Ordinal.nwm
(23.65 KiB) Downloaded 441 times

This Macro could be modified in various ways:–

(1) If the default short date string were set to be in ISO 8601 format, the Macro could insert today's date (as a fixed date) and then proceed to do the conversion. (Or everything could be done using the Macro Language.)

(2) Three-character abbreviations for the months (Jan, Feb, etc) could be incorporated in the code.

(3) Elements could be reordered and additional text added to produce the final display format desired (as in your special case).

When it comes to the more general problem of converting integers (which do not necessarily represent dates) to ordinal numbers, things get quite tricky. Any conversion is probably best done by first selecting the integer to be converted rather than by getting the code to extract it from a string before performing the conversion.

The situation is not helped by the dual use of commas and periods as both punctuation marks and currency separators.

You might convert only integers followed by spaces, but then you miss integers followed by commas or periods (but see my preceding remark!).

You don't want to convert integers that represent years (such as 2021), but there could be (probably rare) cases where an integer that looks like a year does not represent a year and is something you do wish to convert to an ordinal number.

You need to deal with integers terminating in "11", "12" or "13" as special cases: they require an ordinal suffix of "th" and not "st". Depending on how you structure your code, it may be best to deal with these cases before dealing with integers terminating "simply" in "1", "2" or "3".

Don't forget zeros!

I hope this helps.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Automatic Ordinals?

Post by Þorvarður »

I frequently use a custom time string […]: "Dated this 3rd day of March, 2021". It's tedious […] to type that in every time
Hello Vanceone,

Here is a simple macro that should do what you want. Assign it a handy keyboard shortcut, such as commandKey dd. You can also place a button with this macro in your toolbar.

The macro checks the day number and adds "st", "nd", "rd" and "th" accordingly, superscripts them and places the insertion point after the year.
A custom time string for Vanceone.nwm.zip
(2.45 KiB) Downloaded 453 times
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: Automatic Ordinals?

Post by Vanceone »

Thank you Porvadur! Tiny tweak on my part (oddly enough, superscripting the ordinal is not really a good thing--but then, legal document formatting is persnickety) and it works wonderfully! Thanks again!

I do agree with Adryan that this is a hard problem, moving towards a more generic case than my specific need. Date formatting is always harder than it should be, in my limited programming experience.
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Automatic Ordinals?

Post by Þorvarður »

superscripting the ordinal is not really a good thing
Sorry about that. I thought you wanted it superscripted. :–)
We'll have to delete $loc1 then and everything that follows to fix that. :–)
Post Reply