implement exslt-date:date-time()

RESOLVED FIXED

Status

()

Core
XSLT
--
enhancement
RESOLVED FIXED
7 years ago
6 years ago

People

(Reporter: Julian Reschke, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(URL)

Attachments

(1 attachment, 3 obsolete attachments)

(Reporter)

Description

7 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 (.NET CLR 3.5.30729)
Build Identifier: 3.6.10

The EXSLT date-time module contains many functions (http://www.exslt.org/date/index.html). However, implementing just date-time() out of these would be very useful, because it enables XSLTs to get the current system date (something that currently can't done at all).

Reproducible: Always

Steps to Reproduce:
Navigate to http://greenbytes.de/tech/webdav/xslt-test.xml
Actual Results:  
"Date-Time Support

exslt:date-time(): No"

Expected Results:  
"Date-Time Support

exslt:date-time(): Yes, and returns: 2010-10-10T09:40:29.095+01:00"

(with the current date)
(Reporter)

Comment 1

7 years ago
Created attachment 482123 [details] [diff] [review]
implementation of exslt:date-time()

1) the string handling probably should be double-checked

2) is there a canonical place for a test case?
(Reporter)

Updated

7 years ago
Attachment #482123 - Flags: review?(peterv)
Status: UNCONFIRMED → NEW
Ever confirmed: true
Having date-time() would certainly be useful.  I hope it can happen.
(Reporter)

Comment 3

6 years ago
Any chance to get this into FF5?
(Reporter)

Comment 4

6 years ago
Created attachment 524949 [details] [diff] [review]
implementation of exslt:date-time(), plus a minimal test case

The test case is very minimal in that it only compares the prefix of the generated string (the year), but at least the extension function gets called.
Attachment #482123 - Attachment is obsolete: true
Attachment #524949 - Flags: review?(jonas)
Attachment #482123 - Flags: review?(peterv)
Use nsPrintfCString and CopyASCIItoUTF16 instead (yes, our string classes are not easy to use).

You can see how the generate-id function is implemented here:

http://mxr.mozilla.org/mozilla-central/source/content/xslt/src/xslt/txGenerateIdFunctionCall.cpp?force=1#83
http://mxr.mozilla.org/mozilla-central/source/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp#616

Also, is the string returned from this function parsable using the Date object in javascript? If so, it might be nicer to do so and check that the difference to Date.now() is less than, say, 30 minutes.
Attachment #524949 - Flags: review?(jonas) → review-
(Reporter)

Comment 6

6 years ago
(In reply to comment #5)
> Use nsPrintfCString and CopyASCIItoUTF16 instead (yes, our string classes are
> not easy to use).
> 
> You can see how the generate-id function is implemented here:
> 
> http://mxr.mozilla.org/mozilla-central/source/content/xslt/src/xslt/txGenerateIdFunctionCall.cpp?force=1#83
> http://mxr.mozilla.org/mozilla-central/source/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp#616

Will do.

> Also, is the string returned from this function parsable using the Date object
> in javascript? If so, it might be nicer to do so and check that the difference
> to Date.now() is less than, say, 30 minutes.

I tried that last week and got an exception. I didn't investigate further as the the documentation on the 8601 aspect on Date.parse is a bit weak. It would be good to know what exactly it *is* expected to parse.
(Reporter)

Comment 7

6 years ago
Maybe I can use

  https://developer.mozilla.org/en/JavaScript_code_modules/ISO8601DateUtils.jsm#Using_the_ISO.c2.a08601_date_utilities

in the test case?
(Reporter)

Comment 8

6 years ago
Created attachment 526998 [details] [diff] [review]
implementation of exslt:date-time(), plus a minimal test case
Attachment #524949 - Attachment is obsolete: true
Attachment #526998 - Flags: review?
(Reporter)

Updated

6 years ago
Attachment #526998 - Flags: review? → review?(jonas)
(Reporter)

Comment 9

6 years ago
(In reply to comment #6)
> (In reply to comment #5)
> > Use nsPrintfCString and CopyASCIItoUTF16 instead (yes, our string classes are
> > not easy to use).
> > 
> > You can see how the generate-id function is implemented here:
> > 
> > http://mxr.mozilla.org/mozilla-central/source/content/xslt/src/xslt/txGenerateIdFunctionCall.cpp?force=1#83
> > http://mxr.mozilla.org/mozilla-central/source/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp#616
> 
> Will do.

Done.

> > Also, is the string returned from this function parsable using the Date object
> > in javascript? If so, it might be nicer to do so and check that the difference
> > to Date.now() is less than, say, 30 minutes.
> 
> I tried that last week and got an exception. I didn't investigate further as
> the the documentation on the 8601 aspect on Date.parse is a bit weak. It would
> be good to know what exactly it *is* expected to parse.

I retried and got it working (I think I assumed wrong that Date.parse returns a Date). Set the accepted diff to 30 minutes as suggested.
Comment on attachment 526998 [details] [diff] [review]
implementation of exslt:date-time(), plus a minimal test case


>+            // http://exslt.org/date/functions/date-time/
>+            // format: YYYY-MM-DDTTHH:MM:SS.sss+00:00
>+            char formatstr[] = "%04hd-%02ld-%02ldT%02ld:%02ld:%02ld.%03ld%c%02ld:%02ld";
>+            size_t max = sizeof("YYYY-MM-DDTHH:MM:SS.sss+00:00");

Make this |const size_t max|.

>+  ok(now_ms - xslt_ms < accepted_diff, "generated timestamp should be not more than "
>+    + accepted_diff + " ms before 'now', but the difference was: " + (now_ms - xslt_ms));

This needs to be Math.abs(now_ms - xslt_ms), in both places.

r=me with those fixed.

If you attach a new patch (preferrably "hg export"ed) then I can land it.
Attachment #526998 - Flags: review?(jonas) → review+
(Reporter)

Comment 11

6 years ago
(In reply to comment #10)
> Comment on attachment 526998 [details] [diff] [review]
> implementation of exslt:date-time(), plus a minimal test case
> 
> 
> >+            // http://exslt.org/date/functions/date-time/
> >+            // format: YYYY-MM-DDTTHH:MM:SS.sss+00:00
> >+            char formatstr[] = "%04hd-%02ld-%02ldT%02ld:%02ld:%02ld.%03ld%c%02ld:%02ld";
> >+            size_t max = sizeof("YYYY-MM-DDTHH:MM:SS.sss+00:00");
> 
> Make this |const size_t max|.

Will do.

> >+  ok(now_ms - xslt_ms < accepted_diff, "generated timestamp should be not more than "
> >+    + accepted_diff + " ms before 'now', but the difference was: " + (now_ms - xslt_ms));
> 
> This needs to be Math.abs(now_ms - xslt_ms), in both places.

Really? isn't now_ms guaranteed to be >= xslt_ms? Anyway; I'll make that change...
(Reporter)

Comment 12

6 years ago
Created attachment 528302 [details] [diff] [review]
implementation of exslt:date-time(), plus a minimal test case
Attachment #526998 - Attachment is obsolete: true
Attachment #528302 - Flags: review?(jonas)
(Reporter)

Comment 13

6 years ago
Any chance to get this in before FF6 Aurora is branched?

Comment 14

6 years ago
http://hg.mozilla.org/mozilla-central/rev/0abb7330c64c
Yup, checked in. Leaving the honors of marking it fixed to Julian.

(btw, the patch here contained windows lineendings which made it not apply. Easy fix though).
(Reporter)

Comment 16

6 years ago
(In reply to comment #15)
> Yup, checked in. Leaving the honors of marking it fixed to Julian.

Thanks. I build the Nightly from m-c and tested against

  http://greenbytes.de/tech/webdav/xslt-test.xml

and all is well.

> (btw, the patch here contained windows lineendings which made it not apply.
> Easy fix though).

Sorry for that.
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Attachment #528302 - Flags: review?(jonas) → review+
(Reporter)

Updated

6 years ago
OS: Windows 7 → All
Hardware: x86 → All
You need to log in before you can comment on or make changes to this bug.