[V2] set id to a timestamp?

I noticed in an issue posted by @nobiot a header with some interesting properties

:properties:
:id: 2021-04-15T173128
:modified: 2021-04-15T173136
:end:
#+title: test tag 17
#+filetags: meeting

Questions: How do I make an :id: property as a timestamp, and how do I set and manage the :modified: property?

Nothing complicated.

For the time stamp (“modified” property), I have this.

I then simply have org-roam-capture-templates to define the ID and modified properties at the head of a new Org file.

For the time stamp, just like this: :modified: <> (per the in-system documentation in the post I linked above, I think).

I don’t generate the ID with an Org-ID function but the normal date format (like %Y-%m-%d etc.)

For V1, see below. This is for my markdown front matter but it’s essentially the same for my Org. I don’t use it as is any longer as I have moved on to V2.

(setq org-roam-capture-templates
      '(("p" "personal" plain
         (function org-roam--capture-get-point) "%?"
         :file-name "personal/%<%Y-%m-%dT%H%M%S>"
         :head "---\ntitle: ${title}\nid: %<%Y-%m-%dT%H%M%S>\nmodified: <>\n---\n"
         :unnarrowed t)))

1 Like

I was looking through the org-id.el source, and discovered

(defcustom org-id-ts-format "%Y%m%dT%H%M%S.%6N"
  "Default format for IDs generated using `ts' `org-id-method'.
The format should be suitable to pass as an argument to `format-time-string'."
  :type 'string
  :package-version '(Org . "9.5"))

This could make setting the timestamp id really easy.

1 Like

the ts option in org-id-method dates back a bit further, but the custom formatting is new in 9.5. I took the opportunity before answering here to update the docstring slightly, and to squeeze in a mention of org-id-method in the Org manual… :slight_smile:

So… I guess this answer by me isn’t really necessary any longer! Glad you found the setting on your own! :wink:

2 Likes

Yes. I was just coming back to mention it. :slight_smile:

It looks like the 9.5 version will allow for a custom formatting of the time string, which is great for me. @Gustav is that correct understanding?

The only reason I use my custom way is the formatting (I’m on Org 9.4). If you use a custom way like I do, you might then want to manually update the org-id-locations file (a discussion here) — will not be relevant for 9.5 onwards :slight_smile:

The other thing that struck me about the example is that :modified: property ends up in the property drawer along with the id.

What should a template look like to make that happen?

Sorry if I wasn’t clear but I had thought the markdown example above was sufficient? It’s text. I just insert :property: \n :id: \n :end: and so on

1 Like

Locks correct to me!

Personally I’ve left the stable releases of Org a long time back, living on Org mode master (using Straight package manager, to ease with the configuration management). And on Org mode master this (ofc.) already is implemented.

1 Like