开发者

How to get minutes from overlapping time frames

I have a curious problem. I can easily solve this by hand, but can't quite figure out how to code it. My problem involves timezones. I have an app that does work during a set time of day. The data it works on is timezone specific data. I want to calculate the overall "width" of the processing window in minutes.

Say that they pane is from 9:00am to noon. The pane is 180 minutes wide. I have data for timezones -4, -5, -6, -7 and -10. Since the pane is wider that the offset, I calculate the "width" of the processing window as 9 x 60 or 360 mins.

I'm wr开发者_开发百科iting this in C#. I have some code whipped up to start working on this problem, but I'm not sure how to represent the inputs. Any suggestions?


i guess this is what you need: http://www.codeproject.com/KB/datetime/TimePeriod.aspx


I think what you want to do is take the beginning of the earliest time, and the end of the latest time and use DateTimeOffset to get the difference. Something like this:

//1/1/2011 9:00 AM -4
var earliest = new DateTimeOffset(2011, 1, 1, 9, 0, 0, new TimeSpan(-4, 0, 0));
//1/1/2011 12:00 PM -10
var latest = new DateTimeOffset(2011, 1, 1, 12, 0, 0, new TimeSpan(-10, 0, 0));
Console.Out.WriteLine("minutes = {0}", (latest - earliest).TotalMinutes);

This yields a result of 540. 180 minutes of time between the two, plus an additional 360 minutes for the timezone difference. 360 is the difference between -4 and -10 timezones if the hours were exactly the same. If that wasn't what you're looking for, please update your question to add more details / scenarios.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜