Quintiq file version 2.0
|
#parent: #root
|
StaticMethod GetNumberOfPeriodsForDifferentTimeUnits (
|
String smallertimeunit,
|
String biggertimeunit,
|
DateTime periodstartdate
|
) const declarative remote as Real
|
{
|
Description:
|
[*
|
Return the number of period of the larger time unit when converting to a smaller time unit. For example, a month convert to weeks = 4 weeks.
|
This doesn't care the argument periodstartdate is at the beginning or middle or end of the month. For example, a month convert to weeks, with periodstartdate = 15 Jan, still returning 4 weeks.
|
*]
|
TextBody:
|
[*
|
// DWE2 Apr-25-2016 (modified)
|
|
numberofperiod := 0.0;
|
|
// Always take the "bigger" time unit to convert to the "smaller" time unit to avoid decimal point.
|
starttime := periodstartdate;
|
start := starttime.Date();
|
|
// Find the end date of the "bigger" time unit. E.g., 1-Jan-2012 for time unit Month will return 1-Feb-2012.
|
endtime := PeriodSpecification_MP::GetStartOfNextPeriod( starttime, biggertimeunit, 1 );
|
end := endtime.Date();
|
|
//Get number of periods between start and end of the smaller time unit
|
if( smallertimeunit = Translations::MP_GlobalParameters_Hour() )
|
{
|
numberofperiod := ( endtime - starttime ).HoursAsReal();
|
}
|
else if( smallertimeunit = Translations::MP_GlobalParameters_Day() )
|
{
|
numberofperiod := end - start;
|
}
|
else if( smallertimeunit = Translations::MP_GlobalParameters_Week() )
|
{
|
numberofperiod := ( end - start ) / 7;
|
}
|
else if( smallertimeunit = Translations::MP_GlobalParameters_Month()
|
or smallertimeunit = Translations::MP_GlobalParameters_Quarter() )
|
{
|
numberofperiod := ( ( end.Year() - start.Year() ) * 12 ) + end.Month() - start.Month();
|
|
if( smallertimeunit = Translations::MP_GlobalParameters_Quarter() )
|
{
|
numberofperiod := numberofperiod / 3;
|
}
|
}
|
else if( smallertimeunit = Translations::MP_GlobalParameters_Year() )
|
{
|
numberofperiod := end.Year() - start.Year();
|
}
|
|
return numberofperiod;
|
*]
|
}
|