method truncated-to
Documentation for method truncated-to
assembled from the following types:
class Date
From Date
(Date) method truncated-to
Defined as:
method truncated-to(Date: Cool )
Returns a Date
truncated to the first day of its year, month or week. For example
my = Date.new('2012-12-24');say .truncated-to('year'); # OUTPUT: «2012-01-01»say .truncated-to('month'); # OUTPUT: «2012-12-01»say .truncated-to('week'); # OUTPUT: «2012-12-24», because it's Monday already
class DateTime
From DateTime
(DateTime) method truncated-to
Defined as:
method truncated-to(DateTime: Cool )
Returns a copy of the invocant, with everything smaller than the specified unit truncated to the smallest possible value.
my = DateTime.new("2012-02-29T12:34:56.946314Z");say .truncated-to('second'); # OUTPUT: «2012-02-29T12:34:56Z»say .truncated-to('minute'); # OUTPUT: «2012-02-29T12:34:00Z»say .truncated-to('hour'); # OUTPUT: «2012-02-29T12:00:00Z»say .truncated-to('day'); # OUTPUT: «2012-02-29T00:00:00Z»say .truncated-to('month'); # OUTPUT: «2012-02-01T00:00:00Z»say .truncated-to('year'); # OUTPUT: «2012-01-01T00:00:00Z»
DateTimes with fractional seconds can be truncated to whole seconds with .truncated-to('second')
.