Re: Which DOW is day #1?

2003-01-24 Thread Dave Rolsky
On Fri, 24 Jan 2003, Clayton L. Scott wrote:

> So if I want to use Sunday as the first day of the week every will
> method I use will have "sunday" in it? What if for some business reason
> I decide that it's easier to do my calculations if Wednesday is the first
> day of the week?
>
> How about:
>
> use DateTime;
> use DateTime::Lingua::EN;
> use DateTime::Lingua::FR;
>
> DateTime::first_day_of_week( DateTime::Lingua::EN::SUNDAY );
>
> or maybe we can make english the "blessed default language like we are
> doing for the Gragorian Calendar"
>
> DateTime::first_day_of_week( SUNDAY ); # Exported Constant?
>
> DateTime::first_day_of_week( DateTime::Lingua::EN::DIMANCHE );

This is not going to happen.  Allowing this sort of thing makes it
impossible for a module to trust a DateTime object that it's given.  The
API needs to be fixed, so that day_of_week _always_ means the same thing.

And if you _really_ want to treat Wednesday as day 1, you can do this.

 sub day_of_week_wednesday_first
 {
 my $dt = shift;
 my $dow = $dt->day_of_week; # monday first
 $dow = ( ( $dow + 7 ) - 2 ) % 7 );

 return $dow;
 }

> > >3) How many days of a week must be in the new year before
> > >   the week is considered the first week in the new year?
> > >   (ISO: 4, US: 1 and 7)
> >
>
> > Eek, I'm not sure I want to touch this yet.  But if people have good mehod
> > names, I'm happy to include it.
>
> DateTime::min_days_first_week_of_year(7)
>
> If it's a Class value and is object overridable ...

Again, for the same reasoning as above, this is not going to happen.

Module authors need to be able to say "given a DateTime object,
function/method X returns Y", without having to set class variables of its
own (and then who wins?)


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/



Re: Which DOW is day #1?

2003-01-24 Thread Clayton L. Scott
On Fri, 24 Jan 2003, Dave Rolsky wrote:

> On Fri, 24 Jan 2003, Peter J. Acklam wrote:
> > In relation to week numbers and day of week numbers, there are
> > at least four parameters that must be customizable:
> >
> >1) What is the first day of a week (Sunday, Monday, ...)?
> 
> I just need method names for this.  Monday as first day of week is
> "day_of_week" (Monday is 1) and "day_of_week_0" (Monday is 0).  Equivalent
> methods using Sunday are welcome, but they need good names.

So if I want to use Sunday as the first day of the week every will 
method I use will have "sunday" in it? What if for some business reason
I decide that it's easier to do my calculations if Wednesday is the first 
day of the week?

How about:

use DateTime;
use DateTime::Lingua::EN;
use DateTime::Lingua::FR;

DateTime::first_day_of_week( DateTime::Lingua::EN::SUNDAY );

or maybe we can make english the "blessed default language like we are 
doing for the Gragorian Calendar"

DateTime::first_day_of_week( SUNDAY ); # Exported Constant?

DateTime::first_day_of_week( DateTime::Lingua::EN::DIMANCHE );

And then use the '_0' methods as desired if you want a 0 based index

I'd prefer the above plus $d->weekday_num_0 
over
$d->weekday_num_sunday_0;
$d->weekday_num_wednesday_0;

> >3) How many days of a week must be in the new year before
> >   the week is considered the first week in the new year?
> >   (ISO: 4, US: 1 and 7)
> 

> Eek, I'm not sure I want to touch this yet.  But if people have good mehod
> names, I'm happy to include it.

DateTime::min_days_first_week_of_year(7) 

If it's a Class value and is object overridable ...

Clayton




Re: Which DOW is day #1?

2003-01-24 Thread Dave Rolsky
On Fri, 24 Jan 2003, Peter J. Acklam wrote:

> I believe this thread proves that what is considered the first day
> of the week must be customizable.  If it isn't, then someone
> (perhaps not someone on this mailing list, but someone) will be
> dissatisfied and consider the "DateTime" modules useless and write
> their own modules -- and much of the point with the "DateTime"
> modules will be lost.

As Rich pointed out, the idea of offering a rich API that supports all of
these things is good.  The idea of a narrow API which has a changing
meaning is very bad.  We already have some of the rich API needed, like
"day_of_week" and "day_of_week_0".

> In relation to week numbers and day of week numbers, there are
> at least four parameters that must be customizable:
>
>1) What is the first day of a week (Sunday, Monday, ...)?

I just need method names for this.  Monday as first day of week is
"day_of_week" (Monday is 1) and "day_of_week_0" (Monday is 0).  Equivalent
methods using Sunday are welcome, but they need good names.

>2) What is the number of this day (0, 1)?

See above.

>3) How many days of a week must be in the new year before
>   the week is considered the first week in the new year?
>   (ISO: 4, US: 1 and 7)

Eek, I'm not sure I want to touch this yet.  But if people have good mehod
names, I'm happy to include it.

>4) What is the number of this week (0, 1)?

This can be done with more *_0 methods.


This all comes down to have appropriately named methods, basically.


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/



Re: Which DOW is day #1?

2003-01-24 Thread Rich Bowen
On Fri, 24 Jan 2003, Peter J. Acklam wrote:

> [EMAIL PROTECTED] (Dave Rolsky) wrote:
>
> > Ok, having accepted the fact that day of week numbering will be
> > 1-7, now we get to argue about which day is #1.
> >
> > Time::Piece (interface by Larry Wall) says Sunday, as does
> > localtime, which comes from C's localtime function
> >
> > Date::Calc says Monday, and refers us to ISO 8601, which does
> > indeed say day #1 is Monday.
> >
> > I'm inclined to go with ISO rather than backwards compatibility
> > with C.
>
> I believe this thread proves that what is considered the first day
> of the week must be customizable.  If it isn't, then someone
> (perhaps not someone on this mailing list, but someone) will be
> dissatisfied and consider the "DateTime" modules useless and write
> their own modules -- and much of the point with the "DateTime"
> modules will be lost.
>
> In relation to week numbers and day of week numbers, there are
> at least four parameters that must be customizable:
>
>1) What is the first day of a week (Sunday, Monday, ...)?
>2) What is the number of this day (0, 1)?
>3) How many days of a week must be in the new year before
>   the week is considered the first week in the new year?
>   (ISO: 4, US: 1 and 7)
>4) What is the number of this week (0, 1)?
>
> As for the default behaviour, I think ISO is the best thing, since
> it aims at being a world-wide standard.

Sure, but customizable at what level? Having an API that behaves
differently in different installations is a BAD thing. The foo_0
methods, I think, already address this matter.

-- 
And everyone said, "If we only live,
We too will go to sea in a Sieve -
To the hills of the Chankly Bore!"
 (The Jumblies, by Edward Lear)




Re: Which DOW is day #1?

2003-01-24 Thread Peter J. Acklam
[EMAIL PROTECTED] (Dave Rolsky) wrote:

> Ok, having accepted the fact that day of week numbering will be
> 1-7, now we get to argue about which day is #1.
>
> Time::Piece (interface by Larry Wall) says Sunday, as does
> localtime, which comes from C's localtime function
>
> Date::Calc says Monday, and refers us to ISO 8601, which does
> indeed say day #1 is Monday.
>
> I'm inclined to go with ISO rather than backwards compatibility
> with C.

I believe this thread proves that what is considered the first day
of the week must be customizable.  If it isn't, then someone
(perhaps not someone on this mailing list, but someone) will be
dissatisfied and consider the "DateTime" modules useless and write
their own modules -- and much of the point with the "DateTime"
modules will be lost.

In relation to week numbers and day of week numbers, there are
at least four parameters that must be customizable:

   1) What is the first day of a week (Sunday, Monday, ...)?
   2) What is the number of this day (0, 1)?
   3) How many days of a week must be in the new year before
  the week is considered the first week in the new year?
  (ISO: 4, US: 1 and 7)
   4) What is the number of this week (0, 1)?

As for the default behaviour, I think ISO is the best thing, since
it aims at being a world-wide standard.

Peter

-- 
I wish dialog boxes had a butten saying "Whatever".  I hate being
forced to answer "Yes" or "No" to a question I have no opinion on
whatsoever.  There ought to be a button matching my indifference.



Re: Which DOW is day #1?

2003-01-14 Thread Dave Rolsky
On Tue, 14 Jan 2003, Nick Tonkin wrote:

> My preference is to keep integers out of variable names. It's easier to
> read.
>
> What about $date->month_zero_indexed ?

Maybe.

> Also: What about my suggestion that a switch in the DateTime constructor
> cause the default methods to become zero-indexed? Then the names would be
> just used internally anyway.
>
> my $dt = DateTime->new;
> $month = $dt->month(1); # January
>
> my $dt = DateTime->new(zero_indexing => 'yep');
> $month = $dt->month(1); # February, because internal magic overloads
> # month() with month_zero_indexed

No, cause then nobody will ever be able to _learn_ the DateTime API,
because the return value of the methods will be conditional on them
knowing how the object was constructed.  That would be very, very bad.
With my way, if it says "month" or "month_0" and you know the API, you
know what is being returned.


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/



Re: Which DOW is day #1?

2003-01-14 Thread Brad Hughes
Dave Rolsky wrote:
[...]

Make that:

 $month[ $date->month_0 ] vs. $date->month_name

$date->month returns a 1-based numbers
$date->month_0 a 0-based named
$date->month_name returns a name based on the DateTime::Language module
the $date object is holding onto.


While I like returning 1 based numbers by default, I'd like to suggest
eliminating the "_" for the 0 based returns:  $date->month0 instead of
$date->month_0.  Just preference...

brad




Re: Which DOW is day #1?

2003-01-13 Thread Rich Bowen
On Sun, 12 Jan 2003, Nick Tonkin wrote:

> You completely misunderstood my point, Rich. I was not implying any slight
> whatsoever. I continue to disagree with your opinion about the first day
> of the week in the Christian tenet(s), about which I know a good deal more
> than you evidently think.

I apologize for taking offence where there was none. I suppose that I am
now utterly confused as to in what way you disagree with me. In the
Christian week, if we are to call it that, Sunday is the first day of
the week, and traditional Christianity recognizes that the Sabbath,
which is Saturday, is the seventh day, on which God rested. Which part
of that do you feel that I have wrong?

> But my point was simply that cultural and
> religious traditions that may not make "sense" to the programmer are often
> very important. Similar to what you stated above.

OK, true. Since our job is to provide an interface that regular people
can understand, and not have to add and subtract to make sense of it.
Like adding 1900 to years. :-)

-- 
Rich Bowen - [EMAIL PROTECTED]
http://kenya.rcbowen.com/




Re: Which DOW is day #1?

2003-01-12 Thread Nick Tonkin
On Sun, 12 Jan 2003, Rich Bowen wrote:

> On Sun, 12 Jan 2003, Nick Tonkin wrote:
> 
> > Funny how the "Christian" point of view is that Sunday is the first day of
> > the week, when "God" rested on the seventh day after working to make the
> > world. Seventh which is Sunday for Christians .. (and Saturday which is
> > seventh for Jews, so for them Sunday _is_ the first day).
> 
> I would greatly prefer it if we not indulge in implied or actual
> criticizm of various religions, if it's all the same to you. Your
> comments here show that you're unaware of the Christian point of view,
> which makes a very clear distinction between the seventh day, on which
> God rested, and Sunday, which is a celebration of the resurrection of
> Jesus. The seventh day, the Sabbath, is Saturday in the Jewish
> tradition. Sunday has been celebrated in the Christian church,
> since the first Century AD, in commeration of the resurrection,
> not as equated to the Sabbath. That confusion may exist in certain
> protestant denominations, but is not the understanding of the larger
> Christian Church.
> 
> Really the only reason for making this clarification at all, and not
> entirely dropping the religious pursuit of this discussion, is that
> religion is critical in many of the most interesting calendars on this
> planet, and one cannot fully appreciate the history and nuances of any
> of these calendars, notwithstanding the ISO, without a correct
> understanding of the religious communities that stand behind them, even
> if you view them merely as historical curiosities, rather than as
> transcendent truths.
> 
> So, I, for one, and I'm sure many others, would appreciate it if
> everyone restrain from slights, implied or actual, on religions that
> will, of necessity, arise in calendrical discussion.
> 
> Thanks.
> 
> Rich

You completely misunderstood my point, Rich. I was not implying any slight
whatsoever. I continue to disagree with your opinion about the first day
of the week in the Christian tenet(s), about which I know a good deal more
than you evidently think. But my point was simply that cultural and
religious traditions that may not make "sense" to the programmer are often
very important. Similar to what you stated above. You took offense where
one was neither intended nor made.

- nick

   
Nick Tonkin   {|8^)>





Re: Which DOW is day #1?

2003-01-12 Thread Dave Rolsky
On Sun, 12 Jan 2003, David Wheeler wrote:

> On Sunday, January 12, 2003, at 11:15  AM, John Peacock wrote:
>
> > A lot of the 0-based vs 1-based arguments should be resolved simply by
> > having our interface design in place.  Programmers will be less
> > inclined to have to look up some 0-based array when the API we provide
> > does it for them, i.e.
> >
> > month[$date->month_num] vs. $date->month both return January
>
> I think that this will be resolved by:
>
> >  month[$date->month_0] vs. $date->month both return January

Make that:

 $month[ $date->month_0 ] vs. $date->month_name

$date->month returns a 1-based numbers
$date->month_0 a 0-based named
$date->month_name returns a name based on the DateTime::Language module
the $date object is holding onto.


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/



Re: Which DOW is day #1?

2003-01-12 Thread Rich Bowen
On Sun, 12 Jan 2003, Nick Tonkin wrote:

> Funny how the "Christian" point of view is that Sunday is the first day of
> the week, when "God" rested on the seventh day after working to make the
> world. Seventh which is Sunday for Christians .. (and Saturday which is
> seventh for Jews, so for them Sunday _is_ the first day).

I would greatly prefer it if we not indulge in implied or actual
criticizm of various religions, if it's all the same to you. Your
comments here show that you're unaware of the Christian point of view,
which makes a very clear distinction between the seventh day, on which
God rested, and Sunday, which is a celebration of the resurrection of
Jesus. The seventh day, the Sabbath, is Saturday in the Jewish
tradition. Sunday has been celebrated in the Christian church,
since the first Century AD, in commeration of the resurrection,
not as equated to the Sabbath. That confusion may exist in certain
protestant denominations, but is not the understanding of the larger
Christian Church.

Really the only reason for making this clarification at all, and not
entirely dropping the religious pursuit of this discussion, is that
religion is critical in many of the most interesting calendars on this
planet, and one cannot fully appreciate the history and nuances of any
of these calendars, notwithstanding the ISO, without a correct
understanding of the religious communities that stand behind them, even
if you view them merely as historical curiosities, rather than as
transcendent truths.

So, I, for one, and I'm sure many others, would appreciate it if
everyone restrain from slights, implied or actual, on religions that
will, of necessity, arise in calendrical discussion.

Thanks.

Rich

-- 
Oh I have slipped the surly bonds of earth
And danced the sky on laughter-silvered wings
 --High Flight (John Gillespie Magee)




Re: Which DOW is day #1?

2003-01-12 Thread Matthew Simon Cavalletto
On Sunday, January 12, 2003, at 10:48  AM, Rich Bowen wrote:


On Sun, 12 Jan 2003, John Peacock wrote:

We really have to go with ISO because that battle has already been 
fought and won(?) in the international community.

Well, I was going to say the following:

This is not about either ISO standard or backward compatibility with 
C, but about common usage. People think of Sunday as the first day, 
and so we should stick with that, so as not to confuse people.

However, based on your comment, I'm not sure if that is the case.

This is a classic localization problem, with the convention varying 
from one place and time to another.

I've seen a number of indications that many, perhaps most, Europeans 
consider the week to start on Monday, and a quick Google search turned 
up more anecdotal support for this theory, ex: "Many British calendars 
and diaries use Monday as the start of the week; but some still use 
Sunday." (http://www.merlyn.demon.co.uk/weekinfo.htm)

Another source clarifies that starting on Sunday is in fact the 
original pattern, and that counting from Monday is a later development 
of European cultures, especially Protestant and German-speaking ones. 
(http://www.friesian.com/week.htm)

Personally, I've always preferred calendar weeks that start on Monday, 
partly for the onomatopoeia (mONEday, TWOsday, 3ednesday, FOURsday, 
FrIVEsday, ...), and partly because it synched up with the 
school-day/work-day cycle.

Synchronization to the work week is also useful in some kinds of 
business contexts -- if you're scheduling weekday shifts, it's more 
convenient for your work days to run from 1-5 than from 2-6 -- and I 
believe the ISO week-numbering work is based on existing practices in 
the manufacturing industry. Some desktop calendar software allows you 
to switch the display to Monday weeks, and many business-week planning 
calendars also start on Monday.

In a sense, one would like to be able to treat this as a locale issue, 
so that a user could specify the convention used in their setting, in 
the same way that they can select the language used. ("I'm in Germany, 
give me German day names and ISO weeks.")

A simpler solution would be to support multiple interfaces:
  ($year, $week_num, $week_day) = $dt->greg_week();
  ($year, $week_num, $week_day) = $dt->iso_week();

Callers could choose to request whichever number they wanted:
- $dt->iso_week_day   - 1..7 starting with Monday
- $dt->iso_week_day_0 - 0..6 starting with Monday
- $dt->greg_week_day  - 1..7 starting with Sunday
- $dt->greg_week_day_0- 0..6 starting with Sunday

-Simon



Re: Which DOW is day #1?

2003-01-12 Thread David Wheeler
On Sunday, January 12, 2003, at 11:15  AM, John Peacock wrote:


A lot of the 0-based vs 1-based arguments should be resolved simply by 
having our interface design in place.  Programmers will be less 
inclined to have to look up some 0-based array when the API we provide 
does it for them, i.e.

	month[$date->month_num] vs. $date->month both return January

I think that this will be resolved by:


 month[$date->month_0] vs. $date->month both return January


David

--
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/  Yahoo!: dew7e
   Jabber: [EMAIL PROTECTED]




Re: Which DOW is day #1?

2003-01-12 Thread John Peacock
Rich Bowen wrote:

However, based on your comment, I'm not sure if that is the case. So
perhaps, in my parochial view of the world (which I like to think of as
anything but parochial!) "people" means "Americans with Christian
heritage."


Don't count out the Jews, who also consider Sunday to be the first day of the 
week (and did that long before the Christian's splintered off ;~).

http://www.tondering.dk/claus/cal/node6.html#SECTION0066


Can you elaborate on your "fought and won" comment? Because it is not
nearly as clear as that to me. I very firmly think of Sunday as day 1,
and have thought that long before I used Perl, and every calendar that I
saw at the mall over the last several weeks displays the week that way.



"Fought and won(?)" referred to the fact that ISO-8601 mandates that Monday is 
the first day of the week.  All international standards are a long fought out 
compromise between numerous factions.  We ignore those battles and compromises 
at our peril, regardless of "common usage" considerations.

A lot of the 0-based vs 1-based arguments should be resolved simply by having 
our interface design in place.  Programmers will be less inclined to have to 
look up some 0-based array when the API we provide does it for them, i.e.

	month[$date->month_num] vs. $date->month both return January

John


--
John Peacock
Director of Information Research and Technology
Rowman & Littlefield Publishing Group
4720 Boston Way
Lanham, MD 20706
301-459-3366 x.5010
fax 301-429-5747



Re: Which DOW is day #1?

2003-01-12 Thread Nick Tonkin

Funny how the "Christian" point of view is that Sunday is the first day of
the week, when "God" rested on the seventh day after working to make the
world. Seventh which is Sunday for Christians .. (and Saturday which is
seventh for Jews, so for them Sunday _is_ the first day).

Monday is always the first day of the week for me.

Now, regarding indexing (again):

I may have missed the change but Dave R. said in an earlier post that he
advocated zero-indexing day of week. This may have changed since he said
last night something like "Now that we've accepted that day of week is
1-indexed" -- if so I missed that.

I want to argue (again) for _not_ 1-indexing day of week. The arguments
made for 1-indexing month of year and date of month were that one uses
those schemae in Real Life. This is true for month of year, where '2' is
another way of saying 'February.' It appears to be true with date of
month, although it is not, since '11' is the _value_ of date of month, not
an alias for the value. But it is definitely _not_ true for day of week,
which is _only_ a counting mechanism used for calculations and not used by
humans in Real Life as far as I can tell.

I still think all these things should return 0-indexed values unless
specified otherwise. When you want a 1-indexed month of year you are
probably producing output for a UI anyway, functionality which is usually
best kept separate from program logic, even if it's with different
functions in the same package.


On Sun, 12 Jan 2003, Rich Bowen wrote:

> By the way, I still have not seen Dave's original note, except in the
> archive. What's up with that? I wonder if it got filtered off to some
> other folder. /me goes off grumbling to grep -r the mail tree.

I'm getting some of these messages out of order, sometimes by hours ...

- nick




Re: Which DOW is day #1?

2003-01-12 Thread Martijn van Beers
On Sun, Jan 12, 2003 at 09:13:07AM -0500, John Peacock wrote:
> Dave Rolsky wrote:
> >
> >I'm inclined to go with ISO rather than backwards compatibility with C.
> >
> 
> We really have to go with ISO because that battle has already been fought 
> and won(?) in the international community.  And we have already committed 
> to ignore localtime's perversions when required...

iCalendar (rfc 2445) specifies a WKST property for recurrence rules
to let you define your own start of the (work) week. The default
for this is Monday.


Martijn