+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Determining if a day is 0 or 1

  1. #1
    idontkno is offline x10Hosting Member idontkno is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    49

    Determining if a day is 0 or 1

    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

  2. #2
    miguelkp's Avatar
    miguelkp is offline x10 Lieutenant miguelkp is an unknown quantity at this point
    Join Date
    Oct 2009
    Location
    El Bierzo - Spain
    Posts
    302

    Re: Determining if a day is 0 or 1

    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
    Clic on userbar to visit my band's website:

  3. #3
    idontkno is offline x10Hosting Member idontkno is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    49

    Re: Determining if a day is 0 or 1

    Quote Originally Posted by miguelkp View Post
    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
    Yeah, that is what I mean, but it doesn't work when you skip a day.

    For instance:

    Feb 1st = day 0
    Feb 2nd = day 1
    Feb 3rd = day 0
    Feb 4th = day 1
    Feb 5th = skip
    Feb 8th = day 1

  4. #4
    miguelkp's Avatar
    miguelkp is offline x10 Lieutenant miguelkp is an unknown quantity at this point
    Join Date
    Oct 2009
    Location
    El Bierzo - Spain
    Posts
    302

    Re: Determining if a day is 0 or 1

    Where or how do you 'save' the skip-days info? I mean, do you use (or plan to use) a MySQL database to say the script 'hey dude, skip that day!' or something like that?
    Clic on userbar to visit my band's website:

  5. #5
    idontkno is offline x10Hosting Member idontkno is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    49

    Re: Determining if a day is 0 or 1

    Quote Originally Posted by miguelkp View Post
    Where or how do you 'save' the skip-days info? I mean, do you use (or plan to use) a MySQL database to say the script 'hey dude, skip that day!' or something like that?
    I haven't decided. I was going to put it into an ini file though.

  6. #6
    miguelkp's Avatar
    miguelkp is offline x10 Lieutenant miguelkp is an unknown quantity at this point
    Join Date
    Oct 2009
    Location
    El Bierzo - Spain
    Posts
    302

    Re: Determining if a day is 0 or 1

    So I supose that you can store only the number of skipped days and add that number to the int daycode (the function argument). Could this work for your purposes?
    Last edited by miguelkp; 02-13-2010 at 10:11 PM.
    Clic on userbar to visit my band's website:

  7. #7
    idontkno is offline x10Hosting Member idontkno is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    49

    Re: Determining if a day is 0 or 1

    Quote Originally Posted by miguelkp View Post
    So I supose that you can store onle the number of skipped days and add that number to the int daycode (the function argument). Could this work for your purposes?
    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

    Code:
    if (date("w") > 0 && < 6)
    {
    //blah blah blah
    }
    But I have no clue how I would make the 0s and 1s work.

  8. #8
    miguelkp's Avatar
    miguelkp is offline x10 Lieutenant miguelkp is an unknown quantity at this point
    Join Date
    Oct 2009
    Location
    El Bierzo - Spain
    Posts
    302

    Re: Determining if a day is 0 or 1

    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

    PHP Code:
    string date  string $format  [, int $timestamp  ] ) 
    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().


    Parameters:

    [...]

    w = Numeric representation of the day of the week = 0 (for Sunday) through 6 (for Saturday)
    Clic on userbar to visit my band's website:

  9. #9
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Determining if a day is 0 or 1

    Quote Originally Posted by idontkno View Post
    Feb 1st = 0
    Feb 2nd = 1
    Feb 3rd = 0
    Feb 4th = 1
    Feb 5th = skip
    Feb 6th = weekend
    Feb 7th = weekend
    Feb 8th = 0
    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.

  10. #10
    idontkno is offline x10Hosting Member idontkno is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    49

    Re: Determining if a day is 0 or 1

    Quote Originally Posted by misson View Post
    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?
    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.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Determining the status of a remote server without fsockopen().
    By darksuiseiseki in forum Programming Help
    Replies: 0
    Last Post: 07-21-2008, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers