truncated-to
ErrorsCollection

truncated-to

Synthesised documentation from type/Date type/DateTime

From type/Date

See Original text in context

method truncated-to(Date:D: Cool $unit)

Returns a Date truncated to the first day of its year, month or week. For example

my $c = Date.new('2012-12-24');
say $c.truncated-to('year');     # OUTPUT: «2012-01-01␤» 
say $c.truncated-to('month');    # OUTPUT: «2012-12-01␤» 
say $c.truncated-to('week');     # OUTPUT: «2012-12-24␤», because it's Monday already

From type/DateTime

See Original text in context

method truncated-to(DateTime:D: Cool $unit)

Returns a copy of the invocant, with everything smaller than the specified unit truncated to the smallest possible value.

my $d = DateTime.new("2012-02-29T12:34:56.946314Z");
say $d.truncated-to('second');      # OUTPUT: «2012-02-29T12:34:56Z␤» 
say $d.truncated-to('minute');      # OUTPUT: «2012-02-29T12:34:00Z␤» 
say $d.truncated-to('hour');        # OUTPUT: «2012-02-29T12:00:00Z␤» 
say $d.truncated-to('day');         # OUTPUT: «2012-02-29T00:00:00Z␤» 
say $d.truncated-to('month');       # OUTPUT: «2012-02-01T00:00:00Z␤» 
say $d.truncated-to('year');        # OUTPUT: «2012-01-01T00:00:00Z␤»

DateTimes with fractional seconds can be truncated to whole seconds with .truncated-to('second').