bogdem
asked on
Need a function, very hard task.
Hello, Experts!
I have
Run time:
7:00am – 9:00pm
Off time array:
Array_offtime_start(0) = 8:00am
Array_offtime_end(0) = 8:10am
…………………………………
Array_offtime_start(n) = 11:30am
Array_offtime_end(n) = 11:45am
Need a function to check if off time is inside or touching somehow my run time. It can be only one element in off time array, can be none or can be n elements.
If run time IS inside of my runtime, some how I have to get back array or something with all my timeframes.
Thanks a lot for any help.
Oops...
You need to use the interval with DateDiff:
DateDiff(DateInterval.Minu te, runtime_start,....)
You need to use the interval with DateDiff:
DateDiff(DateInterval.Minu
ok real quick...
you have 2 arrays for offtime a startingtime array and an ending time array is that accurate?
you have 2 arrays for offtime a startingtime array and an ending time array is that accurate?
if this is true position n in array start and position n in array end will reprent a time span?
ASKER
In this example
Let say I have one run time
7:00am – 9:00pm
and two off time
Array_offtime_start(0) = 8:00am
Array_offtime_end(0) = 8:10am
Array_offtime_start(1) = 11:30am
Array_offtime_end(1) = 11:45am
I wish to have two arrays with all my timeframes:
Array_timeframe_start(0) = 7:00am
Array_timeframe_end(0) = 8:00am
Array_timeframe_start (1) = 8:00am
Array_timeframe_end (1) = 8:10am
Array_timeframe_start(2) = 8:10am
Array_timeframe_end(2) = 11:30am
Array_timeframe_start(3) = 11:30am
Array_timeframe_end(3) = 11:45am
Array_timeframe_start(4) = 11:45am
Array_timeframe_end(5) = 9:00pm
That’s what I’m after.
Let say I have one run time
7:00am – 9:00pm
and two off time
Array_offtime_start(0) = 8:00am
Array_offtime_end(0) = 8:10am
Array_offtime_start(1) = 11:30am
Array_offtime_end(1) = 11:45am
I wish to have two arrays with all my timeframes:
Array_timeframe_start(0) = 7:00am
Array_timeframe_end(0) = 8:00am
Array_timeframe_start (1) = 8:00am
Array_timeframe_end (1) = 8:10am
Array_timeframe_start(2) = 8:10am
Array_timeframe_end(2) = 11:30am
Array_timeframe_start(3) = 11:30am
Array_timeframe_end(3) = 11:45am
Array_timeframe_start(4) = 11:45am
Array_timeframe_end(5) = 9:00pm
That’s what I’m after.
ASKER
sorry:
Array_timeframe_end(4) = 9:00pm
Array_timeframe_end(4) = 9:00pm
i need you to answer my questions if you want me to help you.
if this is true position n in array start and position n in array end will reprent a time span?
if this is true position n in array start and position n in array end will reprent a time span?
also are you using .net 1.1 or 2.0?
assuming your are using 1.1... and the two arrays are syncronized.
first off having 2 arrays trying to store information for one concept is dirty.
You should have a class called Offtime and a class called TimeFrame which both inherit from a class that has a start time and an end time which are exposed through properties and you will need a method that checks to see if a passed in span overlaps w/ you.. You would then have a single array for each of your span children, which could be checked against each other for overlap
you could then do a for each on your arrays and check each element.
first off having 2 arrays trying to store information for one concept is dirty.
You should have a class called Offtime and a class called TimeFrame which both inherit from a class that has a start time and an end time which are exposed through properties and you will need a method that checks to see if a passed in span overlaps w/ you.. You would then have a single array for each of your span children, which could be checked against each other for overlap
you could then do a for each on your arrays and check each element.
So you can just expand on the DateDiff approach I outlined. You already have all the info you need.
Look at all of the start & stop times as before, and figure out if they are within the time you need to account for. Take the ones that are during the run time and sort them according to their start time. Then build an array:
run time start
off time start 1
off time start 2
.
.
.
off time start x
off time end x
run time end
You can sort the off times by looking at how far "past" the run time start they are.
ctm5
Look at all of the start & stop times as before, and figure out if they are within the time you need to account for. Take the ones that are during the run time and sort them according to their start time. Then build an array:
run time start
off time start 1
off time start 2
.
.
.
off time start x
off time end x
run time end
You can sort the off times by looking at how far "past" the run time start they are.
ctm5
ASKER
I’m using .NET 2.0
I understand what you saying, but can you provide some code?
I understand what you saying, but can you provide some code?
Are you working with me or with mydasx?
ctm5
ctm5
jup im doing that for you now.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I asked if you are on 2.0 cause i use the generic list here, which is type safe and wonderful.
ASKER
I'm just answer the question.
I can do the logic, and if I could write a code by myself then I didn’t post the question here. I need help with coding part not with logic.
Thanks.
I can do the logic, and if I could write a code by myself then I didn’t post the question here. I need help with coding part not with logic.
Thanks.
BTW ctm5
datediff is dangerous when only dealing w/ time. if a programmer forgets to populate the date or populates date some of the time but not all of the time, comparisons of time become hosed. Its been my experience, that taking complexity out of the comparison is safer then taking the complexity out of the constructor. Best case scenario both work, worst case scenario, mine still works.
datediff is dangerous when only dealing w/ time. if a programmer forgets to populate the date or populates date some of the time but not all of the time, comparisons of time become hosed. Its been my experience, that taking complexity out of the comparison is safer then taking the complexity out of the constructor. Best case scenario both work, worst case scenario, mine still works.
anytime you find yourself creating 2 arrays sitting next to each other to work on data that is needed in both, move to a wrapper. Seems you did need a little help w/ the logic :)
Best case scenario and worst case scenario, the programmer is smart enough to build in error checking, which, for the sake of simplicity here, I do not list.
It is not our role to hold someone's hand through every line of code. We are here to suggest approaches, explain concepts, etc. It is also not our role, I believe, to intentionally step all over each other. I hope bogdem can sort through our conflicting answers.
ctm5
It is not our role to hold someone's hand through every line of code. We are here to suggest approaches, explain concepts, etc. It is also not our role, I believe, to intentionally step all over each other. I hope bogdem can sort through our conflicting answers.
ctm5
ASKER
To mydasx
Sorry, can not get it.
I see the runtime, but how to set off time?
Sorry, can not get it.
I see the runtime, but how to set off time?
ASKER
I need help with both, in first with coding :)
bogdem,
I am happy to help you, but I will let mydasx finish up. I will continue to monitor this question. If you want to get back to me, just post a message here.
ctm5
I am happy to help you, but I will let mydasx finish up. I will continue to monitor this question. If you want to get back to me, just post a message here.
ctm5
Best case scenario and worst case scenario, the programmer is smart enough to build in error checking, which, for the sake of simplicity here, I do not list.
It is not our role to hold someone's hand through every line of code. We are here to suggest approaches, explain concepts, etc. It is also not our role, I believe, to intentionally step all over each other. I hope bogdem can sort through our conflicting answers.
Not going to get into a flame war here. However, If you can trust every programmer that will ever touch your code, you live in a world very different from mine.
You set offtime as follows:
'Do this for each one of your timespans:
Dim x As ExSpan = New ExSpan()
x.StartTime = New DateTime(2006, 5, 24, <some hour>, <some minute>, <some second>)
x.EndTime = New DateTime(2006, 5, 24, <some hour>, <some minute>, <some second>)
offTime.Add(x)
It is not our role to hold someone's hand through every line of code. We are here to suggest approaches, explain concepts, etc. It is also not our role, I believe, to intentionally step all over each other. I hope bogdem can sort through our conflicting answers.
Not going to get into a flame war here. However, If you can trust every programmer that will ever touch your code, you live in a world very different from mine.
You set offtime as follows:
'Do this for each one of your timespans:
Dim x As ExSpan = New ExSpan()
x.StartTime = New DateTime(2006, 5, 24, <some hour>, <some minute>, <some second>)
x.EndTime = New DateTime(2006, 5, 24, <some hour>, <some minute>, <some second>)
offTime.Add(x)
ASKER
Hello, Experts!
Here is what I wrote by myself, just tack a look on it and tell me how stupid it is.
Of course all point goes to mydasx . Thanks.
I appreciate any comments about my code.
Public Class Form1
Dim Run_time_Start As Date = #5/23/2006 7:00:00 AM#
Dim Run_time_End As Date = #5/23/2006 7:00:00 PM#
Dim Off_time_Start As New ArrayList
Dim Off_time_End As New ArrayList
Dim TimeFrame_Start As New ArrayList
Dim TimeFrame_End As New ArrayList
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Off_time_Start.Add("5/23/2 006 8:00:00 AM")
Off_time_End.Add("5/23/200 6 8:30:00 AM")
Off_time_Start.Add("5/23/2 006 9:00:00 PM")
Off_time_End.Add("5/23/200 6 9:30:00 PM")
For i As Integer = 0 To Off_time_Start.Count - 1
' add off time to Off_time_Start
Run_time_End = Run_time_End.AddMinutes(Sy stem.Conve rt.ToDateT ime(Off_ti me_End(i)) .Subtract( System.Con vert.ToDat eTime(Off_ time_Start (i))).Tota lMinutes)
If i = 0 Then
TimeFrame_Start.Add(Run_ti me_Start)
TimeFrame_End.Add(Off_time _Start(i))
TimeFrame_Start.Add(Off_ti me_Start(i ))
TimeFrame_End.Add(Off_time _End(i))
Else
TimeFrame_Start.Add(TimeFr ame_End.It em(TimeFra me_End.Cou nt - 1))
TimeFrame_End.Add(Off_time _Start(i))
TimeFrame_Start.Add(Off_ti me_Start(i ))
TimeFrame_End.Add(Off_time _End(i))
End If
' Check if the Run_time_Stop is before next Off_time_Start
' And i is not last element right now
If i + 1 <= Off_time_Start.Count - 1 Then
If DateTime.Compare(Off_time_ Start(i + 1), Run_time_End) = 1 Then
TimeFrame_Start.Add(Off_ti me_End(i))
TimeFrame_End.Add(Run_time _End)
Exit For
End If
End If
If i = Off_time_Start.Count - 1 Then
TimeFrame_Start.Add(Off_ti me_End(i))
TimeFrame_End.Add(Run_time _End)
End If
Next
For i As Integer = 0 To TimeFrame_Start.Count - 1
Debug.WriteLine("From: " & TimeFrame_Start.Item(i) & " To: " & TimeFrame_End.Item(i))
Next
End Sub
End Class
Here is what I wrote by myself, just tack a look on it and tell me how stupid it is.
Of course all point goes to mydasx . Thanks.
I appreciate any comments about my code.
Public Class Form1
Dim Run_time_Start As Date = #5/23/2006 7:00:00 AM#
Dim Run_time_End As Date = #5/23/2006 7:00:00 PM#
Dim Off_time_Start As New ArrayList
Dim Off_time_End As New ArrayList
Dim TimeFrame_Start As New ArrayList
Dim TimeFrame_End As New ArrayList
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Off_time_Start.Add("5/23/2
Off_time_End.Add("5/23/200
Off_time_Start.Add("5/23/2
Off_time_End.Add("5/23/200
For i As Integer = 0 To Off_time_Start.Count - 1
' add off time to Off_time_Start
Run_time_End = Run_time_End.AddMinutes(Sy
If i = 0 Then
TimeFrame_Start.Add(Run_ti
TimeFrame_End.Add(Off_time
TimeFrame_Start.Add(Off_ti
TimeFrame_End.Add(Off_time
Else
TimeFrame_Start.Add(TimeFr
TimeFrame_End.Add(Off_time
TimeFrame_Start.Add(Off_ti
TimeFrame_End.Add(Off_time
End If
' Check if the Run_time_Stop is before next Off_time_Start
' And i is not last element right now
If i + 1 <= Off_time_Start.Count - 1 Then
If DateTime.Compare(Off_time_
TimeFrame_Start.Add(Off_ti
TimeFrame_End.Add(Run_time
Exit For
End If
End If
If i = Off_time_Start.Count - 1 Then
TimeFrame_Start.Add(Off_ti
TimeFrame_End.Add(Run_time
End If
Next
For i As Integer = 0 To TimeFrame_Start.Count - 1
Debug.WriteLine("From: " & TimeFrame_Start.Item(i) & " To: " & TimeFrame_End.Item(i))
Next
End Sub
End Class
i still dont recomend using two lists to represnt a span
You can use the DateDiff function to find out if the offtime_start and the offtime_end fall within the Run Time.
Dim withinstart as Long= DateDiff(runtime_start,arr
Dim withinend as Long= DateDiff(array_offtime_end
If withinstart > -1 And withinend > -1 Then MsgBox("Break is within run time.")
Not sure what you mean by getting back an array of all the timeframes....
ctm5