Say I wanted to set a day as 0 or 1 for weekdays only, alternating every day with an occasional day where you skip alternating and go on to the old value.
E.g. 0,1,0,1,0,break,0,1,0,1,0
Say I wanted to set a day as 0 or 1 for weekdays only, alternating every day with an occasional day where you skip alternating and go on to the old value.
E.g. 0,1,0,1,0,break,0,1,0,1,0
Do you mean monday = 0 = 0; tuesday = 1 = 1; wednesday = 2 = 0; thursday = 3 = 1; friday = 4 = 0 (day = original = newcode). Don't you?
And that you can use this 0 or 1 valor and original valor at.
Then if I understood you well, you can make a function like this (this is more a pseudo code than a true language)
Code:def day_number(int daycode, bol original = false) if(original == true) return day % 2 else return day end end
Nope. I just looked through your code again and I realized that you thought I mean every monday = 1 or tuesday = 0.
If I added on to my February example, you would come up with this:
Feb 1st = 0
Feb 2nd = 1
Feb 3rd = 0
Feb 4th = 1
Feb 5th = skip
Feb 6th = weekend
Feb 7th = weekend
Feb 8th = 0
[...]
Feb 12th = 0
[...]
Feb 15th = 1
Feb 16th = 0
Feb 17th = 1
For the weekends, we could do this
But I have no clue how I would make the 0s and 1s work.Code:if (date("w") > 0 && < 6) { //blah blah blah }
Well. I think you misunderstood me. The int daycode should be the day of the week, not the day of the month. And all should work I think
Every monday will be number 0. Every tuesday will be number 1. And so on. And of course, you can skip weekends, either outside the function or inside it, with a small change.
Depending on what languaje are you working, maybe you can found in Google some algorithm that calculates day of the week.
As I supose you're making some kind of PHP calendar, here you got in PHP:
http://php.net/manual/en/function.date.php
Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time().PHP Code:string date ( string $format [, int $timestamp ] )
Parameters:
[...]
w = Numeric representation of the day of the week = 0 (for Sunday) through 6 (for Saturday)
This contradicts the earlier example, where you assigned a value of 1 to Feb. 8th. Getting the count of days mod 2 will do what you want, but you still haven't specified where you want to start counting from. The beginning of the week? Month? Year? An arbitrary date?
If you told us the overall goal, it would be easier to help you.
Furthermore, do you want to generate the days as well as the values? That is, does the code need to skip weekends and skipped days, or merely return a value when given a day count?
Do you have a particular language in mind, are you looking for algorithms?
Last edited by misson; 02-13-2010 at 10:45 PM.
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.
My overall goal is as I stated it before. Assigning a number to a day, in which, alternates every other day unless there is an exception, such as a weekend or holiday.
I would like for it to start on an arbitrary date, continue on while alternating between 0s and 1s, skipping weekends and holidays. In some cases like my apparent contradiction, counting the day as a 0 or 1 while continuing on.
I was looking for a function where I can generate a function which by inputting an arbitrary date, will tell me if it's a 0 or a 1.
In another hopefully less confusing example:
Feb 1 = 0
Feb 2 = 1
Feb 3 = 0
Feb 4 = 1
Feb 5 = skipped, but counts as 0
Feb 6 = weekend
Feb 7 = weekend
Feb 8 = 1
Feb 9 = 0
Feb 10 = 1
Feb 11 = skipped
Feb 12 = 0
Feb 13 = weekend
Feb 14 = weekend
Feb 15 = 1
Feb 16 = 0
Feb 17 = 1
I was thinking of setting a variable in a DB and just xoring it every day, but skipping it on weekends and predefined dates.