Lean  $LEAN_TAG$
Schedule.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
17 using System.Linq;
19 using System.Collections.Generic;
20 
22 {
23  /// <summary>
24  /// Entity in charge of managing a schedule
25  /// </summary>
26  public class Schedule
27  {
28  private IDateRule _dateRule;
29 
30  /// <summary>
31  /// True if this schedule is set
32  /// </summary>
33  public bool Initialized => _dateRule != null;
34 
35  /// <summary>
36  /// Set a <see cref="IDateRule"/> for this schedule
37  /// </summary>
38  public void On(IDateRule dateRule)
39  {
40  _dateRule = dateRule;
41  }
42 
43  /// <summary>
44  /// Gets the current schedule for a given start time
45  /// </summary>
46  public IEnumerable<DateTime> Get(DateTime startTime, DateTime endTime)
47  {
48  return _dateRule?.GetDates(startTime, endTime) ?? Enumerable.Empty<DateTime>();
49  }
50 
51  /// <summary>
52  /// Creates a new instance holding the same schedule if any
53  /// </summary>
54  public Schedule Clone()
55  {
56  return new Schedule { _dateRule = _dateRule };
57  }
58  }
59 }