all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* parsing a date
@ 2012-09-28  2:07 Eric Abrahamsen
  2012-09-28  2:50 ` Óscar Fuentes
       [not found] ` <mailman.9886.1348800663.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 13+ messages in thread
From: Eric Abrahamsen @ 2012-09-28  2:07 UTC (permalink / raw)
  To: help-gnu-emacs

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. `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?

Any pointers gratefully accepted,

Eric

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




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

* Re: parsing a date
  2012-09-28  2:07 Eric Abrahamsen
@ 2012-09-28  2:50 ` Óscar Fuentes
  2012-09-28  3:20   ` Eric Abrahamsen
       [not found] ` <mailman.9886.1348800663.855.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 13+ messages in thread
From: Óscar Fuentes @ 2012-09-28  2:50 UTC (permalink / raw)
  To: Eric Abrahamsen, help-gnu-emacs

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.

> `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"))



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

* Re: parsing a date
  2012-09-28  2:50 ` Óscar Fuentes
@ 2012-09-28  3:20   ` Eric Abrahamsen
  2012-09-28  4:14     ` Óscar Fuentes
  0 siblings, 1 reply; 13+ messages in thread
From: Eric Abrahamsen @ 2012-09-28  3:20 UTC (permalink / raw)
  To: help-gnu-emacs

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




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

* Re: parsing a date
  2012-09-28  3:20   ` Eric Abrahamsen
@ 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>
  0 siblings, 2 replies; 13+ messages in thread
From: Óscar Fuentes @ 2012-09-28  4:14 UTC (permalink / raw)
  To: help-gnu-emacs

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

>>> 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!

I guess that the designers chose to differenciate among `zero' and `not
specified' on the output of parse-time-string.

As for `encode-time', it takes each date-time component as an argument,
not the output of parse-time-string, which is a list. OTOH,
`encode-time' could interpret arguments with value `nil' as `zero'.




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

* Re: parsing a date
  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>
  1 sibling, 0 replies; 13+ messages in thread
From: Eric Abrahamsen @ 2012-09-28  6:11 UTC (permalink / raw)
  To: help-gnu-emacs

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

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>>>> 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!
>
> I guess that the designers chose to differenciate among `zero' and `not
> specified' on the output of parse-time-string.
>
> As for `encode-time', it takes each date-time component as an argument,
> not the output of parse-time-string, which is a list. OTOH,
> `encode-time' could interpret arguments with value `nil' as `zero'.

I'm also heard of something like this in the works:

(read-time-string "%Y-%m-%d" "2011-11-15")

Where you inform emacs of the format of your incoming strings -- that
seems like it would be more than enough for the sort of thing I'm doing.

E

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




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

* Re: parsing a date
       [not found] ` <mailman.9886.1348800663.855.help-gnu-emacs@gnu.org>
@ 2012-09-29 17:00   ` Stefan Monnier
  0 siblings, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2012-09-29 17:00 UTC (permalink / raw)
  To: help-gnu-emacs

> (mapcar (lambda (x) (if x x 0)) (parse-time-string "2011-11-15"))

(if X X Y) => (or X Y)


        Stefan


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

* Re: parsing a date
       [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
  0 siblings, 1 reply; 13+ messages in thread
From: David Combs @ 2012-10-14  1:51 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.9889.1348812706.855.help-gnu-emacs@gnu.org>,
Eric Abrahamsen  <eric@ericabrahamsen.net> wrote:
>
>I'm also heard of something like this in the works:
>
>(read-time-string "%Y-%m-%d" "2011-11-15")
>
>Where you inform emacs of the format of your incoming strings -- that
>seems like it would be more than enough for the sort of thing I'm doing.
>
>E

In the works where, and when?

David




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

* Re: parsing a date
  2012-10-14  1:51         ` David Combs
@ 2012-10-14  7:18           ` Eric Abrahamsen
  0 siblings, 0 replies; 13+ messages in thread
From: Eric Abrahamsen @ 2012-10-14  7:18 UTC (permalink / raw)
  To: help-gnu-emacs

On Sun, Oct 14 2012, David Combs wrote:

> In article <mailman.9889.1348812706.855.help-gnu-emacs@gnu.org>,
> Eric Abrahamsen  <eric@ericabrahamsen.net> wrote:
>>
>>I'm also heard of something like this in the works:
>>
>>(read-time-string "%Y-%m-%d" "2011-11-15")
>>
>>Where you inform emacs of the format of your incoming strings -- that
>>seems like it would be more than enough for the sort of thing I'm doing.
>>
>>E
>
> In the works where, and when?

I believe it's this: http://www.emacswiki.org/emacs-zh/StrPTime

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




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

* Re: parsing a date
       [not found] <mailman.9885.1348798043.855.help-gnu-emacs@gnu.org>
@ 2012-12-02  7:25 ` WJ
  2012-12-23  5:55   ` Eric Abrahamsen
  0 siblings, 1 reply; 13+ messages in thread
From: WJ @ 2012-12-02  7:25 UTC (permalink / raw)
  To: help-gnu-emacs

Eric Abrahamsen wrote:

> 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. `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?
> 
> Any pointers gratefully accepted,
> 
> Eric

(format-time-string "%Y/%m/%d"
  (apply 'encode-time 0 0 0
    (nthcdr 3 (parse-time-string "2011-11-15"))))

==> "2011/11/15"


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

* Re: parsing a date
  2012-12-02  7:25 ` parsing a date WJ
@ 2012-12-23  5:55   ` Eric Abrahamsen
  2012-12-24  0:39     ` ken
  0 siblings, 1 reply; 13+ messages in thread
From: Eric Abrahamsen @ 2012-12-23  5:55 UTC (permalink / raw)
  To: help-gnu-emacs

"WJ" <w_a_x_man@yahoo.com> writes:

> Eric Abrahamsen wrote:
>
>> 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. `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?
>> 
>> Any pointers gratefully accepted,
>> 
>> Eric
>
> (format-time-string "%Y/%m/%d"
>   (apply 'encode-time 0 0 0
>     (nthcdr 3 (parse-time-string "2011-11-15"))))
>
> ==> "2011/11/15"

Only just saw this -- thanks very much!




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

* Re: parsing a date
  2012-12-23  5:55   ` Eric Abrahamsen
@ 2012-12-24  0:39     ` ken
  2012-12-24  3:02       ` Eric Abrahamsen
  0 siblings, 1 reply; 13+ messages in thread
From: ken @ 2012-12-24  0:39 UTC (permalink / raw)
  Cc: help-gnu-emacs

On 12/23/2012 12:55 AM Eric Abrahamsen wrote:
> (format-time-string "%Y/%m/%d"
>>     (apply 'encode-time 0 0 0
>>       (nthcdr 3 (parse-time-string "2011-11-15"))))

Nice.  I was wanting to do something very close to this awhile back.  Of 
course the above code is more useful in the context of a function, 
something like the below-- which has something missing.  What?

(setq ddd "2013-02-11.tail")  ;Want to remove tail on string also

(defun ddd
(format-time-string "%A, %B %d, %Y"
    (apply 'encode-time 0 0 0
	  (nthcdr 3 (parse-time-string ddd)))))




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

* Re: parsing a date
  2012-12-24  0:39     ` ken
@ 2012-12-24  3:02       ` Eric Abrahamsen
  2012-12-24  3:54         ` ken
  0 siblings, 1 reply; 13+ messages in thread
From: Eric Abrahamsen @ 2012-12-24  3:02 UTC (permalink / raw)
  To: help-gnu-emacs

ken <gebser@mousecar.com> writes:

> On 12/23/2012 12:55 AM Eric Abrahamsen wrote:
>> (format-time-string "%Y/%m/%d"
>>>     (apply 'encode-time 0 0 0
>>>       (nthcdr 3 (parse-time-string "2011-11-15"))))
>
> Nice.  I was wanting to do something very close to this awhile back.
> Of course the above code is more useful in the context of a function,
> something like the below-- which has something missing.  What?
>
> (setq ddd "2013-02-11.tail")  ;Want to remove tail on string also
>
> (defun ddd
> (format-time-string "%A, %B %d, %Y"
>    (apply 'encode-time 0 0 0
> 	  (nthcdr 3 (parse-time-string ddd)))))

I suppose this?

--8<---------------cut here---------------start------------->8---
(defun ddd (s)
  (format-time-string "%Y/%m/%d"
    (apply 'encode-time 0 0 0
      (nthcdr 3 (parse-time-string
		 (replace-regexp-in-string "\.tail" "" s))))))
--8<---------------cut here---------------end--------------->8---




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

* Re: parsing a date
  2012-12-24  3:02       ` Eric Abrahamsen
@ 2012-12-24  3:54         ` ken
  0 siblings, 0 replies; 13+ messages in thread
From: ken @ 2012-12-24  3:54 UTC (permalink / raw)
  To: help-gnu-emacs

On 12/23/2012 10:02 PM Eric Abrahamsen wrote:
> ken<gebser@mousecar.com>  writes:
>....
>
> --8<---------------cut here---------------start------------->8---
> (defun ddd (s)
>    (format-time-string "%Y/%m/%d"
>      (apply 'encode-time 0 0 0
>        (nthcdr 3 (parse-time-string
> 		 (replace-regexp-in-string "\.tail" "" s))))))
> --8<---------------cut here---------------end--------------->8---

That works.  Thanks much.





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

end of thread, other threads:[~2012-12-24  3:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.9885.1348798043.855.help-gnu-emacs@gnu.org>
2012-12-02  7:25 ` parsing a date 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
2012-09-28  2:07 Eric Abrahamsen
2012-09-28  2:50 ` Óscar Fuentes
2012-09-28  3:20   ` Eric Abrahamsen
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

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.