To get what you ask for:
use MONKEY-TYPING; augment class Int { my class Date::Offset { has Pair $.offset is required; method ago () { Date.today.earlier( |$!offset ) } method from-now () { Date.today.later( |$!offset ) } } method days () { Date::Offset.new( offset => days => self ); } method months () { Date::Offset.new( offset => months => self ); } } say 1.days.ago; # 2017-03-13 say Date.today; # 2017-03-14 say 1.days.from-now; # 2017-03-15 say 1.months.ago; # 2017-02-14
Now that I have shown you how, please, do not. You can end up affecting code that you did not intend, in a way that is very difficult to fix.
(There are legitimate reasons to do something similar, but I don't think this is one of them)
If you want to spoil the basic actions, do it lexically.
{ sub postfix:ยซ .days.ago ยป ( Int:D $offset ) { Date.today.earlier( days => $offset ) } sub postfix:ยซ .days.from-now ยป ( Int:D $offset ) { Date.today.later( days => $offset ) } sub postfix:ยซ .months.ago ยป ( Int:D $offset ) { Date.today.earlier( months => $offset ) } sub postfix:ยซ .months.from-now ยป ( Int:D $offset ) { Date.today.later( months => $offset ) } say 1.days.ago; # 2017-03-13 say Date.today; # 2017-03-14 say 1.days.from-now; # 2017-03-15 say 1.months.ago; # 2017-02-14 } say 1.days.ago; # error
source share