root/examples/vmethods/time.pl

Revision 12735, 1.3 kB (checked in by audreyt, 2 years ago)

* examples/vmethods/time.pl: fix one typo.

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1# Please remember to update examples/output/vmethods/time if you change this
2# file so its output will change.
3#
4# based on Ruby's ActiveSupport 1.0.4
5#
6
7use v6-alpha;
8
9multi sub seconds (Int $value) {
10    $value;
11}
12
13our &second ::= &seconds;
14
15multi sub minutes (Int $value) {
16    $value * 60;
17}
18
19our &minute ::= &minutes;
20
21multi sub hours (Int $value) {
22    $value * 60.minutes;
23}
24
25our &hour ::= &hours;
26
27multi sub days (Int $value) {
28    $value * 24.hours;
29}
30
31our &day ::= &days;
32
33multi sub weeks (Int $value) {
34    $value * 7.days;
35}
36
37our &week ::= &weeks;
38
39multi sub fortnights (Int $value) {
40    $value * 2.weeks;
41}
42
43our &fortnight ::= &fortnights;
44
45multi sub months (Int $value) {
46    $value * 30.days;
47}
48
49our &month ::= &months;
50
51multi sub years (Int $value) {
52    $value * 365.days;
53}
54
55our &year ::= &years;
56
57multi sub centuries (Int $value) {
58    $value * 100.years;
59}
60
61our &century ::= &centuries;
62
63multi sub ago (Int $value; Int :$time = time()) {
64    $time - $value;
65}
66
67our &until ::= &ago;
68
69multi sub since (Int $value; Int :$time = time()) {
70    $time + $value;
71}
72
73our &from_now ::= &since;
74
75say "2 days is " ~ 2.days ~ " seconds.";
76say "4 weeks is " ~ 4.weeks ~ " seconds.";
77say "1 month is " ~ 1.month ~ " seconds.";
78
79# say 2.days.ago
80# say 3.weeks.from_now
81# $1_week_ago = 1.week.ago;
82# say 1.day.until($1_week_ago);
83# say 2.months.since($1_week_ago);
Note: See TracBrowser for help on using the browser.