Hi,

On 11/10/2014 01:39 PM, Steve Mynott wrote:
http://doc.perl6.org/type/Date says

my $c = Date.new('2012-12-24');
say $c.truncated-to(:year);     # 2012-01-01

but this doesn't work and what's implemented appears to be "year"
rather than :year

$ perl6
my $c = Date.new('2012-12-24');
2012-12-24
say $c.truncated-to("year")
2012-01-01

Which is correct the code or docs?


iirc there was a spec change.

Let's check...

$ ~/p6/specs (master)$ git log -p -S truncated
commit 9d8bc5fe62dd38805d791c0351c85185d351290e
Author: Carl Masak <cma...@gmail.com>
Date:   Thu Jan 24 18:27:55 2013 +0100

    [S32/Temporal] spec DateTime.delta and Date.delta

    Clarify the .truncated-to method as well; it also uses the
    C<TimeUnit> enum, instead of named parameters.

...
-The C<truncated-to> method allows you to "clear" a number of time values
+The C<truncated-to> constructor allows you to "clear" a number of time values
 below a given resolution:

     my $dt = DateTime.new('2005-02-01T15:20:35Z');
-    say $dt.truncated-to(:hour); # 2005-02-01T15:00:00Z
+    say $dt.truncated-to(hour); # 2005-02-01T15:00:00Z

-An argument of C<:week> yields an object with the date of the last Monday
+Arguments to C<truncated-to> belong to the enum C<TimeUnit>, which encompasses
+these values:
+
+    second  seconds
+    minute  minutes
+    hour    hours
+    day     days
+    week    weeks
+    month   months
+    year    years
+
...

so looks like the docs are out of date. Patches to fix that would be awesome!

Cheers,
Moritz

Reply via email to