GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Feb-2005, 22:56
shinyhui shinyhui is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Posts: 38
shinyhui is on a distinguished road

Return month by providing work week


Is there any function by providing work week to return the month in Visual C++?
example:
work week 07 fall in february
work week 09 fall in march
  #2  
Old 20-Feb-2005, 23:57
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
i don't think there is such function in VC++, but you can always write your own function...

Week 9 = 9 * 7 = 63
so you just have to keep adding number of days in each month and find where week 9 falls into... i think its that simple,

thre was once a thread to count something like this... let me search first..hmmmm

ahhhaaaa here:

a program by dilmv,
http://www.gidforums.com/t-4037.html

CPP / C++ / C Code:
int GetMonthDays(int month, int year)
{
  int days = 0;
  switch(month)
  {
    case 1: 
        days = 31;
        break;
    case 3: 
        days = 31;
        break;
    case 5: 
        days = 31;
        break;
    case 7: 
        days = 31;
        break;
    case 8: 
        days = 31;
        break;
    case 10: 
        days = 31;
        break;
    case 12: 
        days = 31;
        break;
    case 4: 
        days = 30;
        break;
    case 6: 
        days = 30;
        break;
    case 9: 
        days = 30;
        break;
    case 11:
        days = 30;
        break;
    case 2: 
        days = 28 + IsLeap(year);
  }
  return days;
}
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #3  
Old 21-Feb-2005, 00:11
shinyhui shinyhui is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Posts: 38
shinyhui is on a distinguished road
Quote:
Originally Posted by Max Payne
i don't think there is such function in VC++, but you can always write your own function...

Week 9 = 9 * 7 = 63
so you just have to keep adding number of days in each month and find where week 9 falls into... i think its that simple,

thre was once a thread to count something like this... let me search first..hmmmm

ahhhaaaa here:

a program by dilmv,
www.gidforums.com

CPP / C++ / C Code:
int GetMonthDays(int month, int year)
{
  int days = 0;
  switch(month)
  {
    case 1: 
        days = 31;
        break;
    case 3: 
        days = 31;
        break;
    case 5: 
        days = 31;
        break;
    case 7: 
        days = 31;
        break;
    case 8: 
        days = 31;
        break;
    case 10: 
        days = 31;
        break;
    case 12: 
        days = 31;
        break;
    case 4: 
        days = 30;
        break;
    case 6: 
        days = 30;
        break;
    case 9: 
        days = 30;
        break;
    case 11:
        days = 30;
        break;
    case 2: 
        days = 28 + IsLeap(year);
  }
  return days;
}

at first i also do as what u do but somebody tell me that there got a function returning month by providing work week.. so i try to search on it..
  #4  
Old 21-Feb-2005, 00:47
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
well, i never heard of a function like that.. hmm hav you tried google or MSDN, if you still can't find better go to that person and ask him where did he find that function,

if its me, i won't waste time searching for it, when i can also do the same thing, just use this one untill maybe one day i find that function...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #5  
Old 21-Feb-2005, 01:44
shinyhui shinyhui is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Posts: 38
shinyhui is on a distinguished road
Quote:
Originally Posted by Max Payne
well, i never heard of a function like that.. hmm hav you tried google or MSDN, if you still can't find better go to that person and ask him where did he find that function,

if its me, i won't waste time searching for it, when i can also do the same thing, just use this one untill maybe one day i find that function...

i think so... thanks!!
  #6  
Old 21-Feb-2005, 09:07
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by shinyhui
i think so... thanks!!

There are four methods of numbering work weeks that I have seen over the years (different companies, different continents):

1. The week containing Jan 1 is Week #1. The next Sunday is the beginning of Week #2.

2. The week containing the first Sunday of the year is Week #1. The next Sunday is the beginning of Week #2.

3. The week containing Jan 1 is Week #1. The next Monday is the beginning of Week #2.

4. The week containing the first Monday of the year is Week #1. The next Monday is the beginning of Week #2.

Some weeks could be in one month or another, depending not only on the calendar year, but also on the scheme used.

Is Week 5 in January or February? Is Week 23 in May or June. It depends.

I will describe the inverse of your problem. Given a calendar year, how do we calculate the work week number for a given day.


Now, given one of the above options, and given the day of the week of Jan 1, we can step through the calendar week-by-week to assign numbers to successive weeks.

Note that there are still a few decisions to make.

Consider this year (Jan 1 is Saturday).

Suppose we are using scheme #1 above.

Then the week beginning with Sunday, Jan 2, is Week #2, and the week beginning on Sunday, Dec 27, 2004, would be Week #1 of 2005. (But it could have been Week #53 of 2004.)


Suppose we are using scheme #2 above.

Then the week beginning with Sunday, Jan 2, is Week #1, and the week beginning with Sunday, Dec 25, is Week #52. That seems OK. But what is the week that contains Jan 1, 2005? Is it week #0 of 2005? Is it week #52 of 2004? What number do we print on the 2005 calendar?

Note also that if we had Jan 1 on Saturday and it was a leap year, then Sunday, December 31, would be the beginning of Week 53 of that year. So that year could have weeks numbered from 0 to 53.

Fun, huh?

If you find some calendar program on the web, be sure to test all possibilities (most amateurish efforts that I have seen don't take everything into account).

When writing the program be sure to state your assumptions (scheme #1, #2, #3, #4, above, or whatever other way you want to do it). Test with all possible calendars (There are only 14 possible calendars, you know, so it's not very burdonsome to test every possible input.)

Regards,

Dave
Last edited by davekw7x : 21-Feb-2005 at 09:42.
  #7  
Old 21-Feb-2005, 19:04
shinyhui shinyhui is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Posts: 38
shinyhui is on a distinguished road
Quote:
Originally Posted by davekw7x
There are four methods of numbering work weeks that I have seen over the years (different companies, different continents):

1. The week containing Jan 1 is Week #1. The next Sunday is the beginning of Week #2.

2. The week containing the first Sunday of the year is Week #1. The next Sunday is the beginning of Week #2.

3. The week containing Jan 1 is Week #1. The next Monday is the beginning of Week #2.

4. The week containing the first Monday of the year is Week #1. The next Monday is the beginning of Week #2.

Some weeks could be in one month or another, depending not only on the calendar year, but also on the scheme used.

Is Week 5 in January or February? Is Week 23 in May or June. It depends.

I will describe the inverse of your problem. Given a calendar year, how do we calculate the work week number for a given day.


Now, given one of the above options, and given the day of the week of Jan 1, we can step through the calendar week-by-week to assign numbers to successive weeks.

Note that there are still a few decisions to make.

Consider this year (Jan 1 is Saturday).

Suppose we are using scheme #1 above.

Then the week beginning with Sunday, Jan 2, is Week #2, and the week beginning on Sunday, Dec 27, 2004, would be Week #1 of 2005. (But it could have been Week #53 of 2004.)


Suppose we are using scheme #2 above.

Then the week beginning with Sunday, Jan 2, is Week #1, and the week beginning with Sunday, Dec 25, is Week #52. That seems OK. But what is the week that contains Jan 1, 2005? Is it week #0 of 2005? Is it week #52 of 2004? What number do we print on the 2005 calendar?

Note also that if we had Jan 1 on Saturday and it was a leap year, then Sunday, December 31, would be the beginning of Week 53 of that year. So that year could have weeks numbered from 0 to 53.

Fun, huh?

If you find some calendar program on the web, be sure to test all possibilities (most amateurish efforts that I have seen don't take everything into account).

When writing the program be sure to state your assumptions (scheme #1, #2, #3, #4, above, or whatever other way you want to do it). Test with all possible calendars (There are only 14 possible calendars, you know, so it's not very burdonsome to test every possible input.)

Regards,

Dave
Last time i read one article... in standard calender a week should contain 4 days at least... which means 1 Jan 2005 is consider week 52 in 2004 and 2 Jan 2005 is week 01 in 2005...
  #8  
Old 22-Feb-2005, 07:23
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by shinyhui
Last time i read one article... in standard calender a week should contain 4 days at least... which means 1 Jan 2005 is consider week 52 in 2004 and 2 Jan 2005 is week 01 in 2005...

I didn't mention the ISO 8601 standard calendar: "Week 01 of a year is per definition the first week that has the Thursday in this year, which is equivalent to the week that contains the fourth day of January." Here is one reference

I only wanted to point out that there are a number of ways of counting week numbers that I have personally experienced over the years, and that people dealing with calendars might want to be aware that there are lots of fine details to be considered to "get it right" --- where "right" depends on the requirements of the calendar's customer. (You, your company, your university instructor, or whoever wants the calendar.)

Calendars are fun to play with (on what day of the week were you born?), and formulas such as Zeller's rule for calculating the day of the week for Gregorian calendar years are interesting (in my opinion) illustrations of C language integer division and modulus arithmetic.

Regards,

Dave
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 2) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Things to Avoid in C/C++ -- gets() , Part 1 WaltP C Programming Language 5 21-Jun-2007 12:13
C++ file I/O CronoX C++ Forum 36 09-Mar-2004 17:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:51.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.