Reply
0's, 1's, Hours available for the day, how to display the correct blocks of time?
Old 04-15-2008, 08:47 PM 0's, 1's, Hours available for the day, how to display the correct blocks of time?
Super Talker

Posts: 121
Okay, this is the problem....theres a matrix of 0's and 1's taht correspond the time slots and the days of the week on whether you can work or not during the time block. If it's a 1, you can work, if it's a 0, you're unavailable.

I'm trying to set it up for sunday first so I can apply it to the rest of the week, and the method for sunday will apply to mon-sat.

The time blocks are these:
8:00-9:15am => X1
9:45-11:00am => X2
11:15-12:30pm => X3
1:00-2:15pm => X4
2:30-3:45pm => X5
4:25-5:30pm => X6
6:30-7:45pm => X7
8:15-9:30pm => X8

Now, what I'm trying to do is, say you have 1's at x1, x2, x3, and x6, x7, x8, but 0's at x4, and x5.

so you can work from 8:00-12:30, and 4:25 - close.

How can I setup some loops....or something, to make it say that?

My current code:
PHP Code:
$sun=1;
while(
$sun <= 50)
{
    if(
$hours[$sun] == 1)
    {
        switch(
$sun)
        {
        case 
1:
        
$_SESSION['aSundayHours'] .= '8:00-9:15 am, ';
        break;
        case 
8:
        
$_SESSION['aSundayHours'] .= '9:45-11:00 am, ';
        break;
        case 
15:
        
$_SESSION['aSundayHours'] .= '11:15-12:30 pm, ';
        break;
        case 
22:
        
$_SESSION['aSundayHours'] .= '1:00-2:15 pm, ';
        break;
        case 
29:
        
$_SESSION['aSundayHours'] .= '2:30-3:45 pm, ';
        break;
        case 
36:
        
$_SESSION['aSundayHours'] .= '4:25-5:30 pm, ';
        break;
        case 
43:
        
$_SESSION['aSundayHours'] .= '6:30-7:45 pm, ';
        break;
        case 
50:
        
$_SESSION['aSundayHours'] .= '8:15-9:30 pm, ';
        break;
        }
    }
    
$sun $sun 7;

But that will output:
Code:
8:00-9:15 am, 9:45-11:00 am, 11:15-12:30 pm, 4:25-5:30 pm, 6:30-7:45 pm, 8:15-9:30 pm,
I guess my main questions, is what's the best way to have a string of 1's and 0's and finding the groups of 1's and classifying them. Any questions, please ask, and any help is awesome!!!
kbfirebreather is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-16-2008, 04:42 PM Re: 0's, 1's, Hours available for the day, how to display the correct blocks of time?
Skilled Talker

Posts: 73
Name: Mattias Nordahl
Location: Sweden
You have the times and their respective 1 or 0 in an array, right? Then you could probably just go thru them all in a loop, and when you find a time with a 1 you select it's starting time and store it in a variable $start, the same thing for it's ending time, in $end.

Then keep looping and if the next time also has a 1, simply change $end to the new ending time. If the next time also has 1, change $end again and so on. Now, if you put $start and $end in an array instead, like
PHP Code:
array(array('start''end'), array('start''end'), ...) 
you can store several start's and end's.
lizciz is offline
Reply With Quote
View Public Profile
 
Old 04-17-2008, 12:04 PM Re: 0's, 1's, Hours available for the day, how to display the correct blocks of time?
Super Talker

Posts: 121
Well, the only problem is I need to apply this practically to a scheduling system. And something dawned on me...what if I use military time?

That way the start and end time will always be different, and for the schedule, I can check to see if the time their needed is between their available slots.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to 0's, 1's, Hours available for the day, how to display the correct blocks of time?
 

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12893 seconds with 13 queries