unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Date hacking
@ 2002-08-02 18:58 Michael J. Barillier
  2002-08-02 22:14 ` help sorting diary entries Randy Zelick
  0 siblings, 1 reply; 2+ messages in thread
From: Michael J. Barillier @ 2002-08-02 18:58 UTC (permalink / raw)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Since I'm being so generous (*cough* *cough*), here's another hack I
just used to fix up a file full of dates.  Basically, I wanted to add
the day name to the start of all dates, e.g. change

  2002 August 02

to:

  Friday 2002 August 02

calendar.el didn't have a suitable set of functions for working with
dates in the above format, so I hacked up:

(require 'calendar)

(defun monthname-to-index (monthname)
  "Converts a month name to its numeric (1-based) index."
  (cdr (assoc monthname
              (calendar-make-alist calendar-month-name-array))))

(defconst *bw-preferred-date-fmt-regexp*
  "\\(\\(19\\|20\\)[0-9][0-9]\\) \\([^ ]+\\) \\([0-9]+\\)"
  "My preferred date format, e.g. 2002 August 02.")

(defun ymd->date (ymd)
  "Converts a date formatted as:
  \"YYYY Month DD\"
to a date, as used in most of the `calendar.el' functions, i.e. a
list `(m d y)'."
  (save-match-data
    (when (string-match *bw-preferred-date-fmt-regexp* ymd)
      (list (monthname-to-index (match-string 3 ymd))
            (string-to-number (match-string 4 ymd))
            (string-to-number (match-string 1 ymd))))))

(defun fix-dates-in-region (start end)
  "Prefixes dates in the region with the day name.  Should have a
closure parameter or use a closure var or something to allow other
fix-ups ... but this is a hack."
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region start end)
      (goto-char (point-min))
      (condition-case nil
          (while t
            (re-search-forward *bw-preferred-date-fmt-regexp*)
            (let ((date (ymd->date (match-string 0))))
              (replace-match (concat
                              (elt calendar-day-name-array
                                   (calendar-day-of-week date))
                              " "
                              (match-string 0))))
            (goto-char (match-end 0)))
        (error (message "That's all, folks."))))))

- -- 
Michael J. Barillier
(let ((n "blackwolf") (h "pcisys.net")) (concatenate 'string n "@" h))
GnuPG public key ID: 0x35E54973
Fingerprint: EDB9 4FBC 4D0B 070C C0E3 2EE4 D822 78CE 35E5 4973
Knowledge shared is power lost. -- Aleister Crowley
Got a job lead?  Email me--will code for food.  Resume at:
  <http://www.pcisys.net/~blackwolf/resume/>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9StY72CJ4zjXlSXMRAhdXAJ4jApliIvx6SSZudGGDZiLaiFHxJwCgkLDQ
RXs+LkTYtVyHAkBGYh383AY=
=5i+Z
-----END PGP SIGNATURE-----

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

* help sorting diary entries
  2002-08-02 18:58 Date hacking Michael J. Barillier
@ 2002-08-02 22:14 ` Randy Zelick
  0 siblings, 0 replies; 2+ messages in thread
From: Randy Zelick @ 2002-08-02 22:14 UTC (permalink / raw)



Well I am a new user so this may be pretty basic but...

I copied all the stuff below into my .emacs file from a couple of sources,
and according to the documentation I read appointments should be sorted
according to the time of day. Indeed, they are sorted but without regard
to AM or PM. That is, a 4:00 PM entry will appear in the fancy diary
buffer before an 11:00 AM entry. Maybe this is asking too much, but
various docs claim that emacs knows how to handle AM and PM. 

Suggestions??

Thanks,

=Randy=



excerpt from my .emacs file:


;
(setq display-time-day-and-date t)
(display-time) ; show time of day on modeline
(add-hook 'diary-display-hook 'fancy-diary-display)
(add-hook 'diary-hook 'appt-make-list)
(diary 0)
(setq mark-diary-entries-in-calendar t)
(setq view-diary-entries-initially t)
(setq diary-list-include-blanks t)
(add-hook 'list-diary-entries-hook 'sort-diary-entries t) 
(add-hook 'today-visible-calendar-hook 'calendar-mark-today) 
(calendar) 
;

-- 
R. Zelick				email: zelickr@pdx.edu
Department of Biology			voice: 503-725-3086
Portland State University		fax:   503-725-3888

mailing:
P.O. Box 751
Portland, OR 97207

shipping:
1719 SW 10th Ave, Room 246
Portland, OR 97201

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

end of thread, other threads:[~2002-08-02 22:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-02 18:58 Date hacking Michael J. Barillier
2002-08-02 22:14 ` help sorting diary entries Randy Zelick

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).