在另一个时间段内的离散时间段上迭代
我有一个周期表,描述了..比如说..喂鱼的频率:
--------------------------------------------------------
Period: Jan Feb March April May Jun Jul ... n - 1 .... n
--------------------------------------------------------
Val_1: 5 2 3 6 3 2 4 x x
Val_2 ...
--------------------------------------------------------
我有一个周期,有两个日期时间,开始和结束,即:
DateTime start = new DateTime(2010, 3, 11);
DateTime end = new DateTime(2012, 7, 12);
..喂食过程发生的时间。如何从表中获取与 start 和 end 给定期间相关的每个期间的值?
例如,开始和结束给出的期限是2.5年,但我的表只描述了12个月。如何在 start 和 end 给出的整个期间内循环表中的每个期间?
我想出了这样的事情:
class PeriodTableValue
{
DateTime period; // Ignore year component of datetime
double val_1;
double val_2;
}
void FeedMyFish(double howmuch, DateTime period_start, DateTime period_end)
{
...
}
...
PeriodTableValue[] table = ...
DateTime start = ...
DateTime end = ...
DateTime d1 = start;
for(int i = 0; i < table.Length; i++)
{
DateTime d2 = table[i].period;
int nI = find the occurrances of period table[i]. How ???
for(int j = 0; j < nI; j++)
{
FeedMyFish(..parameters ???)
}
d1 = d2;
}
我被困在这里了。请指教。
谢谢!
I have a following table of periods which describes how often to ..say.. feed my fish:
--------------------------------------------------------
Period: Jan Feb March April May Jun Jul ... n - 1 .... n
--------------------------------------------------------
Val_1: 5 2 3 6 3 2 4 x x
Val_2 ...
--------------------------------------------------------
And I have a period given with two DateTimes, start and end, ie:
DateTime start = new DateTime(2010, 3, 11);
DateTime end = new DateTime(2012, 7, 12);
..in which time the feeding process occurs. How can I get the values from the table in every period in correlation with the period given by start and end ?
For example, the period given by start and end is 2.5 years, but my table only describes 12 months. How can I loop over every period in the table WITHIN the whole period given by start and end ?
I came up with something like this:
class PeriodTableValue
{
DateTime period; // Ignore year component of datetime
double val_1;
double val_2;
}
void FeedMyFish(double howmuch, DateTime period_start, DateTime period_end)
{
...
}
...
PeriodTableValue[] table = ...
DateTime start = ...
DateTime end = ...
DateTime d1 = start;
for(int i = 0; i < table.Length; i++)
{
DateTime d2 = table[i].period;
int nI = find the occurrances of period table[i]. How ???
for(int j = 0; j < nI; j++)
{
FeedMyFish(..parameters ???)
}
d1 = d2;
}
And I'm stuck right here. Please advise.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这篇文章包括对各种周期类型的支持以及交叉周期的搜索:
This article includes support for various period types and the search for intersection periods: