Negative values should be returned from seconds-from-dateTime()

Hello all,

I've been having a lot of fun :( trying to get the various date/time
functions working in the Ubiquity XForms library, and most of the
problems arise from timezone switching.

Anyway, one of the tests for seconds-from-dateTime() involves a
timezone, as follows:

  Assert.areEqual(28800,
evalXPath('seconds-from-dateTime("1970-01-01T00:00:00-08:00")').numberValue());

This test is based on an example in section 7.9.6 of the XForms 1.1 spec.

My question is, why is the example saying that it should be a positive
number? It's true that the spec says:

  "...the return value is equal to the number of seconds difference..."

which would imply making the number positive -- so the result is
correct according to the spec. But I wonder what we gain by *losing*
the sign of the result.

The problem is further compounded when you use this function with the
complementary seconds-to-dateTime(). Nothing says that
seconds-to-dateTime() should _not_ take a negative value, so the
problem we have is that the following pair of calls does not give you
back what you started with:

  seconds-from-dateTime(seconds-to-dateTime(-28800))

I.e, the result according to the spec is 28800, when it could easily be -28800.

I think that the fix is to simply change the example in the spec,
which would send a clear signal to implementers:

  Example:

  seconds-from-dateTime('1970-01-01T00:00:00Z')
  returns 0

  seconds-from-dateTime('1970-01-01T00:00:00-08:00')
  returns -28800

Note that the Ubiquity XForms unit tests for this are currently
passing because I've set the functions to return a negative number.
Obviously I'll change that if need be, but I'll see what points come
up on this discussion first.

Regards,

Mark

-- 
Mark Birbeck, webBackplane

mark.birbeck@webBackplane.com

http://webBackplane.com/mark-birbeck

webBackplane is a trading name of Backplane Ltd. (company number
05972288, registered office: 2nd Floor, 69/85 Tabernacle Street,
London, EC2A 4RR)

Received on Friday, 1 August 2008 12:55:15 UTC