Does your SimpleDate class provides day of week method? Is it implemented from Calendar class?
Anyway, you could implement it from scratch as well and cooperate it with Calendar class which provides day of week. Then you should be able to find out using day of month and day of week.
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17
OK, if you cannot use Calendar class, you would have to implement the day of week from scratch. It is not difficult and you could use brute-force algorithm to deal with it. You just need to know what's the day of week of the first day of the year. The first day of year could be hard-coded (such as starting from Januaray 1, 1970).
When dealing with day of week, you may have to design what value would be returned. You could give the starting day of week to Monday and ending on Sunday (some implementation starts on Sunday and ends on Saturday). Then you simply compute day of year by adding all days of each month. You should check for leap year before you add up the whole year days. Once you have the day of year and a known day of week of the first day of a year, you could apply modulo (%) to find out the day of week. Please note that you must watch out for 0 value from modulo if you want to keep value 1~7. The 0 is equal to 7.
/*
i.e.
Value set for starting week day is 1 (Monday) up to 7 (Sunday)
The day of week of January 1, 1970 is 4 (Thursday).
Given a year number, you should be able to find out the day of week of
the given year.
i.e. year 2012
Number of days in the year 1970 is 365 (not a leap year)
The value of day of week of the first day of the year 1971
(4 + 365) % 7 = 5
Number of days in the year 1971 is 365 (not a leap year)
The value of day of week of the first day of the year 1972
(5 + 365) % 7 = 6
Number of days in the year 1972 is 366 (leap year)
The value of day of week of the first day of the year 1973
(6 + 366) % 7 = 1
...
...
Number of days in the year 2011 is 366 (not a leap year)
The value of day of week of the first day of the year 2012
(6 + 365) % 7 = 0 => 7
*/
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17