all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Can `format-time-string' produce full/extended ISO 8601 times?
@ 2009-07-30 22:10 MON KEY
  2009-08-02 23:52 ` Juri Linkov
  0 siblings, 1 reply; 5+ messages in thread
From: MON KEY @ 2009-07-30 22:10 UTC (permalink / raw)
  To: emacs-devel

Does `format-time-string' produce full/extended ISO 8601 format times?

-
Docstring of `format-time-string' states:

 "For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z"."

As best I can gather this is _not_ a 'full' ISO 8601 time string format.
Specifically, section 4.2.5.1-2 of ISO 8601:2004(E)

--
4.2.5.1 Difference between local time and UTC of day

Basic format:      ±hhmm             Example: +0100
                     ±hh                      +01

Extended format:   ±hh:mm            Example: +01:00

--
4.2.5.2 Local time and the difference from UTC

Basic format:      hhmmss±hhmm       Example: 152746+0100
                                              152746−0500
                   hhmmss±hh                  152746+01
                                              152746−05

Extended format:   hh:mm:ss±hh:mm    Example: 15:27:46+01:00
                                              15:27:46−05:00
                   hh:mm:ss±hh                15:27:46+01
                                              15:27:46−05

---
I am referencing from the .pdf available here:
(URL `http://isotc.iso.org/livelink/livelink/4021199/ISO_8601_2004_E.zip?func=doc.Fetch&nodeid=4021199')

----
Is it possible to format the UTC offset/ZONE with a colon per the
Extended format above?

On a w32 system I'm get these results:

(format-time-string "%Y-%m-%dT%T%z")
;=>"2009-07-30T18:04:56-0400"

(format-time-string "%Y-%m-%dT%T,%u%z")
;=>"2009-07-30T18:04:36,4-0400"

(format-time-string "%Y-%m-%dT%T,%u%z" nil t)
"2009-07-30T22:05:47,4+0000Z"

(format-time-string "%Y-%m-%dT%T,%u%z" (current-time) t)
;=>"2009-07-30T22:06:10,4+0000"

-----
GNU Emacs 23.1.50.1 (i386-mingw-nt5.1.2600)
 of 2009-06-30 on LENNART-69DE564 (patched)

s_P




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

* Re: Can `format-time-string' produce full/extended ISO 8601 times?
  2009-07-30 22:10 Can `format-time-string' produce full/extended ISO 8601 times? MON KEY
@ 2009-08-02 23:52 ` Juri Linkov
  2009-08-06 18:39   ` MON KEY
  0 siblings, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2009-08-02 23:52 UTC (permalink / raw)
  To: MON KEY; +Cc: emacs-devel

> Does `format-time-string' produce full/extended ISO 8601 format times?
>
> -
> Docstring of `format-time-string' states:
>
>  "For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z"."
>
> As best I can gather this is _not_ a 'full' ISO 8601 time string format.
> Specifically, section 4.2.5.1-2 of ISO 8601:2004(E)
>
> --
> 4.2.5.1 Difference between local time and UTC of day
>
> Basic format:      ±hhmm             Example: +0100
>                      ±hh                      +01
>
> Extended format:   ±hh:mm            Example: +01:00
>
> --
> 4.2.5.2 Local time and the difference from UTC
>
> Basic format:      hhmmss±hhmm       Example: 152746+0100
>                                               152746−0500
>                    hhmmss±hh                  152746+01
>                                               152746−05
>
> Extended format:   hh:mm:ss±hh:mm    Example: 15:27:46+01:00
>                                               15:27:46−05:00
>                    hh:mm:ss±hh                15:27:46+01
>                                               15:27:46−05
>
> ---
> I am referencing from the .pdf available here:
> (URL `http://isotc.iso.org/livelink/livelink/4021199/ISO_8601_2004_E.zip?func=doc.Fetch&nodeid=4021199')
>
> ----
> Is it possible to format the UTC offset/ZONE with a colon per the
> Extended format above?
>
> On a w32 system I'm get these results:
>
> (format-time-string "%Y-%m-%dT%T%z")
> ;=>"2009-07-30T18:04:56-0400"
>
> (format-time-string "%Y-%m-%dT%T,%u%z")
> ;=>"2009-07-30T18:04:36,4-0400"
>
> (format-time-string "%Y-%m-%dT%T,%u%z" nil t)
> "2009-07-30T22:05:47,4+0000Z"
>
> (format-time-string "%Y-%m-%dT%T,%u%z" (current-time) t)
> ;=>"2009-07-30T22:06:10,4+0000"

Do you complain that `format-time-string' uses the extended format for
date/time and the basic format for time zone?  Well, RFC 3339 says:

  Due to ambiguities in ISO 8601, some interpretations had to
  be made.  First, ISO 8601 is not clear if mixtures of basic and
  extended format are permissible.

And provides a grammar that permits mixtures:

  time-numoffset    = ("+" / "-") time-hour [[":"] time-minute]

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: Can `format-time-string' produce full/extended ISO 8601 times?
  2009-08-02 23:52 ` Juri Linkov
@ 2009-08-06 18:39   ` MON KEY
  2009-08-06 18:47     ` Edward O'Connor
  2009-08-06 20:41     ` Juri Linkov
  0 siblings, 2 replies; 5+ messages in thread
From: MON KEY @ 2009-08-06 18:39 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

2009/8/2 Juri Linkov <juri@jurta.org>:
>> Does `format-time-string' produce full/extended ISO 8601 format times?
>
> Do you complain that `format-time-string' uses the extended format for
> date/time and the basic format for time zone?  Well, RFC 3339 says:

Wasn't a complaint at all.

FTMP `format-time-string' does _exactly_ what one would expect.

To reiterate, the gist of my query is this:

  Is it possible to format the UTC offset/ZONE with a colon per the
'Extended format?

From what I am able to gather the "%z" of the `format-time-string'
spec doesn't produce a colon delimited UTC-offset/ZONE and provides
only for production of the time-numoffset as:

+/-time-hourtime-minute -> +/- hhmm  -> "-0500"

To the extent that the standard is unclear/ambiguous, stating that:

'For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z".'

can not be correct as there is no 'full ISO 8601' format; e.g. the
following is not 'full' but only full-ish :)

(format-time-string "%Y-%m-%dT%T%z")
=> "2009-08-06T13:50:23-0400" ; On a w32 system.

This would _appear_ to stand in contrast the referenced section of the
standard, e.g. '4.2.5.1-2 of ISO 8601:2004(E)' which permits at least
two other possible variations:

The 'Basic format' is one of these:

  +/-time-hour            ->  +/-hh     -> "-05"
  +/-time-hourtime-minute ->  +/- hhmm  -> "-0500"

With the later variant of the basic format considered _more_ specific
than the former.

My specific concern is w/re to the standards proviso for an extended
format such that:

  +/-time-hour:time-minute ->  +/- hh:mm  -> "-05:00"

>
>  Due to ambiguities in ISO 8601, some interpretations had to
>  be made.  First, ISO 8601 is not clear if mixtures of basic and
>  extended format are permissible.
>
> And provides a grammar that permits mixtures:
>
>  time-numoffset    = ("+" / "-") time-hour [[":"] time-minute]
>

As you point out, _here_ the standard is ambiguous as to canonical
preference and permissible deviations. That said - as I read the
standard - it would seem that when in doubt the Extended (and where
applicable delimited) format is generally considered _more_ preferable
than the Basic. Regardless, apropos my initial query, whether this
particular reading is correct need not be of concern.  Rather, I
remain curious to know if it is _possible_ to produce a time string
with a UTC/ZONE portion having the format:

 +/-time-hour:time-minute ->  +/- hh:mm  -> "-05:00"  ; _with_ colon delimiter

Specifically, I am inquiring whether such production is possible with
the current existing `format-time-string' (sans extension).

If so, this should be be made clear in the docs. If not, the docs
should be modified to indicate:

'For example, to produce an ISO 8601 compliant format, use "%Y-%m-%dT%T%z".'

as contrasted with the current:

'For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z".'

Further, if a production of UTZ/Zone colon delimited timestring is not
possible and it does not pose significant runtime/source overhead I
would propose consideration for inclusion of an additional "%Z" format
spec to `format-time-string'.

> Juri Linkov

s_P




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

* Re: Can `format-time-string' produce full/extended ISO 8601 times?
  2009-08-06 18:39   ` MON KEY
@ 2009-08-06 18:47     ` Edward O'Connor
  2009-08-06 20:41     ` Juri Linkov
  1 sibling, 0 replies; 5+ messages in thread
From: Edward O'Connor @ 2009-08-06 18:47 UTC (permalink / raw)
  To: MON KEY; +Cc: Juri Linkov, emacs-devel

> From what I am able to gather the "%z" of the `format-time-string'
> spec doesn't produce a colon delimited UTC-offset/ZONE and provides
> only for production of the time-numoffset as:

FWIW, I have the following code or variations thereof sprinkled
throughout several libraries I maintain:

(let ((stamp (format-time-string "%Y-%m-%dT%H:%M:%S%z" time)))
  (format "%s:%s" (substring stamp 0 -2) (substring stamp -2)))

Adding the ability for format-time-string to produce the tz colon
would be great.


Ted




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

* Re: Can `format-time-string' produce full/extended ISO 8601 times?
  2009-08-06 18:39   ` MON KEY
  2009-08-06 18:47     ` Edward O'Connor
@ 2009-08-06 20:41     ` Juri Linkov
  1 sibling, 0 replies; 5+ messages in thread
From: Juri Linkov @ 2009-08-06 20:41 UTC (permalink / raw)
  To: MON KEY; +Cc: emacs-devel

> To reiterate, the gist of my query is this:
>
>   Is it possible to format the UTC offset/ZONE with a colon per the
> 'Extended format?

I looked briefly at the implementation of time formatting in Emacs
and see that it is an old copy of the function `strftime' from gnulib.
I wonder is it possible to call this function directly from the library
where it already has more supported formats including time zones with
a colon:

`%z'
     RFC 2822/ISO 8601 style numeric time zone (e.g., `-0600' or
     `+0530'), or nothing if no time zone is determinable.
     This is a GNU extension.

`%:z'
     RFC 3339/ISO 8601 style numeric time zone with `:' (e.g., `-06:00'
     or `+05:30'), or nothing if no time zone is determinable.  This is
     a GNU extension.

`%::z'
     Numeric time zone to the nearest second with `:' (e.g.,
     `-06:00:00' or `+05:30:00'), or nothing if no time zone is
     determinable.  This is a GNU extension.

`%:::z'
     Numeric time zone with `:' using the minimum necessary precision
     (e.g., `-06', `+05:30', or `-04:56:02'), or nothing if no time
     zone is determinable.  This is a GNU extension.

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

end of thread, other threads:[~2009-08-06 20:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-30 22:10 Can `format-time-string' produce full/extended ISO 8601 times? MON KEY
2009-08-02 23:52 ` Juri Linkov
2009-08-06 18:39   ` MON KEY
2009-08-06 18:47     ` Edward O'Connor
2009-08-06 20:41     ` Juri Linkov

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.