| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod GetLengthOfTimeAndTimeUnitRatio ( | 
|   String perioddefinationtimeunit, | 
|   String timeunit, | 
|   Number nroftimeunit, | 
|   DateTime start, | 
|   Duration duration | 
| ) const declarative remote as Real | 
| { | 
|   Description: | 
|   [* | 
|     Return the ratio of the period defination time unit's duration over the time unit's duration, takes length of time into consideration | 
|     E.g., period defination time unit's duration = 1 days, time unit's duration is 1 week, length of time = 2, return (1 / 7) / 2. | 
|     Argument time unit is get from unit capacity, unit availabilit or stocking point capacity. Same goes to length of time. | 
|     Argument period defination time unit is unit period or stocking point period's time unit. | 
|   *] | 
|   TextBody: | 
|   [* | 
|     // soh yee Aug-26-2012 (created) | 
|      | 
|     factor := 1.0; | 
|      | 
|     // The factor will be multiplied to the "bigger" time unit. E.g., month is > week. | 
|     if( PeriodSpecification_MP::GetTimeUnitLevel( perioddefinationtimeunit ) > PeriodSpecification_MP::GetTimeUnitLevel( timeunit ) ) | 
|     { | 
|       factor := PeriodSpecification_MP::GetNumberOfPeriodsForDifferentTimeUnits( timeunit, perioddefinationtimeunit, start ); | 
|     } | 
|      | 
|     else | 
|     { | 
|       factor := guard( 1 / PeriodSpecification_MP::GetNumberOfPeriodsForDifferentTimeUnits( perioddefinationtimeunit, timeunit, start ), 0 ); | 
|     } | 
|      | 
|     // Need to find the ratio as some unit period / stocking point's duration doesn't occupy the whole time unit. | 
|     // E.g., Apr-1-2015 to Apr-6-2015 with time unit Quarter. The duration is only few days compare to 90+ days. | 
|     // Changed to Hours as Hours is now the smallest bucket - Nicklaus Oct-14-2016 | 
|     totalhours := PeriodSpecification_MP::GetNumberOfPeriodsForDifferentTimeUnits( Translations::MP_GlobalParameters_Hour(), perioddefinationtimeunit, start ); | 
|     durationratio := guard( duration.HoursAsReal() / totalhours, 0 ); | 
|      | 
|     value := guard( durationratio / nroftimeunit, 0 ) * factor; | 
|      | 
|      | 
|     return value; | 
|   *] | 
| } |