Posts

Showing posts with the label timespan

Can you round a .NET TimeSpan object?

Can you round a .NET TimeSpan object? Can you round a .NET TimeSpan object? TimeSpan I have a Timespan value of: 00:00:00.6193789 Timespan Is there a simple way to keep it a TimeSpan object but round it to something like 00:00:00.62? TimeSpan Just a warning to others. I was going down the road of using TimeSpan as a public property off of a business object. Didn't realize that TimeSpan was not a "XmlSerializable" data type. Discussion on the issue: devnewsgroups.net/group/microsoft.public.dotnet.framework/… – BuddyJoe Dec 4 '08 at 0:14 11 Answers 11 Sorry, guys, but both the question and the popular answer so far are wrong :-) The question is wrong because Tyndall asks for a way to round but shows an example of truncation . Will D...

How do you calculate total duration of overlapping time-spans

How do you calculate total duration of overlapping time-spans This code is good for a set of times sorted in ascending order only! I was getting the wrong answer because the original set of times were given and expected to be calculated unsorted I'm trying to write a piece of code that will calculate the total duration of a given set of task times, where w tasks can be worked on at any given time. If there are two tasks going on, and one of them finish, then another will start immediately. To give some context, the times are in a sorted array as below; int times = {2,2,3,4}; //short array for example int n = sizeof(times) / sizeof(times[0]); int w = 2; //number of tasks that can be done simultatenously int total_time = 0; The method I'm going with is to sum all the wth times in the array. So in this example,the total time should be the second and fourth values (2+4).For that I run a for loop. int main() { for (int i = n-1; i >= 0; i -= w) { //std::cout ...