Click here to Skip to main content
15,868,016 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Hi guys - is it possible to cast generic up the specific types hierarchy??? Pin
supercat94-Feb-09 5:17
supercat94-Feb-09 5:17 
QuestionFinding a given day or weekday x months from today Pin
nzmike3-Feb-09 14:34
nzmike3-Feb-09 14:34 
GeneralRe: Finding a given day or weekday x months from today Pin
Luc Pattyn3-Feb-09 16:13
sitebuilderLuc Pattyn3-Feb-09 16:13 
AnswerRe: Finding a given day or weekday x months from today Pin
Jon Rista3-Feb-09 16:19
Jon Rista3-Feb-09 16:19 
AnswerRe: Finding a given day or weekday x months from today Pin
nzmike3-Feb-09 16:25
nzmike3-Feb-09 16:25 
GeneralRe: Finding a given day or weekday x months from today Pin
Luc Pattyn3-Feb-09 17:30
sitebuilderLuc Pattyn3-Feb-09 17:30 
GeneralRe: Finding a given day or weekday x months from today Pin
Jon Rista4-Feb-09 6:25
Jon Rista4-Feb-09 6:25 
AnswerRe: Finding a given day or weekday x months from today Pin
cmk3-Feb-09 20:45
cmk3-Feb-09 20:45 
nzmike wrote:
at present I'm adding the months to today's date, setting the day to 1


Same as i would do ...

nzmike wrote:
then simply looping though testing each day until I find what I want


... not what i would do. Smile | :)

Let's say you find the 1st of the month of interest is a Wed. (Apr.2009) (which most datetime/cal classes will give).

From where you are now, do:

enum {Mon, Tues, Wed, Thurs, Fri, Sat, Sun} Days;
int weekfirst[7] = [6, 7, 1, 2, 3, 4, 5]
int weeklast[7] = [27, 28, 29, 30, 24, 25, 26]
int *week = weekfirst;
int mul = 1;

If parse 'last' then
mul = -1
week = weeklast

int weekdayidx = (index of lowest number in first 5 elements of week)
int occurence = (default = 0, parse 'first' gives 0, 'second' gives 1, ...);
int offset = 7 * occurence * mul;
int day = offset;

switch( type ) {
case Weekday : a bit more fidly, but should be easy from here; break;
case Monday : day += week[Mon]; break;
...
}

e.g.
2nd Thurs = 7*1*1 + 2 = 9th
1st Mon = 7*0*1 + 6 = 6th
last Tues = 7*0*-1 + 28 = 28th
2nd last Sat = 7*1*-1 + 25 = 18th

[EDIT] whoops, sorry about the C syntax, forgot is was in .net forum [/EDIT]

...cmk

The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack

QuestionSmart Card Pin
Mohd Atiq3-Feb-09 1:38
Mohd Atiq3-Feb-09 1:38 
AnswerRe: Smart Card Pin
annathor5-Feb-09 1:52
annathor5-Feb-09 1:52 
Questionbook Pin
welcan3-Feb-09 1:02
welcan3-Feb-09 1:02 
AnswerRe: book Pin
EliottA3-Feb-09 7:10
EliottA3-Feb-09 7:10 
AnswerRe: book Pin
vaghelabhavesh3-Feb-09 8:38
vaghelabhavesh3-Feb-09 8:38 
QuestionOracle Transactions Handling in ASP .NET Pin
summon_192-Feb-09 23:04
summon_192-Feb-09 23:04 
AnswerRe: Oracle Transactions Handling in ASP .NET Pin
Wendelius3-Feb-09 7:54
mentorWendelius3-Feb-09 7:54 
QuestionSerialization of List<> and Remoting [modified] Pin
Andez20042-Feb-09 22:00
Andez20042-Feb-09 22:00 
QuestionCAS policy how to assign to a specific app Pin
Dan Neely2-Feb-09 8:00
Dan Neely2-Feb-09 8:00 
AnswerRe: CAS policy how to assign to a specific app Pin
Jon Rista3-Feb-09 10:08
Jon Rista3-Feb-09 10:08 
GeneralRe: CAS policy how to assign to a specific app Pin
Dan Neely3-Feb-09 10:21
Dan Neely3-Feb-09 10:21 
QuestionN-Hypernet in .net Pin
kamakshim2-Feb-09 2:59
kamakshim2-Feb-09 2:59 
AnswerRe: N-Hypernet in .net Pin
Colin Angus Mackay2-Feb-09 3:15
Colin Angus Mackay2-Feb-09 3:15 
GeneralRe: N-Hypernet in .net Pin
Mark Churchill2-Feb-09 13:30
Mark Churchill2-Feb-09 13:30 
AnswerRe: N-Hypernet in .net Pin
Pete O'Hanlon2-Feb-09 3:16
subeditorPete O'Hanlon2-Feb-09 3:16 
GeneralRe: NHibernate in .net Pin
kamakshim2-Feb-09 3:27
kamakshim2-Feb-09 3:27 
GeneralRe: NHibernate in .net Pin
Pete O'Hanlon2-Feb-09 3:36
subeditorPete O'Hanlon2-Feb-09 3:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.