On Thu, 19 Feb 2009, Darren Duncan wrote:

+role   Temporal::Date {
+       has Int $.year;
+       has Int $.month;
+       has Int $.day; # Day of month
+       has Int $.dayofweek;

You could make month/day into positive integers or "subtype of Int where 1..12" etc, though it isn't strictly necessary. Leave year as Int of course, since at least in the proleptic Gregorian etc you can have negatives or zero.

I want this role to be composable into the heavy-lifting non-core non-Gregorian modules as well as into Temporal::Interval, so I'm trying not to get too specific.

+       has Int $.era; # BC, AD, etc, depending on locale
+ has Str $.defaultformat; # A CLDR-formatted string, for use with toString();

Now $.era you definitely should change, either to Str like defaultformat or come up with some enumerated type, as Int seems wrong there, though Str is probably best to make later extensions easier, especially if you're sticking with plain Int for the others.

I gave era the flick. I'll assume that negative year are BC, and let CLDR worry about the output.

+ multi method infix:{'<=>'}(Temporal::Date $self, Temporal::Duration $other);

I don't think it makes sense to compare any kind of Instant/Date/Time to a Duration for relative order; they are not the same thing like a position isn't the same as a length.

        Ok, fixed.

+role   Temporal::Time {
        has $.hour;
        has $.minute;
        has $.second;

You didn't give these attributes types like you did for Date.

I suggest Int (or UInt) for hour/minute if you want to be consistent, and Rat/Num for second.

        Fixed, I think.


+ multi method infix:{'<=>'}(Temporal::Time $self, Temporal::Duration $other);

Likewise with the Date example this doesn't make sense, comparing a position to a length.

        Fixed.

+role   Temporal::Subsecond {
+       has     $.nanosecond;
+}

Two things:

1. You should just make that a Rat/Num $second or $frac_second or something. I know DateTime.pm has the precedent but counting in nanoseconds is too arbitrary, especially since newer/future machines would have a higher resolution than that. Using Rat/Num will let this be open-ended.

We also want to be able to avoid floating point rounding problems too. I called the role "Subsecond" instead of "Nanosecond" because I want to make it possible for future machines to add a $.femtosecond if needed :).

2. Why not just make normal $.second in Time be a Rat/Num instead? Users can always subtype it with "where is_desired_precision()" or something if they want that. Separating out whole and fractional seconds has a design smell to me since they measure the same unit (unlike min/hour/day/mon/year, each of which deserve to be separate).

Hmm. Well, I'll think about it for a while, and hope that Dave Rolsky will chime in on this :).

+class Temporal::Instant
<snip>
+ multi method Temporal::Instant infix:<+>(Temporal::Instant $self, Duration $other);
 +      multi method infix:<->(Temporal::Instant $self, Duration $other);
+       multi method infix:<->(Temporal::Instant $self, Duration $other);

You repeated '-' and also the declaration is different than that for '+'; I assume you wanted to make your '-' like your '+'.

I've fixed the multi - declarations (there were indeed supposed to be two). I've been sloppy about return values, but I've fixed that now too.

+       multi method infix:{'<=>'}(Temporal::Instant $self, Duration $other);

Again with the doesn't make sense as per Duration <=> Date|Time.

        Fixed.

+class Temporal::Duration + does Temporal::Date + does Temporal::Time + does Temporal::Subsecond
+{
+}

Okay, I see why you did what you did with those 3 above "doesn't make sense" examples; but in that case, I think what you really want is to move the "<=>" out of Date|Time and into Duration. And stuff.

In fact, while they look similar, I wouldn't reuse the Date|Time roles between Instant and Duration. While they consist of the same units, the allowed values differ; for Duration any Int is allowed while for Instant generally only non-negative constrained values like 1..23 etc are allowed.

But who knows, maybe you can still make the idea of sharing roles in that way work, and I do see it making sense in some ways.

I thought for a bit I did too, but now I've changed my mind, socks, and shoes :).

+=head2 Temporal::Recurring
+
This class specifies when a repetitive action (eg. a cron job) happens. -class DateTime::Recurring {
+class  Temporal::Recurring {
 ...
 }

I should point out that in some respects any Time is effectively a Recurring because it doesn't specify a day and so could mean "on every day"; similarly eg if you have a Date but leave the Year undefined (repeat every year) and so on. Unless your Instant|Date|Time requires all attributes to be defined, or all unit defined attributes than any defined attribute to be defined.

Or more likely in practice, leaving those parts out just means "don't know" and not recurring.

But a dedicated Recurring is definitely useful since it can specify other kinds of recurrings, like "every 90 minutes from X Instant" for example, and it unambiguously means recurring rather than don't know.

        Hmm.  Interesting thoughts, and I'll keep them in mind :).

        :)


---------------------------------------------------------------------
| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: wayl...@wayland.id.au    | I am                           |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y-
-----END GEEK CODE BLOCK-----

Reply via email to