On Thu, 8 Apr 2010, Carl Mäsak wrote:
Among the cons: we lose the nice symmetry wherein :to<day> clears all
values smaller than days, :to<year> clears all values smaller than
years, etc. :to<monday> is still pretty straightforward, but it's a
subtle category error.
Of course. What I really want is for weeks to start on Sunday, like
all the calendars around me seem to indicate that they do. Rather than
pushing my particular time-ideology on everyone else, I would like to
see a post-modern solution for the problem.
Having an internal variable like $[ to define the first day of the week
has turned out bad in the past, so I proposed this solution instead.
Apart from that, I wouldn't mind making the change. Though maybe we
should take a step backward and just remove :to<week> altogether on
the grounds that it doesn't belong, and is more confusing than useful.
I agree that :to<week> is confusing, but just because not everyone can
agree on the definition of week. But if you are writing a calendar
application, it is very useful. We measure time in weeks just as often
as we measure it in months, and weeks are a much less confusing time
interval than months are. Just because we prefer to _write_ dates
in terms of months doesn't mean weeks are any less valid of a time
interval. Anything besides "year" and "day" is rather artificial,
so maybe we should forget about months, weeks, hours, minutes and
seconds too. They should all be part of the calendar class, right?
On Fri, 9 Apr 2010, yary assumed:
indeed truncating to any day of the week can be implemented by user
trivially by adding/subtracting a constant number of days from the
Monday returned.
No, it's not a constant.
$sun = DateTime.new('2010-04-11').trunc( :to<sunday> ) # 2010-04-11
$mon = DateTime.new('2010-04-11').trunc( :to<monday> ) # 2010-04-05
$sun - $mon == 6 days
$sun = DateTime.new('2010-04-12').trunc( :to<sunday> ) # 2010-04-11
$mon = DateTime.new('2010-04-12').trunc( :to<monday> ) # 2010-04-12
$sun - $mon == -1 day
On Thu, 8 Apr 2010, Mark J. Reed wrote:
I think that :to<week> should stay as-is; it truncates to whatever the
.week method returns, and that's Monday-based. It would be too
inconsistent for it to do anything else.
Agreed. That's why I asked for :to<sunday>
Asking for the latest prior Sunday or any other weekday is a useful
function, but it doesn't really have anything to do with 'truncation'.
Asking for the first of the month is truncating to an even more arbitrary
interval than a seven-day period, but we still call it truncation somehow.
The trouble with asking for the prior sunday, is that on sunday an
implementation of the prior() function will return a date 7 days prior to
today, while an implementation of the truncate() function will return
today.