692b9dc79a7c94d1af6204466a5917a371d830ab
FAQ/Questions/How-to-Add-a-Custom-Timespan-Type.md
| ... | ... | @@ -1,21 +1,21 @@ |
| 1 | -#How to Add a Custom Timespan Type |
|
| 1 | +#How to Add a Custom TimePeriod Type |
|
| 2 | 2 | |
| 3 | 3 | [[_TOC_]] |
| 4 | 4 | |
| 5 | -##Adding Custom Timespans |
|
| 5 | +##Adding Custom TimePeriods |
|
| 6 | 6 | |
| 7 | -Here is an example of how to add custom time spans to the filters. Apply this code within ConfigureSettings in Global.asax. |
|
| 7 | +Here is an example of how to add custom time spans to the filters. Apply this code within ``InitializeReporting()`` in your Global.asax. |
|
| 8 | 8 | |
| 9 | 9 | ```csharp |
| 10 | -CustomTimePeriod customTimePeriod = AdHocSettings.CustomTimePeriod[key]; |
|
| 11 | -TimeSpan period = customTimePeriod.Period; |
|
| 12 | -if (period.Ticks > 0) |
|
| 13 | -{ |
|
| 14 | - startDate = now + period; |
|
| 10 | +//the if block prevents the key from being re-added to the list |
|
| 11 | +if (!AdHocSettings.CustomTimePeriods.ContainsKey("Lunar Cycle")) { |
|
| 12 | + AdHocSettings.CustomTimePeriods.Add("Lunar Cycle", new CustomTimePeriod("Lunar Cycle", new TimeSpan(29, 12, 44, 2, 976))); |
|
| 15 | 13 | } |
| 16 | -else |
|
| 17 | -{ |
|
| 18 | - endDate = now; |
|
| 19 | - startDate = now.period; |
|
| 20 | -} |
|
| 14 | +``` |
|
| 15 | + |
|
| 16 | +##Modifying An Existing Time Period |
|
| 17 | + |
|
| 18 | +```csharp |
|
| 19 | + CustomTimePeriod ctp = AdHocSettings.CustomTimePeriods["Lunar Cycle"]; |
|
| 20 | + ctp.StartDate = DateTime.Now + ctp.Period; //passed by reference so the original list will update |
|
| 21 | 21 | ``` |
| ... | ... | \ No newline at end of file |