Oops, thanks. Revised version:
=head3 How small an increment of time can I represent?
A<DateTime> can represent nanoseconds. You can create obects with
that resolution using the C<nanosecond> parameter to C<new> or C<set>
and there is a corresponding C<nanosecond> accessor. For these you
give an integer count of the nanoseconds.
A millisecond is a thousandth of a second (10^-3 or 0.001). The
abbreviation is I<ms>.
A microsecond is a millionth of a second (10^-6 or 0.000001). The
abbreviation is I<us> (or more properly I<E<micro>s>).
A nanosecond is a billionth (US) of a second (10^-9 or 0.000000001).
The abbreviation is I<ns>.
=for example begin
# The ns part is 0.000000230 below
my $dt_ns = DateTime->new(year => 2003, month => 3, day => 1,
hour => 6, minute => 55, second => 23,
nanosecond => 230);
print "ns: ", $dt_ns->nanosecond, "\n"; # Prints: "ns: 230\n"
# Assuming we got milliseconds as an argument
my $ms = 42;
my $dt_ms = DateTime->new(year => 2003, month => 3, day => 1,
hour => 6, minute => 55, second => 23,
nanosecond => $ms * 1_000_000);
print "ms: ", $dt_ms->nanosecond, "\n"; # Prints: "ns: 42000000\n"
=for example end
=for example_testing
is($_STDOUT_, "ns: 230\nns: 42000000\n", "Nanoseconds");
-ben
On Wed, Jun 11, 2003 at 10:05:02PM -0700, Bruce Van Allen wrote:
>
> On Wednesday, June 11, 2003, at 07:08 PM, Ben Bennett wrote:
> >I added a section on nanoseconds:
> >The raw POD is below.
> >
>
> >=head3 How small an increment of time can I represent?
> >
> >A<DateTime> can represent nanoseconds. You can create obects with
>
> >=for example begin
> >
> > # The ns part is 0.000000230 below
> > my $dt_ns = DateTime->new(year => 2003, month => 3, day => 1,
> > hour => 6, minute => 55, second => 23,
> > nanosecond => 230);
> > print "ns: ", $dt_ns->nanosecond, "\n"; # Prints: "ns: 230\n"
> >
> > # Assuming we got microseconds as an argument
> ^^^^^
> I think you meant: milli
>
> > my $ms = 42;
> > my $dt_ms = DateTime->new(year => 2003, month => 3, day => 1,
> > hour => 6, minute => 55, second => 23,
> > nanosecond => $ms * 1_000_000);
> > print "ms: ", $dt_ms->nanosecond, "\n"; # Prints: "ms: 42000000\n"
> ^^
> That number is in nanoseconds (42 milliseconds is 42,000,000
> nanoseconds); does it make sense to label it 'ms' in the test output?
>
> - Bruce
>
> __bruce__van_allen__santa_cruz__ca__