views:

1310

answers:

11

If someone were to say something happens in the first or last week of some month, how would you define that span?


Background

I'm working on a library that needs to handle this kind of thing in an intuitive way, but my intuition doesn't claim one case or the other.

I can make it select different behavior but still need a good default.


For a concrete example I'll just to pick an random month: July 2008

s  m  t  w  r  f  s
--------------------
      1  2  3  4  5
6  7  8  9  10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

(Note: I'll assume the week starts with Sunday but the question could be asked re Monday as well)

What span is the first week of the month?

  1. June 29 - July 5 -- the week that includes the first
  2. July 6 - 12 -- the first week that is all the way int the month

The second week is just the 7 days following the first right?

What span is the last week of the month?

  1. July 27 - Aug 2 -- ditto but the last day
  2. July 20 - 26 -- ditto but the last week

Non wiki comments welcome

+1  A: 

The first week of the month is the week that includes the first

  1. June 29 - July 5
BCS
I don't know why this got downvoted... this is the definition I've always used. All the other interpretations don't make any sense to me.
rmeador
You can use this as long as the last week of the month is the last week wholly contained within the month; otherwise, you get gaps - weeks not belonging to either month.
Jonathan Leffler
+2  A: 

The first week of the month is the first week that is all the way int the month

  1. July 6 - 12
BCS
This coupled with the 'last week of the month is the last week that is all the way in the month' leaves a gap of 1 week unowned by either month most of the time.
Jonathan Leffler
+1  A: 

The last week of the month is the week that includes the last day

  1. July 27 - Aug 2
BCS
If you couple this definition with 'first week of the month is the week that includes the first of the month', you get some weeks belong to two months at the same time. You need to define both the first and the last week rules in pairs, making sure they don't overlap.
Jonathan Leffler
The 5th week of the month (if any) will always push into the next month. *I* don't mind having some weeks have more than one name. Do you see any reason to avoid it?
BCS
Well, I guess it depends on why you're calling it the last week of the month. Accountants tend to get upset if you try counting the revenue earned in the last week of July and the first week of August and end up double-counting the revenue.
Jonathan Leffler
Similarly, people would get upset if they took one week's vacation and because it is both the last week of July and the first week of August, the company dings them for 10 days vacation time when they only took 5 days off work.
Jonathan Leffler
I'm looking for a map /to/ a date span; "last week"->date-date, not from it.
BCS
+2  A: 

The last week of the month is the last week that is all the way int the month

  1. July 20 - 26
BCS
This makes sense when coupled with 'first week is the week that includes the first of the month'.
Jonathan Leffler
+1  A: 

My definition would be the first week is the week of the first working day in the month, and likewise the last week is the week of the last working day in the month.

baretta
I hadn't thought of that one... Hmmm...
BCS
+6  A: 

There is no answer because it varies even inside a country.

However, this source seems to think it's defined by the ISO standard as the first week that contains a thursday. However the above source says that the ISO standard does not list a specification for 'first week of the month'


More than 300 chars - sorry!

The ISO 8601 standard defines the first week of the YEAR as:

calendar week number

ordinal number which identifies a calendar week within its calendar year according to the rule that the first calendar week of a year is that one which includes the first Thursday of that year and that the last calendar week of a calendar year is the week immediately preceding the first calendar week of the next calendar year

There is nothing in ISO 8601 about the first week of the month because, as has been noted, the definition varies by country (and even by company, for example). Oh, and the standard says that weeks start on Monday.

Malfist
OK I sort of figured that was the real answer. Now what would you /like/ it to be?
BCS
This won't help in the development of a date parsing library.
TheTXI
@TheTXI I added more info
Malfist
+5  A: 

If you are building a library, you should allow the user to choose how they want to handle it either by having methods that return the first/last full/partial week of the month or by passing an argument that indicates whether you want the full/partial week. Clearly document whichever is the default if you provide methods that don't require the specification.

public Week GetFirstFullWeekOfMonth( DateTime forDate ) { }

public Week GetFirstPartialWeekOfMonth( DateTime forDate ) { }

Or

public Week GetFirstWeekOfMonth( DateTime forDate, bool includePartial ) {}
tvanfosson
Noted. Now what default should I use?
BCS
I would probably default to the first/last full week and allow the user to choose if they want partial weeks.
tvanfosson
A: 

The first week of the month is the first week that owns 4 or more days of the defined week period. (Not really but I thought I'd throw it in as an option)

Joe Philllips
A: 

There's a fairly obvious option you are missing. The first week of the month is the seven days starting with the first day of the month. Hence, in your example, the first week would be Tuesday, the 1st through Monday, the 7th. This way, the first through 4th weeks would always be fully contained within the month, and only the 5th week would cross over.

Kevin
I had thought of that one but rejected it as a useless option: Who would use that option and where? After being correct+relevant, I'd rather be incorrect+relevant before being correct+irrelevant.
BCS
I don't know what your library is going to be used for, so I don't know what is relevant and what isn't. Merely pointing out that there was a third option.
Kevin
+1  A: 

The first week of the month is week 0 - the week that has the first day of the month. The last week is the week with the last day of the month

Hence the weeknumber of the last week of july IS THE SAME as the weeknumber of the first week of august

** UNLESS **

the month in question ends on the last day of the last week, in wich case the following month would start on the first day of the new week and have a different weeknumber

:)

A: 

Talk to your users and ask them what they think it means when the program says to them "First week of the month" and "Last week of the month".

Kevin Conner
That is what I am trying to do with this question.
BCS