In our application, we use both a DailyCalendar and an HourlyCalendar. So we have the standard SI_Time_Duration quantity with second as a base unit and conversions to hour and day.
For the daily calendar, I want to model a period of time. So I have two element parameters EP_FirstDay and EP_LastDay with range DailyCalendar and a parameter P_LengthOfPeriod. As the length of the period is specified in days, I set the unit of it to day].
However, if I set EP_FirstDay to the 1st of January 2020 and P_LengthOfPeriod to 1 day], then EP_LastDay := EP_FirstDay + P_LengthOfPeriod results in 22nd of July in the year 2256 instead of the 2nd of January (which was quite surprising to me).
I understand, that P_LengthOfPeriod is converted to its base unit , so the above calculation actually adds 86400 days to EP_FirstDay. Of course, I could just remove the unit from P_LengthOfPeriod, but I would like to keep it, if possible.
Is there a better way of modeling these kind of situations?
Procedure PR_Example {
Body: {
EP_FirstDay := '2020-01-01';
P_LengthOfPeriod := 1 1day];
!Results in EP_LastDay = '2256-07-22' instead of '2020-01-02'
EP_LastDay := EP_FirstDay + P_LengthOfPeriod;
}
}
Quantity SI_Time_Duration {
BaseUnit: s;
Conversions: {
hour->s : #-># * 3600,
day ->s : #-># * 86400
}
Comment: "Expresses the value for the duration of periods.";
}
Calendar DailyCalendar {
Unit: day;
BeginDate: "2020-01-01";
EndDate: "4000-12-31";
TimeslotFormat: "%c%y-%m-%d";
}
ElementParameter EP_FirstDay {
Range: DailyCalendar;
}
Parameter P_LengthOfPeriod {
Range: integer;
Unit: day;
}
ElementParameter EP_LastDay {
Range: DailyCalendar;
}