unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: help-gnu-emacs@gnu.org
Subject: Re: parsing a date
Date: Fri, 28 Sep 2012 11:20:48 +0800	[thread overview]
Message-ID: <874nmiltnz.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 87fw62eu7m.fsf@wanadoo.es

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	other threads:[~2012-09-28  3:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-28  2:07 parsing a date Eric Abrahamsen
2012-09-28  2:50 ` Óscar Fuentes
2012-09-28  3:20   ` Eric Abrahamsen [this message]
2012-09-28  4:14     ` Óscar Fuentes
2012-09-28  6:11       ` Eric Abrahamsen
     [not found]       ` <mailman.9889.1348812706.855.help-gnu-emacs@gnu.org>
2012-10-14  1:51         ` David Combs
2012-10-14  7:18           ` Eric Abrahamsen
     [not found] ` <mailman.9886.1348800663.855.help-gnu-emacs@gnu.org>
2012-09-29 17:00   ` Stefan Monnier
     [not found] <mailman.9885.1348798043.855.help-gnu-emacs@gnu.org>
2012-12-02  7:25 ` WJ
2012-12-23  5:55   ` Eric Abrahamsen
2012-12-24  0:39     ` ken
2012-12-24  3:02       ` Eric Abrahamsen
2012-12-24  3:54         ` ken

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874nmiltnz.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).