[
Lists Home |
Date Index |
Thread Index
]
- From: Toby Speight <tms@ansa.co.uk>
- To: "XML developers' list" <xml-dev@ic.ac.uk>
- Date: 09 Jul 1998 10:38:03 +0100
Andrew> Andrew Layman <URL:mailto:andrewl@microsoft.com>
=> In article
=> <5BF896CAFE8DD111812400805F1991F7038CA586@red-msg-08.dns.microsoft.com>,
=> Andrew wrote:
Andrew> Regarding the difficulty of writing a parser for arbitrary date formats, we
Andrew> propose using only one date format, specifically a profile of ISO 8601.
Andrew> This greatly aids interoperability.
In one document type of my own, I use IS-8601 for dates, using the
"yyyy-mm-dd" profile; dd and possibly also mm may be omitted for
reduced precision.
Andrew> Andrew Layman <andrewl@microsoft.com> wrote (in part):
Andrew>
Andrew> One thing I notice in the example shown below is that the
Andrew> element contains the date twice, once in an easily-parsed
Andrew> form, once in what appears to be a display form. I would
Andrew> hope that the parsable form is all that is needed, with an
Andrew> application able to produce the appropriate display when
Andrew> needed.
Andrew>
Andrew> <some-date-element type="ISO 8601" value="19980708">July
Andrew> 8, 1998</some-date-value>
Andrew>
Andrew> While it is easy for an application (written in a
Andrew> Turing-complete language) to go from a canonical date
Andrew> representation to some (presumably localized) pretty-printed
Andrew> version, it is not clear to me how you would do this with the
Andrew> standard *ML style sheet mechanisms (either CSS or XSL).
Perhaps you could port the DSSSL code from the stylesheet I use with
the XML I mentioned earlier (CSS isn't expressive enough; I don't know
enough about XSL):
;; given a date string of the form "yyyy[-mm[-dd]]", return an
;; English-local string "[[dd ]Month ]yyyy"
(define (PRETTY-DATE x)
(if (not (string? x))
(node-list-error (string-append "Bad or missing date attribute") (current-node))
(let ((year (cond ((< (string-length x) 4)
(node-list-error (string-append "Bad date (YYYY): \"" x "\"") (current-node)))
(#t (substring x 0 4))))
(month (cond ((< (string-length x) 5)
"--")
((not (char=? #\- (string-ref x 4)))
(node-list-error (string-append "Bad date (YYYY-): \"" x "\"") (current-node)))
((< (string-length x) 7)
(node-list-error (string-append "Bad date (YYYY-MM): \"" x "\"") (current-node)))
(#t (substring x 5 7))))
(day (cond ((< (string-length x) 8)
"--")
((not (char=? #\- (string-ref x 7)))
(node-list-error (string-append "Bad date (YYYY-MM-): \"" x "\"") (current-node)))
((< (string-length x) 10)
(node-list-error (string-append "Bad date (YYYY-MM-DD): \"" x "\"") (current-node)))
(#t (substring x 8 10)))))
(string-append
(case day
(("--") "")
(else (string-append (number->string (string->number day)) " ")))
(case month
(("--") "")
(("01") "January ") (("02") "February ") (("03") "March " ) (("04") "April ")
(("05") "May ") (("06") "June ") (("07") "July ") (("08") "August ")
(("09") "September ") (("10") "October ") (("11") "November ") (("12") "December ")
(else (node-list-error (string-append "Bad month: \"" month "\"") (current-node))))
year))))
Andrew> The benefit of the sample syntax is that the element content
Andrew> would be apparent, for example, to any HTML browser that
Andrew> latched on to it and which followed the rule that unknown
Andrew> tags are ignored, but their contents are processed.
Another advantage is that one may specify the date/time using
completely arbitrary natural language, eg
<!ATTLIST date
date CDATA #REQUIRED
type NMTOKEN "IS-8601">
<date date="1999-04-02">Good Friday</date>
OTOH, there's the disadvantage that there's nothing to stop people
using ambiguous formats such as 2/4/99 in the free text (though you
might be able to catch some of these automatically).
--
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)
|