emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Converting dates to org-mode dates
@ 2007-11-12 13:20 Chris Randle
  2007-11-12 13:30 ` Rainer Stengele
  2007-11-12 15:02 ` Bastien
  0 siblings, 2 replies; 4+ messages in thread
From: Chris Randle @ 2007-11-12 13:20 UTC (permalink / raw)
  To: emacs-orgmode

Hi

I've been converting a file that contains dates in this format:

dd/mm/yyyy

to Org-mode inactive format. It's pretty simple using regular expression
search & replace, except that I get this far:

[yyyy-mm-dd ]

and can't find a way to put the day of the week in there. Individually,
I can do a 'C-u 0 S-right' on each date, and that shifts the date 0 days
into the future, and fills in the day of the week.

This also impacts on cases (unusual and unlikely, I grant you) where you
might have an incorrect day:

[2007-11-12 Tue] (should be Mon)

As far as I can see, that will stay like this until the date is shifted
in some way.

Is there any way to parse an entire region/buffer for Org-mode dates and
refresh their day of the week text?

-- 
Chris Randle
GNU Emacs 22.1.1
Org-mode 5.13h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Converting dates to org-mode dates
  2007-11-12 13:20 Converting dates to org-mode dates Chris Randle
@ 2007-11-12 13:30 ` Rainer Stengele
  2007-11-12 15:02 ` Bastien
  1 sibling, 0 replies; 4+ messages in thread
From: Rainer Stengele @ 2007-11-12 13:30 UTC (permalink / raw)
  To: emacs-orgmode

Chris Randle schrieb:
> Hi
> 
> I've been converting a file that contains dates in this format:
> 
> dd/mm/yyyy
> 
> to Org-mode inactive format. It's pretty simple using regular expression
> search & replace, except that I get this far:
> 
> [yyyy-mm-dd ]
> 
> and can't find a way to put the day of the week in there. Individually,
> I can do a 'C-u 0 S-right' on each date, and that shifts the date 0 days
> into the future, and fills in the day of the week.
> 
> This also impacts on cases (unusual and unlikely, I grant you) where you
> might have an incorrect day:
> 
> [2007-11-12 Tue] (should be Mon)
> 
> As far as I can see, that will stay like this until the date is shifted
> in some way.
> 
> Is there any way to parse an entire region/buffer for Org-mode dates and
> refresh their day of the week text?
> 

I would probably do this with an Emacs macro,
searching for the date as a regex, moving to the space before "]" and shifting rigth and again shifting left.
This will end up with the right week day for each date.

rainer

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Converting dates to org-mode dates
  2007-11-12 15:02 ` Bastien
@ 2007-11-12 14:45   ` Chris Randle
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Randle @ 2007-11-12 14:45 UTC (permalink / raw)
  To: emacs-orgmode

Bastien wrote:
> Maybe you can try this (not heavily tested):
> 
> (defun my-update-day-name-in-inactive-time-stamps ()
>   "Update the abbreviate day name in inactive time-stamps."

Thank you. It works a treat. It also has a potentially useful
side-effect, in that valid inactive time stamps like:

[2007-11-12 ]

are left untouched, which may well be what some people would want,
whereas if my search replace operations leave:

[2007-11-12 xxx]

then they will be updated. And if I want the former style stamps
updated, your code is clear enough that (even!) I can see how to adjust
it.

Thanks again.

-- 
Chris Randle

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Converting dates to org-mode dates
  2007-11-12 13:20 Converting dates to org-mode dates Chris Randle
  2007-11-12 13:30 ` Rainer Stengele
@ 2007-11-12 15:02 ` Bastien
  2007-11-12 14:45   ` Chris Randle
  1 sibling, 1 reply; 4+ messages in thread
From: Bastien @ 2007-11-12 15:02 UTC (permalink / raw)
  To: emacs-orgmode

"Chris Randle" <chris@amlog.co.uk> writes:

> [2007-11-12 Tue] (should be Mon)
>
> As far as I can see, that will stay like this until the date is shifted
> in some way.
>
> Is there any way to parse an entire region/buffer for Org-mode dates and
> refresh their day of the week text?

Maybe you can try this (not heavily tested):

(defun my-update-day-name-in-inactive-time-stamps ()
  "Update the abbreviate day name in inactive time-stamps."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward 
	    "\\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)\\( [a-z]+\\)\\]" nil t)
      (let* ((date (match-string 1))
	     (day (format-time-string
		   "%a"
		   (apply 'encode-time 
			  (save-match-data (org-parse-time-string date))))))
	(replace-match (concat "[" date " " day "]") t t)))))

-- 
Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-11-12 14:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-12 13:20 Converting dates to org-mode dates Chris Randle
2007-11-12 13:30 ` Rainer Stengele
2007-11-12 15:02 ` Bastien
2007-11-12 14:45   ` Chris Randle

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).