Date conversion: Roam to ISO?

30 views
Skip to first unread message

Mark Ware

unread,
Mar 13, 2023, 10:58:33 AM3/13/23
to TextSoap
Is it possible to use regex to convert dates in Roam's format, i.e. March 13th, 2023, to standard yyyy-mm-dd (2023-03-13) format? I know enough regex to extract the digits for the day and year, but how would convert a text match ("March", "April") into digits? Or do you have to do 12 search/replace operations first to convert the months, and then use regex to reorganise the resulting strings?

Mark Munz

unread,
Mar 13, 2023, 11:07:05 AM3/13/23
to text...@googlegroups.com
If you select the Dates group (popup menu), you'll see built-in cleaners, one which includes the cleaner "Normalize Dates to YYYY-MM-DD". These cleaners can be used directly from the sidebar (can be added to custom groups, etc).

image.png

If you need more custom date formatting, TextSoap 9.2 or later includes a Format Dates action which gives you full control of the date formatting.

image.png

The Format Dates action can be used within a custom cleaner (you can also use the above Apply action within a custom cleaner) as part of your workflow.


On Mon, Mar 13, 2023 at 7:58 AM Mark Ware <ware...@gmail.com> wrote:
Is it possible to use regex to convert dates in Roam's format, i.e. March 13th, 2023, to standard yyyy-mm-dd (2023-03-13) format? I know enough regex to extract the digits for the day and year, but how would convert a text match ("March", "April") into digits? Or do you have to do 12 search/replace operations first to convert the months, and then use regex to reorganise the resulting strings?

--
You received this message because you are subscribed to the Google Groups "TextSoap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to textsoap+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/textsoap/1636bcc2-abb2-4382-a372-0a0410fc5664n%40googlegroups.com.


--
Mark Munz
unmarked software
http://www.unmarked.com/

Mark Ware

unread,
Mar 13, 2023, 12:23:33 PM3/13/23
to TextSoap
Many thanks for speedy reply, appreciated. 

Unfortunately I didn't properly specify the problem. I want to convert the dates in the Roam link format, i.e. enclosed in double brackets, (e.g., change [[March 13th, 2023]] to [[2023-03-13]]), while leaving other dates or times in the text unaltered. (The Date converter is too enthusiastic, e.g. if there is a time like 17:45 in the text, it gets converted to today's date in the spec'd format.) So what I thought was using regex to match dates in double brackets (while ignoring anything else in double brackets), and then converting the format of just the matched strings. Is this possible?

Mark Munz

unread,
Mar 13, 2023, 1:51:20 PM3/13/23
to text...@googlegroups.com
Now that I better understand the parameters, I might go with something like this:

image.png

So this *should* match the Roam format as described, still using the Date formatter cleaner. 
The If Matches Regex will match a guess at a Roam date. It's not looking at the actual month name and allows optional st, nd, rd, th, (or any two letter endings). Once it has a possible date, it tries to apply the date formatter on it. It won't match other dates or times, so they don't get processed.

The expression breakdown is as followed:
\w+ - one more word characters (this is the month name)
\s - whitespace
\d+ - one more digits
\w{0,2} - this allows optional: 1st, 2nd, 3rd, etc. If these are required, change it to \w{2}
, - comma
\s - whitespace
\d+ - what should be a year.

So the If action will match "March 13, 2023" or "March 13th, 2023" and "Junk 20, 2023" and then try to apply the Normalize Date cleaner to each match.
The first two are actual dates and will be transformed. The third isn't a real date, so it will be ignored (no change).

Any other formatted dates or times won't match the If, so are also ignored.

OK… and then I read the response a little more carefully 🤔 and realized you wanted it only when in double brackets. So I tweaked it a bit more:

image.png

The If action will match [[March 13, 2023]], but not "March 13th, 2023"m but will match [[Junk 20, 2023]] and then try to apply the Normalize Date cleaner to each match.


Two additions. At the beginning:

\[{2} - [ needs to be escaped in regex, so we look use \[ and {2} to explicitly say 2 (we could write \[\[ as well, but that's a lot of slashes)


And at the end:

\]{2} - ] doesn't need to be escaped, but I do it for convention (and to keep syntax highlighting happy). Again {2} is explicit count, and could be written as \]\] or even ]] if you don't mind the goofed syntax highlight.



Mark Ware

unread,
Mar 16, 2023, 7:08:53 AM3/16/23
to TextSoap
Many thanks, sorry not to get back before, life getting in the way. 

That seems to be absolutely perfect for what I want. I don't though see "If Matches Regex" as an option in my version 8.6.3 – do I need to upgrade to v9 for this?

Mark Munz

unread,
Mar 16, 2023, 10:52:17 AM3/16/23
to text...@googlegroups.com
If Matches Regex is the same as If Matches Text (with Regex option enabled), so you should be able to still use TextSoap 8.

However, if you are running macOS 11 (or even macOS 10.15) or later, I'd highly recommend upgrading. TextSoap 8 lacks support for newer platforms and features.
You can read about all the various changes in TextSoap 9: https://textsoap.com/mac/releasenotes.html
And if you're ready to upgrade, go to https://textsoap.com/upgrade/



Mark Ware

unread,
Mar 16, 2023, 12:34:44 PM3/16/23
to TextSoap
Thanks, again - I've upgraded to v9 and all sorted now.
Reply all
Reply to author
Forward
0 new messages