* parsing time stamp
@ 2008-05-22 18:25 Xah
2008-05-22 18:46 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Xah @ 2008-05-22 18:25 UTC (permalink / raw)
To: help-gnu-emacs
is there a function that parses a timestamp like “Monday, Nov. 28,
1994” so that i can write a function to turn it into the format yyyy-
mm-dd?
Thanks in advance.
Xah
xah@xahlee.org
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: parsing time stamp
2008-05-22 18:25 parsing time stamp Xah
@ 2008-05-22 18:46 ` Drew Adams
2008-05-22 19:51 ` David Hansen
2008-05-22 21:49 ` Johan Bockgård
2 siblings, 0 replies; 6+ messages in thread
From: Drew Adams @ 2008-05-22 18:46 UTC (permalink / raw)
To: 'Xah', help-gnu-emacs
> is there a function that parses a timestamp like "Monday, Nov. 28,
> 1994" so that i can write a function to turn it into the format yyyy-
> mm-dd?
It would be useful, but I don't think so.
See thread "regexp to match formatted time string?" in emacs-devel@gnu.org,
2008-02-01:
http://lists.gnu.org/archive/html/emacs-devel/2008-02/msg00060.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: parsing time stamp
2008-05-22 18:25 parsing time stamp Xah
2008-05-22 18:46 ` Drew Adams
@ 2008-05-22 19:51 ` David Hansen
2008-05-22 21:49 ` Johan Bockgård
2 siblings, 0 replies; 6+ messages in thread
From: David Hansen @ 2008-05-22 19:51 UTC (permalink / raw)
To: help-gnu-emacs
On Thu, 22 May 2008 11:25:08 -0700 (PDT) Xah wrote:
> is there a function that parses a timestamp like “Monday, Nov. 28,
> 1994” so that i can write a function to turn it into the format yyyy-
> mm-dd?
I'm pretty sure there is such a function in Gnus and Emacs-w3m.
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: parsing time stamp
2008-05-22 18:25 parsing time stamp Xah
2008-05-22 18:46 ` Drew Adams
2008-05-22 19:51 ` David Hansen
@ 2008-05-22 21:49 ` Johan Bockgård
2008-05-23 4:17 ` Kevin Rodgers
2 siblings, 1 reply; 6+ messages in thread
From: Johan Bockgård @ 2008-05-22 21:49 UTC (permalink / raw)
To: help-gnu-emacs
Xah <xahlee@gmail.com> writes:
> is there a function that parses a timestamp like “Monday, Nov. 28,
> 1994” so that i can write a function to turn it into the format yyyy-
> mm-dd?
parse-time-string
--
Johan Bockgård
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: parsing time stamp
2008-05-22 21:49 ` Johan Bockgård
@ 2008-05-23 4:17 ` Kevin Rodgers
2008-05-23 4:47 ` Kevin Rodgers
0 siblings, 1 reply; 6+ messages in thread
From: Kevin Rodgers @ 2008-05-23 4:17 UTC (permalink / raw)
To: help-gnu-emacs
Johan Bockgård wrote:
> Xah <xahlee@gmail.com> writes:
>
>> is there a function that parses a timestamp like “Monday, Nov. 28,
>> 1994” so that i can write a function to turn it into the format yyyy-
>> mm-dd?
>
> parse-time-string
(parse-time-string "Monday, Nov. 28, 1994")
=> (nil nil nil 28 11 1994 nil nil nil)
Odd that the leading "Monday, " yields nil DOW... It turns out that is
due to the fact that the parse-time-weekdays variable only has
abbreviations (e.g. "mon"), just like parse-time-months. Easy to fix:
(let ((parse-time-weekdays (append parse-time-weekdays
'(("sunday" . 0)
("monday" . 1)
("tuesday" . 2)
("wednesday" . 3)
("thursday" . 4)
("friday" . 5)
("saturday" . 6)))))
(parse-time-string "Monday, Nov. 28, 1994"))
=> (nil nil nil 28 11 1994 1 nil nil)
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: parsing time stamp
2008-05-23 4:17 ` Kevin Rodgers
@ 2008-05-23 4:47 ` Kevin Rodgers
0 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2008-05-23 4:47 UTC (permalink / raw)
To: help-gnu-emacs
Kevin Rodgers wrote:
> Johan Bockgård wrote:
>> Xah <xahlee@gmail.com> writes:
>>
>>> is there a function that parses a timestamp like “Monday, Nov. 28,
>>> 1994” so that i can write a function to turn it into the format yyyy-
>>> mm-dd?
>>
>> parse-time-string
>
> (parse-time-string "Monday, Nov. 28, 1994")
> => (nil nil nil 28 11 1994 nil nil nil)
>
> Odd that the leading "Monday, " yields nil DOW... It turns out that is
> due to the fact that the parse-time-weekdays variable only has
> abbreviations (e.g. "mon"), just like parse-time-months. Easy to fix:
>
> (let ((parse-time-weekdays (append parse-time-weekdays
> '(("sunday" . 0)
> ("monday" . 1)
> ("tuesday" . 2)
> ("wednesday" . 3)
> ("thursday" . 4)
> ("friday" . 5)
> ("saturday" . 6)))))
> (parse-time-string "Monday, Nov. 28, 1994"))
> => (nil nil nil 28 11 1994 1 nil nil)
That reminds me of a hack I put together a few years ago, to generate a
list of both day names and abbreviations, which are sensitive to the
locale:
(let ((year (string-to-number (format-time-string "%Y")))
(month (string-to-number (format-time-string "%m"))))
(apply 'nconc
(mapcar (lambda (time)
(list (format-time-string "%a." time)
(format-time-string "%A" time)))
(sort (mapcar (lambda (day)
(encode-time 0 0 0 day month year 0))
'(1 2 3 4 5 6 7))
;; by day of week:
(lambda (time-1 time-2)
(< (nth 6 (decode-time time-1))
(nth 6 (decode-time time-2))))))))
Perhaps that could be incorporated into the initial value of
parse-time-weekdays to handle localized time strings. There's also a
corresponding hack for month names and abbreviations (parse-time-months):
(let ((year (string-to-number (format-time-string "%Y"))))
(apply 'nconc
(mapcar (lambda (month)
(let ((first (encode-time 0 0 0 1 month year 0)))
(list (format-time-string "%b." first t)
(format-time-string "%B" first t))))
'(1 2 3 4 5 6 7 8 9 10 11 12))))
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-05-23 4:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-22 18:25 parsing time stamp Xah
2008-05-22 18:46 ` Drew Adams
2008-05-22 19:51 ` David Hansen
2008-05-22 21:49 ` Johan Bockgård
2008-05-23 4:17 ` Kevin Rodgers
2008-05-23 4:47 ` Kevin Rodgers
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.