| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod GetStartOfPreviousPeriod ( | 
|   Date date, | 
|   String timeunit, | 
|   Number nroftimeunit | 
| ) declarative remote as DateTime | 
| { | 
|   Description: 'Return the start of the previous period given the date, time unit and nr of time unit' | 
|   TextBody: | 
|   [* | 
|     // DWE2 Apr-25-2016 (modified) | 
|     value := date.DateTime(); | 
|      | 
|     // Hour | 
|     if( timeunit = Translations::MP_GlobalParameters_Hour() ) | 
|     { | 
|      value := date - Duration::Hours( nroftimeunit ); | 
|     } | 
|     // Day | 
|     else if( timeunit = Translations::MP_GlobalParameters_Day() ) | 
|     { | 
|       value := date - Duration::Days( nroftimeunit ); | 
|     } | 
|     // Week | 
|     else if( timeunit = Translations::MP_GlobalParameters_Week() ) | 
|     { | 
|       value := value - Duration::Weeks( nroftimeunit ); | 
|     } | 
|     // Month | 
|     else if( timeunit = Translations::MP_GlobalParameters_Month() ) | 
|     { | 
|       value := PeriodSpecification_MP::GetStartOfPreviousMonth( value, nroftimeunit ); | 
|     } | 
|     // Quarter | 
|     else if( timeunit = Translations::MP_GlobalParameters_Quarter() ) | 
|     { | 
|       value := PeriodSpecification_MP::GetStartOfPreviousMonth( value, nroftimeunit * 3 ); // A quarter = 3 month | 
|     } | 
|     // Year | 
|     else if( timeunit = Translations::MP_GlobalParameters_Year() ) | 
|     { | 
|       value := PeriodSpecification_MP::GetStartOfPreviousMonth( value, nroftimeunit * 12 ); // One year = 12 months | 
|     } | 
|      | 
|     return value; | 
|   *] | 
| } |