Front page | perl.perl6.language |
Postings from April 2010
r30398 - docs/Perl6/Spec/S32-setting-library
From:
pugs-commits
Date:
April 16, 2010 13:40
Subject:
r30398 - docs/Perl6/Spec/S32-setting-library
Message ID:
20100416204037.19161.qmail@feather.perl6.nl
Author: moritz
Date: 2010-04-16 22:40:37 +0200 (Fri, 16 Apr 2010)
New Revision: 30398
Modified:
docs/Perl6/Spec/S32-setting-library/Temporal.pod
Log:
[S32/Temporal] spec Date type
This is heavily inspired by Date::Simple on CPAN, and mostly implemented
at http://github.com/moritz/Date/ as an external module, that currently works
fine with Rakudo (but is really compiler agnostic).
Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod
===================================================================
--- docs/Perl6/Spec/S32-setting-library/Temporal.pod 2010-04-16 15:47:23 UTC (rev 30397)
+++ docs/Perl6/Spec/S32-setting-library/Temporal.pod 2010-04-16 20:40:37 UTC (rev 30398)
@@ -8,6 +8,7 @@
Carl Mäsak <cmasak@gmail.com>
Martin Berends <mberends@autoexec.demon.nl>
+ Moritz Lenz <moritz@faui2k3.org>
(and others named in FOOTNOTE at bottom)
=head1 VERSION
@@ -74,6 +75,11 @@
This has the same effect as doing C<DateTime.now().truncate('day')>; see
'"Set" methods' below.
+Or if you want to extract the date as a C<Date> object (see below),
+you can use simple type coercion:
+
+ my $today = $datetime.Date;
+
General dates can be specified through the C<new> constructor:
my $moonlanding = DateTime.new( :year(1969), :month(7), :day(16),
@@ -195,6 +201,62 @@
Monday of the week in which it occurs, and the time components are all
set to 0.
+=head1 Date
+
+C<Date> objects represent a day without a time component, and allow easier
+manipulation by assuming that integers always mean days.
+
+Days, Months and days of week are 1-based.
+
+=head2 Constructors
+
+ Date.today(); # today's date
+ Date.new('2010-12-24'); # YYYY-MM-DD format
+ Date.new(:year(2010), :month(12), :day(24));
+ Date.new(2010, 12, 24);
+
+The constructors die with a helpful error message if month or day are out of
+range.
+
+=head2 Accessors
+
+The following accessors are pretty obvious, and are defined by example only.
+See the test suite for more formal definitions.
+
+ my $d = Date.new('2010-12-24');
+ $d.year # 2010
+ $d.month # 12
+ $d.day # 24
+ $d.day-of-week # 5 # Friday
+ $d.is-leap-year # Bool::False
+ $d.days-in-month # 31
+ $d.Str # '2010-12-24'
+
+=head2 Arithmetics
+
+ $d.succ # Date.new('2010-12-25')
+ $d.pred # Date.new('2010-12-23')
+ $d - Date.new('1984-03-02') # 9793 # (difference in days)
+ $d - 42 # Date.new('2010-11-12')
+ $d + 3 # Date.new('2010-12-27')
+ 3 + $d # Date.new('2010-12-27')
+
+=head2 Semi-internal methods
+
+[This section is severely conjectural]
+
+For efficient implementation of arithmetics on C<Date> objects, two more
+methods are exposed:
+
+ $d.daycount
+ Date.new-from-daycount(Int $daycount)
+
+The C<daycount> method returns the difference of number of days between the
+current object and an arbitrary start of epoch. This epoch is arbitrary and
+implementation dependent, and is even allowed to change between invocations of
+the same program. The C<new-from-daycount> constructor creates a new C<Date>
+object with a given daycount.
+
=head1 Additions
Please post errors and feedback to C<perl6-language>. If you are making