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 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, 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-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 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



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 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 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 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^)