all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Question about parse-time-string and date-to-time
@ 2017-03-29 21:01 Eric Abrahamsen
  2017-03-29 21:18 ` Eric Abrahamsen
  2017-03-29 22:14 ` John Mastro
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Abrahamsen @ 2017-03-29 21:01 UTC (permalink / raw)
  To: help-gnu-emacs

A conundrum:

parse-time-string accepts a string representing a date, and parses it
into a list of time elements, with nil for the unknowns.

date-to-time calls parse-time-string and passes the result straight to
encode-time, to produce a time value.

encode-time accepts series of time elements, and raises an error if any
of them are nil.

I might be missing something, but I don't see how date-to-time could
ever work. Wouldn't it always have to replace the nils with zeros before
passing the result to encode time?

Eric




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

* Re: Question about parse-time-string and date-to-time
  2017-03-29 21:01 Question about parse-time-string and date-to-time Eric Abrahamsen
@ 2017-03-29 21:18 ` Eric Abrahamsen
  2017-03-29 22:14 ` John Mastro
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Abrahamsen @ 2017-03-29 21:18 UTC (permalink / raw)
  To: help-gnu-emacs

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> A conundrum:
>
> parse-time-string accepts a string representing a date, and parses it
> into a list of time elements, with nil for the unknowns.
>
> date-to-time calls parse-time-string and passes the result straight to
> encode-time, to produce a time value.
>
> encode-time accepts series of time elements, and raises an error if any
> of them are nil.
>
> I might be missing something, but I don't see how date-to-time could
> ever work. Wouldn't it always have to replace the nils with zeros before
> passing the result to encode time?

Or maybe time elements with nils for any of day/month/year are simply
considered invalid? 




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

* Re: Question about parse-time-string and date-to-time
  2017-03-29 21:01 Question about parse-time-string and date-to-time Eric Abrahamsen
  2017-03-29 21:18 ` Eric Abrahamsen
@ 2017-03-29 22:14 ` John Mastro
  2017-03-29 23:12   ` Eric Abrahamsen
  1 sibling, 1 reply; 4+ messages in thread
From: John Mastro @ 2017-03-29 22:14 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org; +Cc: Eric Abrahamsen

Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
> A conundrum:
>
> parse-time-string accepts a string representing a date, and parses it
> into a list of time elements, with nil for the unknowns.
>
> date-to-time calls parse-time-string and passes the result straight to
> encode-time, to produce a time value.
>
> encode-time accepts series of time elements, and raises an error if any
> of them are nil.
>
> I might be missing something, but I don't see how date-to-time could
> ever work. Wouldn't it always have to replace the nils with zeros before
> passing the result to encode time?

It looks like, if the first call to `encode-time' signals an error, it
re-tries using the result of calling `timezone-make-date-arpa-standard'
on the original DATE argument:

    (defun date-to-time (date)
      (condition-case err
          (apply 'encode-time (parse-time-string date))
        (error
         ;; ...
         (apply 'encode-time
                (parse-time-string
                 (timezone-make-date-arpa-standard date)))
         ;; ...
         )))

I was not familiar with `timezone-make-date-arpa-standard', and am not
familiar with "arpanet standard date" as a concept. It seems to
guarantee that some valid date string will be returned, but not
necessarily the one I would have guessed when time information is
missing:

    (timezone-make-date-arpa-standard "2017-03-29 3:05:00")
    ;=> "28 Mar 2017 20:05:00 -0700"
    (timezone-make-date-arpa-standard "2017-03-29")
    ;=> "31 Dec 1999 16:00:00 -0800"
    (timezone-make-date-arpa-standard "3/29/2016")
    ;=> "31 Dec 1999 16:00:00 -0800"

And sure enough:

    (equal (date-to-time "2017-03-29")
           (date-to-time "31 Dec 1999 16:00:00 -0800"))
    ;=> t

So it seems like it returns an arbitrary date if time elements are
missing?

        John



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

* Re: Question about parse-time-string and date-to-time
  2017-03-29 22:14 ` John Mastro
@ 2017-03-29 23:12   ` Eric Abrahamsen
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Abrahamsen @ 2017-03-29 23:12 UTC (permalink / raw)
  To: help-gnu-emacs

John Mastro <john.b.mastro@gmail.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>> A conundrum:
>>
>> parse-time-string accepts a string representing a date, and parses it
>> into a list of time elements, with nil for the unknowns.
>>
>> date-to-time calls parse-time-string and passes the result straight to
>> encode-time, to produce a time value.
>>
>> encode-time accepts series of time elements, and raises an error if any
>> of them are nil.
>>
>> I might be missing something, but I don't see how date-to-time could
>> ever work. Wouldn't it always have to replace the nils with zeros before
>> passing the result to encode time?
>
> It looks like, if the first call to `encode-time' signals an error, it
> re-tries using the result of calling `timezone-make-date-arpa-standard'
> on the original DATE argument:
>
>     (defun date-to-time (date)
>       (condition-case err
>           (apply 'encode-time (parse-time-string date))
>         (error
>          ;; ...
>          (apply 'encode-time
>                 (parse-time-string
>                  (timezone-make-date-arpa-standard date)))
>          ;; ...
>          )))
>
> I was not familiar with `timezone-make-date-arpa-standard', and am not
> familiar with "arpanet standard date" as a concept. It seems to
> guarantee that some valid date string will be returned, but not
> necessarily the one I would have guessed when time information is
> missing:
>
>     (timezone-make-date-arpa-standard "2017-03-29 3:05:00")
>     ;=> "28 Mar 2017 20:05:00 -0700"
>     (timezone-make-date-arpa-standard "2017-03-29")
>     ;=> "31 Dec 1999 16:00:00 -0800"
>     (timezone-make-date-arpa-standard "3/29/2016")
>     ;=> "31 Dec 1999 16:00:00 -0800"
>
> And sure enough:
>
>     (equal (date-to-time "2017-03-29")
>            (date-to-time "31 Dec 1999 16:00:00 -0800"))
>     ;=> t
>
> So it seems like it returns an arbitrary date if time elements are
> missing?

That's what I've found. If parse-time-string returns any nil values,
then you get 31 Dec, 1999. I'd rather get an error!




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

end of thread, other threads:[~2017-03-29 23:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-29 21:01 Question about parse-time-string and date-to-time Eric Abrahamsen
2017-03-29 21:18 ` Eric Abrahamsen
2017-03-29 22:14 ` John Mastro
2017-03-29 23:12   ` Eric Abrahamsen

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.