Re: Patch for DateTime::Format::W3CDTF to respekt second fragment part

2007-11-08 Thread Zefram
Jonathan Leffler wrote:
>Or, what happens if there are 10 digits after the decimal point.

That's what the substr() is for.

>Yeah, mostly academic, except I'm working towards a time type (not for 
>Perl per se) that extends down to picoseconds (and up to 10^12 years, 
>too).

At least 105 bits, then.  TAI64 covers nearly 10^12 years, of course,
and the extension TAI64NA goes down to attoseconds in a 128-bit format.
What's the concept behind your type?

Personally I like to use bignum rational arithmetic, for unlimited
resolution.  Performance is atrocious with the Perl bignum libraries,
unfortunately.

-zefram


Re: Patch for DateTime::Format::W3CDTF to respekt second fragment part

2007-11-08 Thread Jonathan Leffler
Zefram <[EMAIL PROTECTED]> wrote:
> Re: Patch for DateTime::Format::W3CDTF to respekt second fragment part
> 
> Julian Haupt wrote:
> >+if ($date =~ s/\.(\d+)$// )
> >+{
> >+   my $fraction = $1;
> >+   $p{'nanosecond'} = (1 / $fraction) * 10**9;
> >+}
> 
> That inversion can't be right.  Surely you mathematically want
> 
>$p{'nanosecond'} = "0.$fraction" * 10**9;
> 
> but actually the nanoseconds member is supposed to be an integer, and
> it would be better to avoid floating-point arithmetic entirely:
> 
>$fraction = substr($fraction, 0, 9);
>$fraction .= "0" x (9 - length($fraction);
>$p{'nanosecond'} = 0 + $fraction;

Beware the picosecond!

Or, what happens if there are 10 digits after the decimal point.  I've no 
idea what -3 zeroes looks like, but the answer is unlikely to be correct.

Yeah, mostly academic, except I'm working towards a time type (not for 
Perl per se) that extends down to picoseconds (and up to 10^12 years, 
too).

-- 
Jonathan Leffler ([EMAIL PROTECTED])
STSM, Informix Database Engineering, IBM Information Management Division
4100 Bohannon Drive, Menlo Park, CA 94025-1013
Tel: +1 650-926-6921Tie-Line: 630-6921
"I don't suffer from insanity; I enjoy every minute of it!"

NB: with effect from 2007-11-28, my address and phone number change to:
4400 N First St, San Jose, CA 95134-1257
Tel: +1 408-956-2436 T/L: 475-2436



smime.p7s
Description: S/MIME Cryptographic Signature


Re: Patch for DateTime::Format::W3CDTF to respekt second fragment part

2007-11-07 Thread Zefram
Julian Haupt wrote:
>+if ($date =~ s/\.(\d+)$// )
>+{
>+  my $fraction = $1;
>+  $p{'nanosecond'} = (1 / $fraction) * 10**9;
>+}

That inversion can't be right.  Surely you mathematically want

$p{'nanosecond'} = "0.$fraction" * 10**9;

but actually the nanoseconds member is supposed to be an integer, and
it would be better to avoid floating-point arithmetic entirely:

$fraction = substr($fraction, 0, 9);
$fraction .= "0" x (9 - length($fraction);
$p{'nanosecond'} = 0 + $fraction;

-zefram


Patch for DateTime::Format::W3CDTF to respekt second fragment part

2007-11-06 Thread Julian Haupt
Hello,

i added support for "decimal fraction of a
second" in DateTime::Format::W3CDTF (as described in
http://www.w3.org/TR/NOTE-datetime)

Please note: There is already a bug report and a patch in ticket #14179
http://rt.cpan.org/Public/Bug/Display.html?id=14179

But this patch looked a bit too invasive for me.

I would be glad if could pull this patch into the mainstream package.

Please also note: I'm not subscribed to this mailing list, so you have to
anwser me directly.

Best regards,

Julian

--- DateTime/Format/W3CDTF.pm.orig	2007-11-06 21:15:12.0 +0100
+++ DateTime/Format/W3CDTF.pm	2007-11-06 21:35:17.0 +0100
@@ -66,6 +66,13 @@
 $p{time_zone} = 'floating';
 }
 
+#check for decimal fraction
+if ($date =~ s/\.(\d+)$// )
+{
+	my $fraction = $1;
+	$p{'nanosecond'} = (1 / $fraction) * 10**9;
+}
+
 my $format = $valid_formats{ length $date }
 or die "Invalid W3CDTF datetime string ($original)";