help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parsing a date


From: Eric Abrahamsen
Subject: Re: parsing a date
Date: Fri, 28 Sep 2012 11:20:48 +0800
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2.50 (gnu/linux)

On Fri, Sep 28 2012, Óscar Fuentes wrote:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> I'm reading in files with dates in this format: "2011-11-25". I need to
>> write them out as "2011/11/25". Instead of just manhandling the strings
>> (I'll likely need this date information in other places) I wanted to
>> parse the strings into proper date objects, then format them back into
>> strings.
>
> Why? Once you have the date components, you only need to write them
> separated by /
>
> Or just replace - with / on the original date string.

As I mention, this is on the first step, and I'll likely need the dates
in a few other contexts as well. I suppose you're right, though -- I can
just use the elements of the list returned by parse-time-string.

>> `date-to-time' doesn't work because (parse-time-string
>> "2011-11-15") gives me:
>>
>> (nil nil nil 15 11 2011 nil nil nil)
>>
>> Which is not acceptable to `encode-time', because it requires integers,
>> not nil. I can't believe this is quite this complicated: do I really
>> have to replace all the nils with 0 myself?
>
> (mapcar (lambda (x) (if x x 0)) (parse-time-string "2011-11-15"))

Sure, it's doable, but it just seems odd that `parse-time-string'
returns a structure that `encode-time' can't read!

E

-- 
GNU Emacs 24.2.50.1 (i686-pc-linux-gnu, GTK+ Version 3.4.4)
 of 2012-09-16 on pellet




reply via email to

[Prev in Thread] Current Thread [Next in Thread]